using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Web.UI.WebControls; using LYFZ.BLL; namespace LYFZ.Software.MainBusiness.Customers { public partial class Othercustomers : LYFZ.Software.UI.Customers.Othercustomers { LYFZ.BLL.BLL_ErpOrder orbll = new BLL_ErpOrder(); BLL.BLL_ErpCustomer ctbll = new BLL.BLL_ErpCustomer(); LYFZ.BLL.BLL_ErpSystemLogs slgbll = new BLL_ErpSystemLogs(); public Othercustomers() { this.Shown += Othercustomers_Shown; this.dgvData.CellDoubleClick += dgvData_CellDoubleClick; this.btnAdd.Click += btnAdd_Click; this.btnUpdate.Click += btnUpdate_Click; this.btnDelete.Click += btnDelete_Click; this.btnClose.Click += btnClose_Click; this.btnSlect.Click += btnSlect_Click; this.btnAddExcel.Click += btnAddExcel_Click; this.chkBaby.CheckedChanged += chkBaby_CheckedChanged; this.btnExport.Click += btnExport_Click; this.btnTexting.Click += btnTexting_Click; this.chkONkh.CheckedChanged += chkONkh_CheckedChanged; this.Resize += Othercustomers_Resize; this.btnAddExcel.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OtherCustomerCompetence, LYFZ.CustomAttributes.OperatingAuthority.DataImport); this.btnAdd.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OtherCustomerCompetence, LYFZ.CustomAttributes.OperatingAuthority.Add); this.btnUpdate.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OtherCustomerCompetence, LYFZ.CustomAttributes.OperatingAuthority.Update); this.btnDelete.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OtherCustomerCompetence, LYFZ.CustomAttributes.OperatingAuthority.Delete); this.btnExport.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OldCustomerCompetence, CustomAttributes.OperatingAuthority.DataExport); this.btnTexting.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OldCustomerCompetence, CustomAttributes.OperatingAuthority.SMSSend); } /// /// 窗体加载 /// void Othercustomers_Shown(object sender, EventArgs e) { string StrColumnName = "ID,Cus_CustomerNumber,客户姓名,性别,客户生日,客户QQ,微信号,客户电话,客户固定电话,客户所在地区,客户工作单位,录入时间,客户地址"; this.dgvData.DataColumns(StrColumnName, strHideField: "ID,Cus_CustomerNumber"); this.dgvData.Columns["录入时间"].Width = 110; this.dgvData.Columns["客户工作单位"].Width = 250; this.dgvData.Columns["客户地址"].Width = 500; this.PublicFunctionRows(); } /// /// 发送短信 /// /// /// void btnTexting_Click(object sender, EventArgs e) { try { string Cus_Telephone = ""; string Sj1 = ""; LYFZ.Software.MainBusiness.SMSManagement.SmsSend.FrmSendSms set = new SMSManagement.SmsSend.FrmSendSms(); if (this.dgvData.SelectedRows.Count == 0) { MessageBoxCustom.Show("选择你要发送短信的客户!"); return; } for (int i = 0; i < this.dgvData.SelectedRows.Count; i++) { Cus_Telephone = this.dgvData.SelectedRows[i].Cells["客户电话"].Value.ToString(); //检查手机合法性 string okPhones = ""; LYFZ.WinAPI.CustomPublicMethod.ValidationPhones(Cus_Telephone.Replace('/', ','), ref okPhones); if (!string.IsNullOrEmpty(okPhones)) { Sj1 += okPhones + ","; } } set.Phone = Sj1.Trim(','); set.ShowDialog(); } catch (Exception ex) { MessageBoxCustom.Show(ex.Message); } } /// /// 导出 /// /// /// void btnExport_Click(object sender, EventArgs e) { this.dgvData.ExportDataTable(); } /// /// 儿童客户 /// /// /// void chkBaby_CheckedChanged(object sender, EventArgs e) { if (this.chkBaby.Checked) { this.btnUpdate.Enabled = false; this.chkONkh.Checked = false; this.PublicFunctionRows(); } else { this.btnUpdate.Enabled = true; if (!this.chkONkh.Checked) this.PublicFunctionRows(); } } /// /// 未使用过客户 /// /// /// void chkONkh_CheckedChanged(object sender, EventArgs e) { this.PublicFunctionRows(); } /// /// 导入Excel /// /// /// void btnAddExcel_Click(object sender, EventArgs e) { ImportExcel open = new ImportExcel(); open.Type = 0; if (open.ShowDialog() == DialogResult.OK) { this.PublicFunctionRows(); } } /// /// 查询 /// /// /// void btnSlect_Click(object sender, EventArgs e) { this.PublicFunctionRows(); } /// /// 创建行 /// void PublicFunctionRows() { if (this.dgvData.Rows.Count > 0) { this.dgvData.Rows.Clear(); } DataTable dt = new DataTable(); StringBuilder str = new StringBuilder(); if (this.cmbQueryText.Text != "") { str.Append(" and (Cus_Name like '%" + this.cmbQueryText.Text.Trim() + "%' or Cus_QQ like '%" + this.cmbQueryText.Text.Trim() + "%' or Cus_Telephone like '%" + this.cmbQueryText.Text.Trim() + "%' or Cus_FixedPhone like '%" + this.cmbQueryText.Text.Trim() + "%' or Cus_Region like '%" + this.cmbQueryText.Text.Trim() + "%' or Cus_Address like '%" + this.cmbQueryText.Text.Trim() + "%' or Cus_WorkUnit like '%" + this.cmbQueryText.Text.Trim() + "%')"); } if (this.chkBaby.Checked) { str.Append(" and Cus_Type='儿童'"); } else { str.Append(" and (Cus_Type!='儿童' or Cus_Type is null) "); } bool ischkONkh = this.chkONkh.Checked; LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker) { if (ischkONkh) { dt = DAL.DAL_ErpCustomer.GetInvalidCustomer(str.ToString()); } else { dt = DAL.DAL_ErpCustomer.GetOtherCustomer(str.ToString()); } }); this.lbStatistics.Text = String.Format("共计 {0} 条", dt.Rows.Count); if (dt.Rows.Count > 0) { #region for (int t = 0; t < dt.Rows.Count; t++) { DataGridViewRow dgvr = new DataGridViewRow(); DataGridViewCell cell = null; //客户ID cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["ID"].ToString().Trim(); dgvr.Cells.Add(cell); //客户编号 cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["Cus_CustomerNumber"].ToString().Trim(); dgvr.Cells.Add(cell); //客户姓名 cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["Cus_Name"].ToString().Trim(); dgvr.Cells.Add(cell); //性别 cell = new DataGridViewTextBoxCell(); cell.Value = Convert.ToBoolean(dt.Rows[t]["Cus_Sex"]) ? "女" : "男"; dgvr.Cells.Add(cell); //客户生日 cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["Cus_Birthday"].ToString().Trim() == "1900/1/1 0:00:00" ? "" : dt.Rows[t]["Cus_Birthday"].ToString().Trim(); dgvr.Cells.Add(cell); //客户QQ cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["Cus_QQ"].ToString().Trim(); dgvr.Cells.Add(cell); // 微信号 cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["Cus_MicroSignal"].ToString().Trim(); dgvr.Cells.Add(cell); //客户电话 cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["Cus_Telephone"].ToString().Trim(); dgvr.Cells.Add(cell); //客户固定电话 cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["Cus_FixedPhone"].ToString().Trim(); dgvr.Cells.Add(cell); //客户所在地区 cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["Cus_Region"].ToString().Trim(); dgvr.Cells.Add(cell); //客户工作单位 cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["Cus_WorkUnit"].ToString().Trim(); dgvr.Cells.Add(cell); //录入时间 cell = new DataGridViewTextBoxCell(); cell.Value = LYFZ.Command.Command_Validate.DateTimeToString(dt.Rows[t]["Cus_CreateDateTime"], "yyyy-MM-dd HH:mm"); dgvr.Cells.Add(cell); //客户地址 cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["Cus_Address"].ToString().Trim(); dgvr.Cells.Add(cell); this.dgvData.Rows.Add(dgvr); } #endregion } this.dgvData.ClearSelection(); } /// /// 列表双击事件 /// /// /// void dgvData_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { try { if (e.RowIndex >= 0 && e.ColumnIndex >= 0) { this.btnUpdate_Click(this, null); } } catch (Exception ex) { MessageBoxCustom.Show(ex.Message); } } /// /// 删除按钮 /// void btnDelete_Click(object sender, EventArgs e) { try { if (this.dgvData.SelectedRows.Count > 0) { List ctlist = new List(); if (MessageBoxCustom.Show("是否删除!", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { string StrMagess = ""; List clist = new List(); for (int i = 0; i < this.dgvData.SelectedRows.Count; i++) { DataTable dt = orbll.GetView_Custom("tb_ErpMemberCard", StrWhere: "Mc_CustomerNumber = '" + this.dgvData.SelectedRows[i].Cells["Cus_CustomerNumber"].Value.ToString().Trim() + "' And Mc_Status = '1' And Mc_CradNumber != ''", ShowColumnName: "ID").Tables[0]; if (dt.Rows.Count <= 0) { clist.Add(ctbll.GetDeleteCommandInfo("Cus_CustomerNumber", "=", this.dgvData.SelectedRows[i].Cells["Cus_CustomerNumber"].Value.ToString().Trim())); clist.Add(slgbll.GetAddCommandInfo(LYFZ.BLL.BLL_ErpSystemLogs.GetWriteLogModel(LYFZ.EnumPublic.SystemLogsType.删除客户资料, "删除联系人资料:" + this.dgvData.SelectedRows[i].Cells["客户姓名"].Value.ToString() + ",时间:" + SDateTime.Now, LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID, LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name, StrInfoID: LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetLocalCompanyInfoID()))); } else { StrMagess += this.dgvData.SelectedRows[i].Cells["客户姓名"].Value.ToString() + ","; } } bool IsDelete = false; if (clist.Count > 0) { if (LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist) > 0) { IsDelete = true; } } if (!string.IsNullOrEmpty(StrMagess)) { StrMagess += "但客户:" + StrMagess.TrimEnd(',') + "已办有会员卡,不允许删除!"; } if (IsDelete) { StrMagess = "删除成功!" + StrMagess; } else { StrMagess = "删除失败!" + StrMagess; } MessageBoxCustom.Show(StrMagess); if (StrMagess.IndexOf("成功") != -1) { this.PublicFunctionRows(); } } } else { MessageBoxCustom.Show("请选中要删除的信息!"); } } catch (Exception ex) { MessageBoxCustom.Show(ex.Message); } } /// /// 更新按钮 /// void btnUpdate_Click(object sender, EventArgs e) { try { if (this.dgvData.Rows.Count > 0) { if (this.dgvData.SelectedRows.Count > 0) { if (this.dgvData.CurrentRow != null) { if (this.dgvData.CurrentRow.Index >= 0 && this.dgvData.CurrentCell.ColumnIndex >= 0) { LYFZ.Software.MainBusiness.Customers.OldCustomer.FrmAddContacts frm = new OldCustomer.FrmAddContacts(); frm.YouID = this.dgvData.CurrentRow.Cells["ID"].Value.ToString(); frm.Zhuangtai = "编辑"; if (frm.ShowDialog() == DialogResult.OK) { this.PublicFunctionRows(); } } } } else { MessageBoxCustom.Show("请选择修改信息!"); } } } catch (Exception ex) { MessageBoxCustom.Show(ex.Message); } } /// /// 添加按钮 /// void btnAdd_Click(object sender, EventArgs e) { try { LYFZ.Software.MainBusiness.Customers.OldCustomer.FrmAddContacts frm = new OldCustomer.FrmAddContacts(); frm.Zhuangtai = "添加"; frm.Qita = true; if (frm.ShowDialog() == DialogResult.OK) { MessageBoxCustom.Show("添加成功!"); this.PublicFunctionRows(); } } catch (Exception ex) { MessageBoxCustom.Show(ex.Message); } } /// /// 关闭 /// /// /// void btnClose_Click(object sender, EventArgs e) { this.Close(); } /// /// 窗体大小发生变化 /// /// /// void Othercustomers_Resize(object sender, EventArgs e) { switch (this.panelONkh.Location.Y) { case 3: this.flowLayoutPanel1.Height = 36; break; case 37: this.flowLayoutPanel1.Height = 70; break; } } } }