我有一个客户回访记录表record(user,customer,tele,info,date)
有10个客服人员,都有录入权限。
现在我想实现的功能是:
1.每个客服登录后,只能看自己的回访记录,请问如何实现?
2.设置一个客服经理,可以根据条件查看任何客服的记录,还可以将记录导出到excel表格。
谢谢!
有10个客服人员,都有录入权限。
现在我想实现的功能是:
1.每个客服登录后,只能看自己的回访记录,请问如何实现?
2.设置一个客服经理,可以根据条件查看任何客服的记录,还可以将记录导出到excel表格。
谢谢!
我是从数据源直接拖拽到Form中的DataGridView,
接下来我需要怎样修改,就可以只显示客服自己的记录了?
那上面的方案变通一下,在你的客服记录表里,加个字段客户ID的字段吧.我是从数据源直接拖拽到Form中的DataGridView,
接下来我需要怎样修改,就可以只显示客服自己的记录了?你最好是用代码来提取数据,在提取的时候进行客户记录ID判断.(灵活)客服登录后,只显示自己的记录,而且在这个窗体中,可以添加删除,或者修改纪录。
你所要实现的只是一个简单的拿用户ID进行数据查询过滤功能.
if(登陆用户 != '经理')
{
select * FORM record WHERE user = '登陆用户'
}
else{select * FORM record
}
{
this.recorderTableAdapter.Fill(this.salesDataSet1.recorder); }
{
select * FORM record WHERE user = '登陆用户'
}
else {select * FORM record
}
根据ID擦和讯数据库记录绑定到datagridview
private SqlConnection cn;
private SqlCommandBuilder builder;
private SqlDataAdapter da;
private DataSet ds; int ID=1;//客服ID
private void butSearch_Click(object sender, EventArgs e)
{
cn = new SqlConnection("");
cn.Open();
ds = new DataSet();
SqlCommand cmd = new SqlCommand("select * from record where ID="+ID, cn);
da = new SqlDataAdapter(cmd);
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
builder = new SqlCommandBuilder(da);
da.Fill(ds, "Test");
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
private void butUpdate_Click(object sender, EventArgs e)
{
int row = da.Update(ds, "Test");
MessageBox.Show("更新完成" + row + builder.GetUpdateCommand().CommandText);
}
private void btnDelete_Click(object sender, EventArgs e)
{
ds.Tables[0].Rows[this.dataGridView1.CurrentRow.Index].Delete();
int row = da.Update(ds, "Test");
MessageBox.Show("删除完成" + row + builder.GetDeleteCommand().CommandText);
}
每天回帖即可获得10分可用分!
代码如何写?
我是这样写的
SqlCommand cmd = new SqlCommand("select * from record where ID="+Form3.UID, cn); 现在老是提示:列名“tao001” 无效;
这是什么原因?
where UID='" + Form3.UID + "'"
/// 名称:WriteToExcel
/// 功能:查询结果导出Execl
/// 编写人:
/// 编写时间:2008-11-26
/// </summary>
/// <param name="table"></param>
public void WriteToExcel(DataTable table)
{
try
{
string tempImagePath = Application.StartupPath;
string temp = tempImagePath + "\\ExeclFiles";
Directory.CreateDirectory(@temp);
string strFilePath = @Application.StartupPath + @"\ExeclFiles\" + CommonClass.CommonDateTime() + ".xls";
System.IO.StreamWriter sw = new System.IO.StreamWriter(strFilePath,true, System.Text.Encoding.Default);
object[] values = new object[table.Columns.Count];
for (int i = 0; i < table.Columns.Count; ++i)
{
sw.Write(table.Columns[i].Caption.ToString());
sw.Write('\t');
}
sw.Write("\r\n");
for (int i = 0; i < table.Rows.Count; i++)
{
for (int j = 0; j < values.Length; ++j)
{
sw.Write(table.Rows[i][j].ToString());
sw.Write('\t');
}
sw.Write("\r\n");
}
sw.Flush();
sw.Close();
CommonClass.MessageBoxOK("成功导出[" + ds.Tables[0].Rows.Count.ToString() + "]行到Execl!");
}
catch
{
CommonClass.MessageBoxNo("导出Execl失败!");
}
}
{
SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Execl files (*.xls)|*.xls"; saveFileDialog.FilterIndex = 0; saveFileDialog.RestoreDirectory = true; saveFileDialog.CreatePrompt = true; saveFileDialog.Title = "Export Excel File To";
saveFileDialog.ShowDialog();
Stream myStream; myStream = saveFileDialog.OpenFile(); //StreamWriter sw = new StreamWriter(myStream, System.Text.Encoding.GetEncoding("gb2312")); StreamWriter sw = new StreamWriter(myStream, System.Text.Encoding.GetEncoding(-0)); string str = ""; try
{ //写标题 for (int i = 0; i < dataGridView1.ColumnCount; i++)
{ if (i > 0)
{ str += "\t"; } str += dataGridView1.Columns[i].HeaderText; }
sw.WriteLine(str); //写内容 for (int j = 0; j < dataGridView1.Rows.Count; j++)
{ string tempStr = ""; for (int k = 0; k < dataGridView1.Columns.Count; k++)
{ if (k > 0)
{ tempStr += "\t"; } tempStr += dataGridView1.Rows[j].Cells[k].Value.ToString(); } sw.WriteLine(tempStr); } sw.Close(); myStream.Close(); } catch (Exception error)
{ // MessageBox.Show(error.ToString()); } finally
{ sw.Close(); myStream.Close(); } }
这是我的导出代码
现在能到处到excel表格,但是有个提示错误:
System.NullReferenceException
不知道啥原因,如何解决?
这一行有什么问题?
检查看你的datagridview是否有空值的存在.另外你提供详细的错误信息吧.这是一个比较广泛的错误.建议你GOOGLE或是baidu一下
1.如果是管理员,就要显示全部数据,如何写代码?
2.datagridview的列宽如何设置?比如说,我想让所有列按百分比比例都显示出来。
这两个问题解决后就结贴,谢谢!
dategridview的autosizecolumnmode设置为Fill代码:this.dataGridView1.DataSource = ds.Tables[0].DefaultView ;
this.dataGridView1.Columns[0].FillWeight = 8;
this.dataGridView1.Columns[1].FillWeight = 8;
就剩一个问题了 如何让管理员查看所有的记录,管理员的UID是 AD001
期待帮助,谢谢!
谢谢大家地帮助!!!