123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395 |
- using LYFZ.BLL;
- using LYFZ.DAL;
- using LYFZ.Model;
- using LYFZ.Software.MainBusiness.DoorCityProcess;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace LYFZ.Software.MainBusiness.Customers.OldCustomer
- {
- /// <summary>
- /// 添加(Zhuangtai=添加) 修改(可订单号:或根据修改的表对应赋值)
- /// </summary>
- public partial class FrmAddContacts : LYFZ.Software.UI.Customers.OldCustomer.FrmAddContacts
- {
- LYFZ.BLL.BLL_ErpOrder orbll = new BLL_ErpOrder();
- public LYFZ.Model.Model_ErpCustomer model = null;
- BLL_ErpCustomer ctbll = new BLL_ErpCustomer();
- /// <summary>
- /// 状态 添加还是编辑
- /// </summary>
- public string Zhuangtai = "";
- /// <summary>
- /// 客户组编号
- /// </summary>
- public string GP = "";
- //修改操作时 传入客户信息ID 客户组ID
- /// <summary>
- /// 个人信息ID
- /// </summary>
- public string YouID = "";
- /// <summary>
- /// 客户组ID
- /// </summary>
- public string GMID = "";
- /// <summary>
- /// 判断是否 其他客户调用
- /// </summary>
- public bool Qita;
- public FrmAddContacts()
- {
- this.txtCus_FixedPhone.KeyPress += txtCus_FixedPhone_KeyPress;
- this.btnUnbind.Click += btnUnbind_Click;
- }
- LYFZ.BLL.BLL_ErpSystemCategory scbll = new BLL.BLL_ErpSystemCategory();
- BLL_ErpCustomerGroupMembers gmbll = new BLL_ErpCustomerGroupMembers();
- Model_ErpCustomerGroupMembers modelGm = null;
- List<Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
- /// <summary>
- /// 窗体加载事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void FrmAddContacts_Shown(object sender, EventArgs e)
- {
- try
- {
- LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.HidePhoneControls(this.txtCus_Telephone);
- LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.HidePhoneControls(this.txtCus_FixedPhone);
- //获取客户区域,客户来源,生肖,客户关系
- LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_ClientSourec("AAAAAAC", this.cmbtxtCus_Region, strHideFiled: "");
- DataTable dt_tbl = scbll.GetList(" Sc_ClassParentID = '" + scbll.GetModel("BFABDBAJBJCEBDJCJ").ID.ToString().Trim() + "'").Tables[0];
- for (int i = 0; i < dt_tbl.Rows.Count; i++)
- { this.cmbCus_Relations.Items.Add(dt_tbl.Rows[i]["Sc_ClassName"].ToString().Trim()); }
- if (this.Zhuangtai == "添加")
- {
- this.Text = "新增联系人";
- this.btnSave.Text = "添加";
- if (this.Qita)
- { this.labelEx15.Visible = false; this.cmbCus_Relations.Visible = false; }
- }
- if (this.Zhuangtai == "编辑")
- {
- this.panelMicroID.Visible = true;
- this.btnUnbind.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.MicroInfo, CustomAttributes.OperatingAuthority.MicroInfo_Unbind);
- if (this.GMID != "")
- {
- this.modelGm = gmbll.GetModel(Convert.ToInt32(GMID.Trim()));
- this.cmbCus_Relations.Text = this.modelGm.GM_Relation;
- }
- else
- { this.labelEx15.Visible = false; this.cmbCus_Relations.Visible = false; }
- this.model = ctbll.GetModel(Convert.ToInt32(YouID));
- this.Text = "编辑联系人";
- this.txtCus_Name.Text = this.model.Cus_Name;
- if (this.model.Cus_Sex == false)
- { this.radCus_Nan.Checked = true; }
- else { this.radCus_Nv.Checked = true; }
- this.txtCus_Birthday.Text = model.Cus_Birthday;
- if (this.model.Cus_BirthdayLunar == "1")
- { this.chkCus_Lunar.Checked = true; }
- this.txtCus_QQ.Text = this.model.Cus_QQ;
- this.txtCus_MicroSignal.Text = this.model.Cus_MicroSignal;
- this.txtCus_Telephone.Text = this.model.Cus_Telephone;
- this.txtCus_FixedPhone.Text = this.model.Cus_FixedPhone;
- this.cmbtxtCus_Region.Text = this.model.Cus_Region;
- this.txtCus_Address.Text = this.model.Cus_Address;
- this.txtCus_WorkUnit.Text = this.model.Cus_WorkUnit;
- if (!string.IsNullOrEmpty(this.model.Cus_OpenID.Trim()))
- { this.txtMicroID.Text = "已绑定"; }
- else
- { this.txtMicroID.Text = "未绑定"; }
- }
- //如果不等于空,修改DGV的信息
- if (this.model != null && GP == "")
- {
- this.Text = "编辑联系人";
- this.txtCus_Name.Text = this.model.Cus_Name;
- if (this.model.Cus_Sex == false)
- { this.radCus_Nan.Checked = true; }
- else { this.radCus_Nv.Checked = true; }
- this.txtCus_Birthday.Text = this.model.Cus_Birthday;
- if (this.model.Cus_BirthdayLunar == "1")
- { this.chkCus_Lunar.Checked = true; }
- this.txtCus_QQ.Text = this.model.Cus_QQ;
- this.txtCus_MicroSignal.Text = this.model.Cus_MicroSignal;
- this.txtCus_Telephone.Text = this.model.Cus_Telephone;
- this.txtCus_FixedPhone.Text = this.model.Cus_FixedPhone;
- this.cmbtxtCus_Region.Text = this.model.Cus_Region;
- this.txtCus_Address.Text = this.model.Cus_Address;
- this.txtCus_WorkUnit.Text = this.model.Cus_WorkUnit;
- this.cmbCus_Relations.Text = this.model.Cus_Relations;
- if (!string.IsNullOrEmpty(this.model.Cus_OpenID.Trim()))
- { this.txtMicroID.Text = "已绑定"; }
- else
- { this.txtMicroID.Text = "未绑定"; }
- }
- }
- catch (Exception ex)
- { MessageBoxCustom.Show(ex.Message); }
- }
- /// <summary>
- /// 解绑微信
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void btnUnbind_Click(object sender, EventArgs e)
- {
- if (this.txtMicroID.Text.Trim() == "已绑定")
- {
- if (MessageBoxCustom.Show("是否要解除绑定?", "温馨提示!", MessageBoxButtons.YesNo) == DialogResult.No)
- { return; }
- LYFZ.Model.Model_ErpCustomer model = ctbll.GetModel(this.model.ID);
- model.Cus_OpenID = "";
- model.Cus_UpdateDateTime = SDateTime.Now;
- model.Cus_UpdateName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
- if (ctbll.Update(model))
- {
- MessageBoxCustom.Show("解绑成功!");
- this.txtMicroID.Text = "未绑定";
- }
- else
- { MessageBoxCustom.Show("解绑失败"); }
- }
- }
- /// <summary>
- /// 保存
- /// </summary>
- protected override void btnSave_Click(object sender, EventArgs e)
- {
- if (Zhuangtai == "编辑")
- {
- #region 保存时
- try
- {
- #region 判断手机是否存在
- string StrPhone = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.MaskedTextBoxExGetText(this.txtCus_Telephone);
- if (!string.IsNullOrEmpty(StrPhone))
- {
- if (StrPhone.Length != 11)
- { MessageBoxCustom.Show("手机号码必须为11位数!"); return; }
- DataTable tblClient = orbll.GetView_Custom("tb_ErpCustomer", StrWhere: "Cus_Telephone = '" + StrPhone + "' and ID != '" + YouID + "'", ShowColumnName: "ID").Tables[0];
- if (tblClient.Rows.Count > 0)
- { MessageBoxCustom.Show("手机号已存在"); return; }
- }
- #endregion
- #region 输入不能为空
- if (string.IsNullOrEmpty(this.txtCus_Name.Text))
- { MessageBoxCustom.Show("姓名不能为空"); return; }
- int intMasse = this.txtCus_Birthday.CheckDateValue(this.txtCus_Birthday, chkCus_Lunar);
- if (intMasse == 1) { MessageBoxCustom.Show("生日日期日期格式输入错误"); return; }
- else if (intMasse == 2)
- { MessageBoxCustom.Show("生日日期:" + this.txtCus_Birthday.StrValue.Trim() + "不是公历日期,若要保存请勾上农历"); return; }
- //如果有没客户组编号,可能是其他客户
- if (GMID != "")
- {
- if (string.IsNullOrEmpty(cmbCus_Relations.Text))
- { MessageBoxCustom.Show("与主客户的关系不能为空!"); return; }
- }
- #endregion
- #region 取值
- model.Cus_Name = LYFZ.BLL.OtherCommonModel.ClearSpecialCharacter(this.txtCus_Name.Text.ToString().Trim());
- model.Cus_NamePinyin = LYFZ.Command.Command_ChineseToPinyin.GetChineseSpellPinyin(model.Cus_Name).ToLower();
- if (this.radCus_Nan.Checked == true)
- { model.Cus_Sex = false; }
- else
- { model.Cus_Sex = true; }
- model.Cus_Telephone = StrPhone;
- model.Cus_Birthday = "";
- model.Cus_BirthdayLunar = "";
- model.Cus_Zodiac = "";
- if (txtCus_Birthday.StrValue.Trim() != "")
- {
- model.Cus_Birthday = txtCus_Birthday.StrValue.Trim();
- model.Cus_Zodiac = LYFZ.Command.Command_CalendarTurnLunar.GetZodiac(this.txtCus_Birthday.StrValue.Trim(), this.chkCus_Lunar.Checked);
- if (chkCus_Lunar.Checked == true)
- { model.Cus_BirthdayLunar = "1"; }
- else
- { model.Cus_BirthdayLunar = "0"; }
- }
- model.Cus_MicroSignal = this.txtCus_MicroSignal.Text.ToString().Trim();
- model.Cus_QQ = this.txtCus_QQ.Text.ToString().Trim();
- model.Cus_Address = this.txtCus_Address.Text.ToString().Trim();
- model.Cus_FixedPhone = this.txtCus_FixedPhone.Text.ToString().Trim();
- model.Cus_Region = this.cmbtxtCus_Region.Text.ToString().Trim();
- model.Cus_WorkUnit = this.txtCus_WorkUnit.Text.ToString().Trim();
- model.Cus_UpdateDateTime = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime();
- model.Cus_UpdateName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
- //添加到LIst
- clist.Add(ctbll.GetUpdateCommandInfo(model));
- //如果有没客户组编号,可能是其他客户
- if (GMID != "")
- {
- modelGm.GM_Relation = cmbCus_Relations.Text.ToString().Trim();
- clist.Add(gmbll.GetUpdateCommandInfo(modelGm));
- }
- #endregion
- //执行sql事务
- if (LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist) > 0)
- {
- if (GP != "")
- { DAL_ErpCustomer.UpdateAggregationCustomer(GP); }
- //日志
- LYFZ.BLL.BLL_ErpSystemLogs.WriteSystemLog(LYFZ.EnumPublic.SystemLogsType.修改客户资料, "修改客户:'" + model.Cus_Name + "'资料,时间:" + SDateTime.Now, LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID, LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name);
- MessageBoxCustom.Show("修改成功");
- this.DialogResult = DialogResult.OK;
- }
- else
- { MessageBoxCustom.Show("修改失败"); }
- }
- catch (Exception ex)
- { MessageBoxCustom.Show(ex.Message); }
- #endregion
- }
- if (Zhuangtai == "添加")
- {
- #region 添加时
- model = new Model.Model_ErpCustomer();
- try
- {
- #region 不能为空
- if (string.IsNullOrEmpty(this.txtCus_Name.Text))
- { MessageBoxCustom.Show("姓名或不能为空"); return; }
- string StrPhone = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.MaskedTextBoxExGetText(this.txtCus_Telephone);
- if (!string.IsNullOrEmpty(txtCus_Telephone.Text))
- {
- if (StrPhone.Length != 11)
- { MessageBoxCustom.Show("手机号码必须为11位数!"); return; }
- DataTable tblClient = orbll.GetView_Custom("tb_ErpCustomer", StrWhere: "Cus_Telephone = '" + StrPhone + "'", ShowColumnName: "ID").Tables[0];
- if (tblClient.Rows.Count > 0)
- { MessageBoxCustom.Show("手机号已存在"); return; }
- }
- if (string.IsNullOrEmpty(cmbCus_Relations.Text) && !Qita)
- { MessageBoxCustom.Show("与主客户的关系不能为空!"); return; }
- int intMasse = this.txtCus_Birthday.CheckDateValue(this.txtCus_Birthday, this.chkCus_Lunar);
- if (intMasse == 1) { MessageBoxCustom.Show("客户生日日期格式输入错误!"); return; }
- else if (intMasse == 2)
- { MessageBoxCustom.Show("客户生日:" + this.txtCus_Birthday.StrValue.Trim() + "不是公历日期,若要保存请勾上农历!"); return; }
- #endregion
- model.Cus_CustomerNumber = LYFZ.BLL.BLL_ErpCustomer.GetClientNumber();//获取新编号
- model.Cus_DividedShop = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetLocalCompanyInfoID();
- model.Cus_Type = "";
- model.Cus_Name = LYFZ.BLL.OtherCommonModel.ClearSpecialCharacter(this.txtCus_Name.Text);
- model.Cus_NamePinyin = LYFZ.Command.Command_ChineseToPinyin.GetChineseSpellPinyin(model.Cus_Name).ToLower();
- if (this.radCus_Nan.Checked == true)
- { model.Cus_Sex = false; }
- else { model.Cus_Sex = true; }
- model.Cus_Birthday = txtCus_Birthday.StrValue.Trim();
- if (model.Cus_Birthday != "")
- {
- model.Cus_Zodiac = LYFZ.Command.Command_CalendarTurnLunar.GetZodiac(this.txtCus_Birthday.StrValue.Trim(), this.chkCus_Lunar.Checked);
- if (chkCus_Lunar.Checked == true)
- { model.Cus_BirthdayLunar = "1"; }
- else
- { model.Cus_BirthdayLunar = "0"; }
- }
- else
- {
- model.Cus_Zodiac = "";
- model.Cus_Birthday = "";
- model.Cus_BirthdayLunar = "";
- }
- model.Cus_Telephone = StrPhone;
- model.Cus_MicroSignal = this.txtCus_MicroSignal.Text.ToString().Trim();
- model.Cus_QQ = this.txtCus_QQ.Text.ToString().Trim();
- model.Cus_Address = this.txtCus_Address.Text.ToString().Trim();
- model.Cus_FixedPhone = this.txtCus_FixedPhone.Text.ToString().Trim();
- model.Cus_Region = this.cmbtxtCus_Region.Text.ToString().Trim();
- model.Cus_WorkUnit = this.txtCus_WorkUnit.Text.ToString().Trim();
- model.Cus_Relations = cmbCus_Relations.Text.ToString().Trim();
- model.Cus_CreateDateTime = SDateTime.Now;
- model.Cus_CreateName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
- if (MessageBoxCustom.Show("是否添加", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
- {
- //如果为true 侧是其他客户进入此窗体
- if (Qita)
- {
- if (ctbll.Add(model))
- {
- this.DialogResult = DialogResult.OK;
- //日志
- LYFZ.BLL.BLL_ErpSystemLogs.WriteSystemLog(LYFZ.EnumPublic.SystemLogsType.添加客户资料, "添加客户:'" + model.Cus_Name + "'资料,客户编号:" + model.Cus_CustomerNumber + ",时间:" + SDateTime.Now, LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID, LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name);
- }
- else { MessageBoxCustom.Show("添加失败!"); }
- return;
- }
- this.DialogResult = DialogResult.OK;
- }
- }
- catch (Exception ex) { MessageBoxCustom.Show(ex.Message); }
- #endregion
- }
- }
- /// <summary>
- /// 关闭
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void btnClose_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- /// <summary>
- /// 文本框输入
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void txtCus_Telephone_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (!Char.IsNumber(e.KeyChar) && !Char.IsControl(e.KeyChar))
- { e.Handled = true; }
- }
- /// <summary>
- /// 文本框输入
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void txtCus_QQ_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (!Char.IsNumber(e.KeyChar) && !Char.IsControl(e.KeyChar))
- { e.Handled = true; }
- }
- /// <summary>
- /// 文本框输入
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void txtCus_FixedPhone_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (!Char.IsNumber(e.KeyChar) && !Char.IsControl(e.KeyChar))
- { e.Handled = true; }
- }
- /// <summary>
- /// 设置客户区域
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void btnRegion_Click(object sender, EventArgs e)
- {
- LYFZ.Software.MainBusiness.InitialSet.FrmSystemSet set = new InitialSet.FrmSystemSet();
- set.TypeName = "AAAAAAC";
- set.Version = "Version";
- if (set.ShowDialog() == DialogResult.OK)
- { LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_ClientSourec("AAAAAAC", this.cmbtxtCus_Region, strHideFiled: ""); }
- }
- }
- }
|