private void mnuEditTrace_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; if (DBGridTrace.CurrentRow == null) { return; } modCustomerLog mod = (modCustomerLog)DBGridTrace.CurrentRow.DataBoundItem; EditCustomerLog frm = new EditCustomerLog(); frm.EditItem(mod); if (frm.ShowDialog() == DialogResult.OK) { LoadTraceInfo(mod.CustId); } } catch (Exception ex) { MessageBox.Show(ex.Message, clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } finally { this.Cursor = Cursors.Default; } }
private void toolDel_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; if (DBGrid.CurrentRow == null) { return; } if (MessageBox.Show(clsTranslate.TranslateString("Do you really want to delete it?"), clsTranslate.TranslateString("Confirm"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } modCustomerLog mod = (modCustomerLog)DBGrid.CurrentRow.DataBoundItem; bool ret = _dal.Delete(mod.Id, out Util.emsg); if (ret) { LoadData(); } else { MessageBox.Show(Util.emsg, clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch (Exception ex) { MessageBox.Show(ex.Message, clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } finally { this.Cursor = Cursors.Default; } }
public void EditItem(modCustomerLog mod) { txtCustId.Text = mod.CustId; txtCustName.Text = mod.CustName; txtId.Text = mod.Id.ToString(); cboActionType.SelectedValue = mod.ActionCode; txtActionSubject.Text = mod.ActionSubject; txtActionMan.Text = mod.ActionMan; txtObjectName.Text = mod.ObjectName; txtVenue.Text = mod.Venue; dtpFromTime.Text = mod.FromTime; dtpToTime.Text = mod.ToTime; txtActionContent.Text = mod.ActionContent; }
/// <summary> /// delete a customerlog /// <summary> /// <param name=id>id</param> /// <param name=out emsg>return error message</param> /// <returns>true/false</returns> public bool Delete(int id, out string emsg) { try { modCustomerLog mod = GetItem(id, out emsg); if (mod == null) { emsg = null; return(true); } dalUserList dalu = new dalUserList(); DateTime svrtime = dalu.GetServerTime(out emsg); TimeSpan ts1 = new TimeSpan(svrtime.Ticks); TimeSpan ts2 = new TimeSpan(DateTime.Parse(mod.ToTime).Ticks); TimeSpan ts = ts1.Subtract(ts2).Duration(); if (ts.Days < 0) { emsg = "您不能删除未来的工作日志!"; return(false); } dalSysParameters dalp = new dalSysParameters(); int delaydays = Convert.ToInt32(dalp.GetParaValue("CUSTOMER_LOG_DELAY_DAYS")); if (ts.Days >= delaydays) { emsg = "您提交的日期不能超过" + delaydays.ToString() + "天"; return(false); } string sql = string.Format("delete customer_log where id={0} ", id); int i = SqlHelper.ExecuteNonQuery(sql); if (i > 0) { emsg = null; return(true); } else { emsg = "Unknown error when ExecuteNonQuery!"; return(false); } } catch (Exception ex) { emsg = dalUtility.ErrorMessage(ex.Message); return(false); } }
/// <summary> /// get table record /// <summary> /// <param name=id>id</param> /// <param name=out emsg>return error message</param> ///<returns>get a record detail of customerlog</returns> public modCustomerLog GetItem(int?id, out string emsg) { try { //Execute a query to read the categories string sql = string.Format("select id,cust_id,cust_name,action_code,action_type,action_man,form_id,action_subject,action_content,object_name,venue,from_time,to_time,scores,ad_flag,trace_flag,update_user,update_time from customer_log where ID={0} order by id", id); using (SqlDataReader rdr = SqlHelper.ExecuteReader(sql)) { if (rdr.Read()) { modCustomerLog model = new modCustomerLog(); model.Id = dalUtility.ConvertToInt(rdr["id"]); model.CustId = dalUtility.ConvertToString(rdr["cust_id"]); model.CustName = dalUtility.ConvertToString(rdr["cust_name"]); model.ActionCode = dalUtility.ConvertToString(rdr["action_code"]); model.ActionType = dalUtility.ConvertToString(rdr["action_type"]); model.ActionMan = dalUtility.ConvertToString(rdr["action_man"]); model.FormId = dalUtility.ConvertToString(rdr["form_id"]); model.ActionSubject = dalUtility.ConvertToString(rdr["action_subject"]); model.ActionContent = dalUtility.ConvertToString(rdr["action_content"]); model.ObjectName = dalUtility.ConvertToString(rdr["object_name"]); model.Venue = dalUtility.ConvertToString(rdr["venue"]); model.FromTime = dalUtility.ConvertToString(rdr["from_time"]); model.ToTime = dalUtility.ConvertToString(rdr["to_time"]); model.Scores = dalUtility.ConvertToDecimal(rdr["scores"]); model.AdFlag = dalUtility.ConvertToInt(rdr["ad_flag"]); model.TraceFlag = dalUtility.ConvertToInt(rdr["trace_flag"]); model.UpdateUser = dalUtility.ConvertToString(rdr["update_user"]); model.UpdateTime = dalUtility.ConvertToDateTime(rdr["update_time"]); emsg = null; return(model); } else { emsg = "Error on read data"; return(null); } } } catch (Exception ex) { emsg = dalUtility.ErrorMessage(ex.Message); return(null); } }
/// <summary> /// update a customerlog /// <summary> /// <param name=id>id</param> /// <param name=mod>model object of customerlog</param> /// <param name=out emsg>return error message</param> /// <returns>true/false</returns> public bool Update(int id, modCustomerLog mod, out string emsg) { try { dalUserList dalu = new dalUserList(); DateTime svrtime = dalu.GetServerTime(out emsg); TimeSpan ts1 = new TimeSpan(svrtime.Ticks); TimeSpan ts2 = new TimeSpan(DateTime.Parse(mod.ToTime).Ticks); TimeSpan ts = ts1.Subtract(ts2).Duration(); if (ts.Days < 0) { emsg = "您不能更新未来的工作日志!"; return(false); } dalSysParameters dalp = new dalSysParameters(); int delaydays = Convert.ToInt32(dalp.GetParaValue("CUSTOMER_LOG_DELAY_DAYS")); if (ts.Days >= delaydays) { emsg = "你提交的日期不能超过" + delaydays.ToString() + "天"; return(false); } string sql = string.Format("update customer_log set cust_id='{0}',cust_name='{1}',action_code='{2}',action_type='{3}',action_man='{4}',form_id='{5}',action_subject='{6}',action_content='{7}',object_name='{8}',venue='{9}',from_time='{10}',to_time='{11}',scores={12},ad_flag={13},update_user='******',update_time=getdate() where id={15}", mod.CustId, mod.CustName, mod.ActionCode, mod.ActionType, mod.ActionMan, mod.FormId, mod.ActionSubject, mod.ActionContent, mod.ObjectName, mod.Venue, mod.FromTime, mod.ToTime, mod.Scores, mod.AdFlag, mod.UpdateUser, id); int i = SqlHelper.ExecuteNonQuery(sql); if (i > 0) { emsg = null; return(true); } else { emsg = "Unknown error when ExecuteNonQuery!"; return(false); } } catch (Exception ex) { emsg = dalUtility.ErrorMessage(ex.Message); return(false); } }
private void toolSave_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; if (dtpFromTime.Value < Util.modperiod.StartDate) { MessageBox.Show("该日期的数据已锁定,不能更新数据!", clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); dtpFromTime.Focus(); return; } if (string.IsNullOrEmpty(txtActionMan.Text.Trim())) { MessageBox.Show(clsTranslate.TranslateString("Action Man") + clsTranslate.TranslateString(" can not be null!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtActionMan.Focus(); return; } if (string.IsNullOrEmpty(txtActionSubject.Text.Trim())) { MessageBox.Show(clsTranslate.TranslateString("Action Subject") + clsTranslate.TranslateString(" can not be null!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtActionSubject.Focus(); return; } if (string.IsNullOrEmpty(txtActionContent.Text.Trim())) { MessageBox.Show(clsTranslate.TranslateString("Action Content") + clsTranslate.TranslateString(" can not be null!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtActionContent.Focus(); return; } if (Util.GetStrLength(txtActionContent.Text.Trim()) < 20) { MessageBox.Show(clsTranslate.TranslateString("Action Content") + clsTranslate.TranslateString(" length must >= 20!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtActionContent.Focus(); return; } if (Util.GetStrLength(txtActionContent.Text.Trim()) > 1024) { MessageBox.Show(clsTranslate.TranslateString("Action Content") + clsTranslate.TranslateString(" length must <= 1024!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtActionContent.Focus(); return; } if (string.IsNullOrEmpty(txtVenue.Text.Trim())) { MessageBox.Show(clsTranslate.TranslateString("Venue") + clsTranslate.TranslateString(" can not be null!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtVenue.Focus(); return; } if (string.IsNullOrEmpty(txtObjectName.Text.Trim())) { MessageBox.Show(clsTranslate.TranslateString("Object Name") + clsTranslate.TranslateString(" can not be null!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtObjectName.Focus(); return; } if (string.IsNullOrEmpty(cboActionType.Text.Trim())) { MessageBox.Show(clsTranslate.TranslateString("Action Type") + clsTranslate.TranslateString(" can not be null!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); cboActionType.Focus(); return; } if (dtpToTime.Value <= dtpFromTime.Value) { MessageBox.Show("截止时间必须大于起始时间!", clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); dtpToTime.Focus(); return; } modCustomerLog mod = new modCustomerLog(); mod.Id = Convert.ToInt32(txtId.Text); mod.CustId = txtCustId.Text.Trim(); mod.CustName = txtCustName.Text.Trim(); mod.ActionMan = txtActionMan.Text.Trim(); mod.ActionCode = cboActionType.SelectedValue.ToString(); mod.ActionType = cboActionType.Text.Replace("加分", ""); mod.ActionSubject = txtActionSubject.Text.Trim(); mod.ActionContent = txtActionContent.Text.Trim(); mod.ObjectName = txtObjectName.Text.Trim(); mod.Venue = txtVenue.Text.Trim(); mod.AdFlag = 1; mod.TraceFlag = 1; mod.FromTime = dtpFromTime.Text; mod.ToTime = dtpToTime.Text; mod.UpdateUser = Util.UserId; dalCustomerScoreRule dalcsr = new dalCustomerScoreRule(); modCustomerScoreRule modcsr = dalcsr.GetItem(mod.ActionCode, out Util.emsg); mod.Scores = modcsr.Scores; bool ret; if (_action == "ADD" || _action == "NEW") { ret = _dal.Insert(mod, out Util.emsg); } else { ret = _dal.Update(mod.Id, mod, out Util.emsg); } if (ret) { this.DialogResult = DialogResult.OK; this.Dispose(); } else { MessageBox.Show(Util.emsg, clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } finally { this.Cursor = Cursors.Default; } }
/// <summary> /// get all customerlog /// <summary> /// <param name=custidlist>custidlist</param> /// <param name=actioncodelist>actioncodelist</param> /// <param name=actiontypelist>actiontypelist</param> /// <param name=actionmanlist>actionmanlist</param> /// <param name=traceflaglist>traceflaglist</param> /// <param name=fromtime>fromtime</param> /// <param name=totime>totime</param> /// <param name=out emsg>return error message</param> ///<returns>details of all customerlog</returns> public BindingCollection <modCustomerLog> GetIList(string custidlist, string actioncodelist, string actiontypelist, string actionmanlist, string traceflaglist, string fromtime, string totime, out string emsg) { try { BindingCollection <modCustomerLog> modellist = new BindingCollection <modCustomerLog>(); //Execute a query to read the categories string custidwhere = string.Empty; if (!string.IsNullOrEmpty(custidlist) && custidlist.CompareTo("ALL") != 0) { custidwhere = "and cust_id in ('" + custidlist.Replace(",", "','") + "') "; } string actioncodewhere = string.Empty; if (!string.IsNullOrEmpty(actioncodelist) && actioncodelist.CompareTo("ALL") != 0) { actioncodewhere = "and action_code in ('" + actioncodelist.Replace(",", "','") + "') "; } string actiontypewhere = string.Empty; if (!string.IsNullOrEmpty(actiontypelist) && actiontypelist.CompareTo("ALL") != 0) { actiontypewhere = "and action_type in ('" + actiontypelist.Replace(",", "','") + "') "; } string actionmanwhere = string.Empty; if (!string.IsNullOrEmpty(actionmanlist) && actionmanlist.CompareTo("ALL") != 0) { actionmanwhere = "and action_man in ('" + actionmanlist.Replace(",", "','") + "') "; } string traceflagwhere = string.Empty; if (!string.IsNullOrEmpty(traceflaglist) && traceflaglist.CompareTo("ALL") != 0) { traceflagwhere = "and trace_flag in ('" + traceflaglist.Replace(",", "','") + "') "; } string fromtimewhere = string.Empty; if (!string.IsNullOrEmpty(fromtime)) { fromtimewhere = "and from_time >= '" + Convert.ToDateTime(fromtime) + "' "; } if (!string.IsNullOrEmpty(totime)) { fromtimewhere += "and from_time <= '" + Convert.ToDateTime(totime).AddDays(1).AddSeconds(-1) + "' "; } string sql = "select id,cust_id,cust_name,action_code,action_type,action_man,form_id,action_subject,action_content,object_name,venue,from_time,to_time,scores,ad_flag,trace_flag,update_user,update_time " + "from customer_log where 1=1 " + custidwhere + actioncodewhere + actiontypewhere + actionmanwhere + traceflagwhere + fromtimewhere + " order by id"; using (SqlDataReader rdr = SqlHelper.ExecuteReader(sql)) { while (rdr.Read()) { modCustomerLog model = new modCustomerLog(); model.Id = dalUtility.ConvertToInt(rdr["id"]); model.CustId = dalUtility.ConvertToString(rdr["cust_id"]); model.CustName = dalUtility.ConvertToString(rdr["cust_name"]); model.ActionCode = dalUtility.ConvertToString(rdr["action_code"]); model.ActionType = dalUtility.ConvertToString(rdr["action_type"]); model.ActionMan = dalUtility.ConvertToString(rdr["action_man"]); model.FormId = dalUtility.ConvertToString(rdr["form_id"]); model.ActionSubject = dalUtility.ConvertToString(rdr["action_subject"]); model.ActionContent = dalUtility.ConvertToString(rdr["action_content"]); model.ObjectName = dalUtility.ConvertToString(rdr["object_name"]); model.Venue = dalUtility.ConvertToString(rdr["venue"]); model.FromTime = dalUtility.ConvertToString(rdr["from_time"]); model.ToTime = dalUtility.ConvertToString(rdr["to_time"]); model.Scores = dalUtility.ConvertToDecimal(rdr["scores"]); model.AdFlag = dalUtility.ConvertToInt(rdr["ad_flag"]); model.TraceFlag = dalUtility.ConvertToInt(rdr["trace_flag"]); model.UpdateUser = dalUtility.ConvertToString(rdr["update_user"]); model.UpdateTime = dalUtility.ConvertToDateTime(rdr["update_time"]); modellist.Add(model); } } emsg = null; return(modellist); } catch (Exception ex) { emsg = dalUtility.ErrorMessage(ex.Message); return(null); } }