Othercustomers.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Web.UI.WebControls;
  10. using LYFZ.BLL;
  11. namespace LYFZ.Software.MainBusiness.Customers
  12. {
  13. public partial class Othercustomers : LYFZ.Software.UI.Customers.Othercustomers
  14. {
  15. LYFZ.BLL.BLL_ErpOrder orbll = new BLL_ErpOrder();
  16. BLL.BLL_ErpCustomer ctbll = new BLL.BLL_ErpCustomer();
  17. LYFZ.BLL.BLL_ErpSystemLogs slgbll = new BLL_ErpSystemLogs();
  18. public Othercustomers()
  19. {
  20. this.Shown += Othercustomers_Shown;
  21. this.dgvData.CellDoubleClick += dgvData_CellDoubleClick;
  22. this.btnAdd.Click += btnAdd_Click;
  23. this.btnUpdate.Click += btnUpdate_Click;
  24. this.btnDelete.Click += btnDelete_Click;
  25. this.btnClose.Click += btnClose_Click;
  26. this.btnSlect.Click += btnSlect_Click;
  27. this.btnAddExcel.Click += btnAddExcel_Click;
  28. this.chkBaby.CheckedChanged += chkBaby_CheckedChanged;
  29. this.btnExport.Click += btnExport_Click;
  30. this.btnTexting.Click += btnTexting_Click;
  31. this.chkONkh.CheckedChanged += chkONkh_CheckedChanged;
  32. this.Resize += Othercustomers_Resize;
  33. this.btnAddExcel.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OtherCustomerCompetence, LYFZ.CustomAttributes.OperatingAuthority.DataImport);
  34. this.btnAdd.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OtherCustomerCompetence, LYFZ.CustomAttributes.OperatingAuthority.Add);
  35. this.btnUpdate.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OtherCustomerCompetence, LYFZ.CustomAttributes.OperatingAuthority.Update);
  36. this.btnDelete.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OtherCustomerCompetence, LYFZ.CustomAttributes.OperatingAuthority.Delete);
  37. this.btnExport.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OldCustomerCompetence, CustomAttributes.OperatingAuthority.DataExport);
  38. this.btnTexting.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OldCustomerCompetence, CustomAttributes.OperatingAuthority.SMSSend);
  39. }
  40. /// <summary>
  41. /// 窗体加载
  42. /// </summary>
  43. void Othercustomers_Shown(object sender, EventArgs e)
  44. {
  45. string StrColumnName = "ID,Cus_CustomerNumber,客户姓名,性别,客户生日,客户QQ,微信号,客户电话,客户固定电话,客户所在地区,客户工作单位,录入时间,客户地址";
  46. this.dgvData.DataColumns(StrColumnName, strHideField: "ID,Cus_CustomerNumber");
  47. this.dgvData.Columns["录入时间"].Width = 110;
  48. this.dgvData.Columns["客户工作单位"].Width = 250;
  49. this.dgvData.Columns["客户地址"].Width = 500;
  50. this.PublicFunctionRows();
  51. }
  52. /// <summary>
  53. /// 发送短信
  54. /// </summary>
  55. /// <param name="sender"></param>
  56. /// <param name="e"></param>
  57. void btnTexting_Click(object sender, EventArgs e)
  58. {
  59. try
  60. {
  61. string Cus_Telephone = "";
  62. string Sj1 = "";
  63. LYFZ.Software.MainBusiness.SMSManagement.SmsSend.FrmSendSms set = new SMSManagement.SmsSend.FrmSendSms();
  64. if (this.dgvData.SelectedRows.Count == 0)
  65. {
  66. MessageBoxCustom.Show("选择你要发送短信的客户!");
  67. return;
  68. }
  69. for (int i = 0; i < this.dgvData.SelectedRows.Count; i++)
  70. {
  71. Cus_Telephone = this.dgvData.SelectedRows[i].Cells["客户电话"].Value.ToString();
  72. //检查手机合法性
  73. string okPhones = "";
  74. LYFZ.WinAPI.CustomPublicMethod.ValidationPhones(Cus_Telephone.Replace('/', ','), ref okPhones);
  75. if (!string.IsNullOrEmpty(okPhones))
  76. { Sj1 += okPhones + ","; }
  77. }
  78. set.Phone = Sj1.Trim(',');
  79. set.ShowDialog();
  80. }
  81. catch (Exception ex)
  82. { MessageBoxCustom.Show(ex.Message); }
  83. }
  84. /// <summary>
  85. /// 导出
  86. /// </summary>
  87. /// <param name="sender"></param>
  88. /// <param name="e"></param>
  89. void btnExport_Click(object sender, EventArgs e)
  90. {
  91. this.dgvData.ExportDataTable();
  92. }
  93. /// <summary>
  94. /// 儿童客户
  95. /// </summary>
  96. /// <param name="sender"></param>
  97. /// <param name="e"></param>
  98. void chkBaby_CheckedChanged(object sender, EventArgs e)
  99. {
  100. if (this.chkBaby.Checked)
  101. {
  102. this.btnUpdate.Enabled = false;
  103. this.chkONkh.Checked = false;
  104. this.PublicFunctionRows();
  105. }
  106. else
  107. {
  108. this.btnUpdate.Enabled = true;
  109. if (!this.chkONkh.Checked)
  110. this.PublicFunctionRows();
  111. }
  112. }
  113. /// <summary>
  114. /// 未使用过客户
  115. /// </summary>
  116. /// <param name="sender"></param>
  117. /// <param name="e"></param>
  118. void chkONkh_CheckedChanged(object sender, EventArgs e)
  119. {
  120. this.PublicFunctionRows();
  121. }
  122. /// <summary>
  123. /// 导入Excel
  124. /// </summary>
  125. /// <param name="sender"></param>
  126. /// <param name="e"></param>
  127. void btnAddExcel_Click(object sender, EventArgs e)
  128. {
  129. ImportExcel open = new ImportExcel();
  130. open.Type = 0;
  131. if (open.ShowDialog() == DialogResult.OK)
  132. { this.PublicFunctionRows(); }
  133. }
  134. /// <summary>
  135. /// 查询
  136. /// </summary>
  137. /// <param name="sender"></param>
  138. /// <param name="e"></param>
  139. void btnSlect_Click(object sender, EventArgs e)
  140. {
  141. this.PublicFunctionRows();
  142. }
  143. /// <summary>
  144. /// 创建行
  145. /// </summary>
  146. void PublicFunctionRows()
  147. {
  148. if (this.dgvData.Rows.Count > 0)
  149. { this.dgvData.Rows.Clear(); }
  150. DataTable dt = new DataTable();
  151. StringBuilder str = new StringBuilder();
  152. if (this.cmbQueryText.Text != "")
  153. {
  154. 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() + "%')");
  155. }
  156. if (this.chkBaby.Checked)
  157. {
  158. str.Append(" and Cus_Type='儿童'");
  159. }
  160. else
  161. {
  162. str.Append(" and (Cus_Type!='儿童' or Cus_Type is null) ");
  163. }
  164. bool ischkONkh = this.chkONkh.Checked;
  165. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  166. {
  167. if (ischkONkh)
  168. {
  169. dt = DAL.DAL_ErpCustomer.GetInvalidCustomer(str.ToString());
  170. }
  171. else
  172. {
  173. dt = DAL.DAL_ErpCustomer.GetOtherCustomer(str.ToString());
  174. }
  175. });
  176. this.lbStatistics.Text = String.Format("共计 {0} 条", dt.Rows.Count);
  177. if (dt.Rows.Count > 0)
  178. {
  179. #region
  180. for (int t = 0; t < dt.Rows.Count; t++)
  181. {
  182. DataGridViewRow dgvr = new DataGridViewRow();
  183. DataGridViewCell cell = null;
  184. //客户ID
  185. cell = new DataGridViewTextBoxCell();
  186. cell.Value = dt.Rows[t]["ID"].ToString().Trim();
  187. dgvr.Cells.Add(cell);
  188. //客户编号
  189. cell = new DataGridViewTextBoxCell();
  190. cell.Value = dt.Rows[t]["Cus_CustomerNumber"].ToString().Trim();
  191. dgvr.Cells.Add(cell);
  192. //客户姓名
  193. cell = new DataGridViewTextBoxCell();
  194. cell.Value = dt.Rows[t]["Cus_Name"].ToString().Trim();
  195. dgvr.Cells.Add(cell);
  196. //性别
  197. cell = new DataGridViewTextBoxCell();
  198. cell.Value = Convert.ToBoolean(dt.Rows[t]["Cus_Sex"]) ? "女" : "男";
  199. dgvr.Cells.Add(cell);
  200. //客户生日
  201. cell = new DataGridViewTextBoxCell();
  202. cell.Value = dt.Rows[t]["Cus_Birthday"].ToString().Trim() == "1900/1/1 0:00:00" ? "" : dt.Rows[t]["Cus_Birthday"].ToString().Trim();
  203. dgvr.Cells.Add(cell);
  204. //客户QQ
  205. cell = new DataGridViewTextBoxCell();
  206. cell.Value = dt.Rows[t]["Cus_QQ"].ToString().Trim();
  207. dgvr.Cells.Add(cell);
  208. // 微信号
  209. cell = new DataGridViewTextBoxCell();
  210. cell.Value = dt.Rows[t]["Cus_MicroSignal"].ToString().Trim();
  211. dgvr.Cells.Add(cell);
  212. //客户电话
  213. cell = new DataGridViewTextBoxCell();
  214. cell.Value = dt.Rows[t]["Cus_Telephone"].ToString().Trim();
  215. dgvr.Cells.Add(cell);
  216. //客户固定电话
  217. cell = new DataGridViewTextBoxCell();
  218. cell.Value = dt.Rows[t]["Cus_FixedPhone"].ToString().Trim();
  219. dgvr.Cells.Add(cell);
  220. //客户所在地区
  221. cell = new DataGridViewTextBoxCell();
  222. cell.Value = dt.Rows[t]["Cus_Region"].ToString().Trim();
  223. dgvr.Cells.Add(cell);
  224. //客户工作单位
  225. cell = new DataGridViewTextBoxCell();
  226. cell.Value = dt.Rows[t]["Cus_WorkUnit"].ToString().Trim();
  227. dgvr.Cells.Add(cell);
  228. //录入时间
  229. cell = new DataGridViewTextBoxCell();
  230. cell.Value = LYFZ.Command.Command_Validate.DateTimeToString(dt.Rows[t]["Cus_CreateDateTime"], "yyyy-MM-dd HH:mm");
  231. dgvr.Cells.Add(cell);
  232. //客户地址
  233. cell = new DataGridViewTextBoxCell();
  234. cell.Value = dt.Rows[t]["Cus_Address"].ToString().Trim();
  235. dgvr.Cells.Add(cell);
  236. this.dgvData.Rows.Add(dgvr);
  237. }
  238. #endregion
  239. }
  240. this.dgvData.ClearSelection();
  241. }
  242. /// <summary>
  243. /// 列表双击事件
  244. /// </summary>
  245. /// <param name="sender"></param>
  246. /// <param name="e"></param>
  247. void dgvData_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  248. {
  249. try
  250. {
  251. if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
  252. {
  253. this.btnUpdate_Click(this, null);
  254. }
  255. }
  256. catch (Exception ex)
  257. { MessageBoxCustom.Show(ex.Message); }
  258. }
  259. /// <summary>
  260. /// 删除按钮
  261. /// </summary>
  262. void btnDelete_Click(object sender, EventArgs e)
  263. {
  264. try
  265. {
  266. if (this.dgvData.SelectedRows.Count > 0)
  267. {
  268. List<int> ctlist = new List<int>();
  269. if (MessageBoxCustom.Show("是否删除!", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
  270. {
  271. string StrMagess = "";
  272. List<Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
  273. for (int i = 0; i < this.dgvData.SelectedRows.Count; i++)
  274. {
  275. 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];
  276. if (dt.Rows.Count <= 0)
  277. {
  278. clist.Add(ctbll.GetDeleteCommandInfo("Cus_CustomerNumber", "=", this.dgvData.SelectedRows[i].Cells["Cus_CustomerNumber"].Value.ToString().Trim()));
  279. 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())));
  280. }
  281. else
  282. { StrMagess += this.dgvData.SelectedRows[i].Cells["客户姓名"].Value.ToString() + ","; }
  283. }
  284. bool IsDelete = false;
  285. if (clist.Count > 0)
  286. {
  287. if (LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist) > 0)
  288. { IsDelete = true; }
  289. }
  290. if (!string.IsNullOrEmpty(StrMagess))
  291. { StrMagess += "但客户:" + StrMagess.TrimEnd(',') + "已办有会员卡,不允许删除!"; }
  292. if (IsDelete)
  293. { StrMagess = "删除成功!" + StrMagess; }
  294. else
  295. { StrMagess = "删除失败!" + StrMagess; }
  296. MessageBoxCustom.Show(StrMagess);
  297. if (StrMagess.IndexOf("成功") != -1)
  298. { this.PublicFunctionRows(); }
  299. }
  300. }
  301. else
  302. { MessageBoxCustom.Show("请选中要删除的信息!"); }
  303. }
  304. catch (Exception ex)
  305. { MessageBoxCustom.Show(ex.Message); }
  306. }
  307. /// <summary>
  308. /// 更新按钮
  309. /// </summary>
  310. void btnUpdate_Click(object sender, EventArgs e)
  311. {
  312. try
  313. {
  314. if (this.dgvData.Rows.Count > 0)
  315. {
  316. if (this.dgvData.SelectedRows.Count > 0)
  317. {
  318. if (this.dgvData.CurrentRow != null)
  319. {
  320. if (this.dgvData.CurrentRow.Index >= 0 && this.dgvData.CurrentCell.ColumnIndex >= 0)
  321. {
  322. LYFZ.Software.MainBusiness.Customers.OldCustomer.FrmAddContacts frm = new OldCustomer.FrmAddContacts();
  323. frm.YouID = this.dgvData.CurrentRow.Cells["ID"].Value.ToString();
  324. frm.Zhuangtai = "编辑";
  325. if (frm.ShowDialog() == DialogResult.OK)
  326. { this.PublicFunctionRows(); }
  327. }
  328. }
  329. }
  330. else
  331. { MessageBoxCustom.Show("请选择修改信息!"); }
  332. }
  333. }
  334. catch (Exception ex)
  335. { MessageBoxCustom.Show(ex.Message); }
  336. }
  337. /// <summary>
  338. /// 添加按钮
  339. /// </summary>
  340. void btnAdd_Click(object sender, EventArgs e)
  341. {
  342. try
  343. {
  344. LYFZ.Software.MainBusiness.Customers.OldCustomer.FrmAddContacts frm = new OldCustomer.FrmAddContacts();
  345. frm.Zhuangtai = "添加";
  346. frm.Qita = true;
  347. if (frm.ShowDialog() == DialogResult.OK)
  348. {
  349. MessageBoxCustom.Show("添加成功!");
  350. this.PublicFunctionRows();
  351. }
  352. }
  353. catch (Exception ex)
  354. { MessageBoxCustom.Show(ex.Message); }
  355. }
  356. /// <summary>
  357. /// 关闭
  358. /// </summary>
  359. /// <param name="sender"></param>
  360. /// <param name="e"></param>
  361. void btnClose_Click(object sender, EventArgs e)
  362. { this.Close(); }
  363. /// <summary>
  364. /// 窗体大小发生变化
  365. /// </summary>
  366. /// <param name="sender"></param>
  367. /// <param name="e"></param>
  368. void Othercustomers_Resize(object sender, EventArgs e)
  369. {
  370. switch (this.panelONkh.Location.Y)
  371. {
  372. case 3: this.flowLayoutPanel1.Height = 36; break;
  373. case 37: this.flowLayoutPanel1.Height = 70; break;
  374. }
  375. }
  376. }
  377. }