private void button1_Click(object sender, EventArgs e) { Worklog worklog = new Worklog(); worklog.销售 = (selectStaffControl1.SelectedStaffs != null && selectStaffControl1.SelectedStaffs.Count > 0) ? selectStaffControl1.SelectedStaffs[0] : null; worklog.日期 = DateTime.Parse(textBox3.Text.Trim()); worklog.客户 = textBox1.Text.Trim(); worklog.电话 = textBox2.Text.Trim(); worklog.是否自访 = checkBox1.Checked; worklog.是否老会员 = checkBox2.Checked; worklog.是否电话拜访 = checkBox3.Checked; worklog.性别 = (性别)Enum.ToObject(typeof(性别), comboBox2.SelectedIndex); worklog.意向 = textBox4.Text.Trim(); worklog.住址 = textBox5.Text.Trim(); worklog.备注 = textBox6.Text; WorklogLogic rl = WorklogLogic.GetInstance(); int id = rl.AddWorklog(worklog); if (id > 0) { worklog.ID = id; LoadWorklogs(); MessageBox.Show("添加成功!"); } }
private void button2_Click(object sender, EventArgs e) { if (comboBox1.SelectedIndex > -1) { Worklog worklog = new Worklog(); worklog.ID = ((Product)comboBox1.SelectedItem).ID; worklog.销售 = (selectStaffControl1.SelectedStaffs != null && selectStaffControl1.SelectedStaffs.Count > 0) ? selectStaffControl1.SelectedStaffs[0] : null; worklog.日期 = DateTime.Parse(textBox3.Text.Trim()); worklog.客户 = textBox1.Text.Trim(); worklog.电话 = textBox2.Text.Trim(); worklog.是否自访 = checkBox1.Checked; worklog.是否老会员 = checkBox2.Checked; worklog.是否电话拜访 = checkBox3.Checked; worklog.性别 = (性别)Enum.ToObject(typeof(性别), comboBox2.SelectedIndex); worklog.意向 = textBox4.Text.Trim(); worklog.住址 = textBox5.Text.Trim(); worklog.备注 = textBox6.Text; WorklogLogic rl = WorklogLogic.GetInstance(); if (rl.UpdateWorklog(worklog)) { LoadWorklogs(); MessageBox.Show("修改成功!"); } } else { MessageBox.Show("先选定要修改的工作日报!"); } }
public bool UpdateWorklog(Worklog element) { string sql = "update TF_Worklog set 销售=" + element.销售.ID + ", 日期='" + element.日期 + "', 客户='" + element.客户 + "', 电话='" + element.电话 + "', 是否自访=" + (element.是否自访 ? "1" : "0") + ", 是否老会员=" + (element.是否老会员 ? "1" : "0") + ", 是否电话拜访=" + (element.是否电话拜访 ? "1" : "0") + ", 性别=" + (int)element.性别 + ", 意向='" + element.意向 + "', 住址='" + element.住址 + "', 备注='" + element.备注 + "' where ID=" + element.ID; int r = sqlHelper.ExecuteSql(sql); return(r > 0); }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.SelectedIndex > -1) { Worklog worklog = comboBox1.SelectedItem as Worklog; if (worklog != null) { selectStaffControl1.SelectedStaffs = new List <Staff>() { worklog.销售 }; textBox1.Text = worklog.客户; monthCalendar1.SelectionStart = worklog.日期; textBox3.Text = worklog.日期.ToString("yyyy-MM-dd"); textBox2.Text = worklog.电话; checkBox1.Checked = worklog.是否自访; checkBox2.Checked = worklog.是否老会员; checkBox3.Checked = worklog.是否电话拜访; comboBox2.SelectedIndex = (int)worklog.性别; textBox4.Text = worklog.意向; textBox5.Text = worklog.住址; textBox6.Text = worklog.备注; } } }
public List <Worklog> GetAllWorklogs() { List <Worklog> elements = new List <Worklog>(); string sql = "select * from TF_Worklog"; DataTable dt = sqlHelper.Query(sql); if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { Worklog element = new Worklog(); element.ID = Convert.ToInt32(dt.Rows[i]["ID"]); element.销售 = StaffLogic.GetInstance().GetStaff(Convert.ToInt32(dt.Rows[i]["销售"])); element.日期 = Convert.ToDateTime(dt.Rows[i]["日期"]); element.客户 = dt.Rows[i]["客户"].ToString(); element.电话 = dt.Rows[i]["电话"].ToString(); element.是否自访 = Convert.ToBoolean(dt.Rows[i]["是否自访"]); element.是否老会员 = Convert.ToBoolean(dt.Rows[i]["是否老会员"]); element.是否电话拜访 = Convert.ToBoolean(dt.Rows[i]["是否电话拜访"]); element.性别 = (性别)Enum.ToObject(typeof(性别), Convert.ToInt32(dt.Rows[i]["性别"])); element.意向 = dt.Rows[i]["意向"].ToString(); element.住址 = dt.Rows[i]["住址"].ToString(); element.备注 = dt.Rows[i]["备注"].ToString(); elements.Add(element); } } return(elements); }
public bool DeleteWorklog(Worklog element) { string sql = "delete from TF_Worklog where ID=" + element.ID; int r = sqlHelper.ExecuteSql(sql); return(r > 0); }
public int AddWorklog(Worklog element) { string sql = "insert into TF_Worklog (销售, 日期, 客户, 电话, 是否自访, 是否老会员, 是否电话拜访, 性别, 意向, 住址, 备注) values (" + element.销售.ID + ", '" + element.日期 + "', '" + element.客户 + "', '" + element.电话 + "', " + (element.是否自访 ? "1" : "0") + ", " + (element.是否老会员 ? "1" : "0") + ", " + (element.是否电话拜访 ? "1" : "0") + ", " + (int)element.性别 + ", '" + element.意向 + "', '" + element.住址 + "', '" + element.备注 + "'); select SCOPE_IDENTITY()"; object obj = sqlHelper.ExecuteSqlReturn(sql); int R; if (obj != null && obj != DBNull.Value && int.TryParse(obj.ToString(), out R)) { return(R); } else { return(0); } }
private void button3_Click(object sender, EventArgs e) { if (comboBox1.SelectedIndex > -1) { if (MessageBox.Show("确定要删除该工作日报?", "删除提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK) { Worklog worklog = (Worklog)comboBox1.SelectedItem; if (WorklogLogic.GetInstance().DeleteWorklog(worklog)) { LoadWorklogs(); } } } else { MessageBox.Show("先选定要删除的工作日报!"); } }
public Worklog GetWorklog(int id) { string sql = "select * from TF_Worklog where ID=" + id; DataTable dt = sqlHelper.Query(sql); if (dt != null && dt.Rows.Count > 0) { Worklog element = new Worklog(); element.ID = id; element.销售 = StaffLogic.GetInstance().GetStaff(Convert.ToInt32(dt.Rows[0]["销售"])); element.日期 = Convert.ToDateTime(dt.Rows[0]["日期"]); element.客户 = dt.Rows[0]["客户"].ToString(); element.电话 = dt.Rows[0]["电话"].ToString(); element.是否自访 = Convert.ToBoolean(dt.Rows[0]["是否自访"]); element.是否老会员 = Convert.ToBoolean(dt.Rows[0]["是否老会员"]); element.是否电话拜访 = Convert.ToBoolean(dt.Rows[0]["是否电话拜访"]); element.性别 = (性别)Enum.ToObject(typeof(性别), Convert.ToInt32(dt.Rows[0]["性别"])); element.意向 = dt.Rows[0]["意向"].ToString(); element.住址 = dt.Rows[0]["住址"].ToString(); element.备注 = dt.Rows[0]["备注"].ToString(); return(element); } return(null); }