using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace LYFZ.Software.MainBusiness.Dresses.DressView
{
public class UCDressCustomer : LYFZ.Software.UI.Dresses.DressView.UCDressCustomer
{
LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
LYFZ.BLL.BLL_ErpCustomer ctbll = new BLL.BLL_ErpCustomer();
public UCDressCustomer()
{
this.txtClientName.KeyDown += txtClientName_KeyDown;
this.txtClientName.KeyPress += txtClientName_KeyPress;
this.txtClientFixedPhone.KeyPress += txtClientFixedPhone_KeyPress;
this.txtClientQQ.KeyPress += txtClientQQ_KeyPress;
this.txtClientWorkUnit.KeyPress += txtClientWorkUnit_KeyPress;
this.btnDial.Click += btnDial_Click;
this.btnQQCall.Click += btnQQCall_Click;
this.btnClientSelect.Click += btnClientSelect_Click;
this.btn_CustomerEdit.Click += btn_CustomerEdit_Click;
btn_CustomerEdit.Visible = false;
}
///
/// 保存数据控制
///
///
public LYFZ.Command.Result SaveCustomerData(ref string StrClientName, ref string StrClientTelephone,int indx=1)
{
#region 客户
LYFZ.Command.Result> resultSQL = new Command.Result>();
List clist = new List();
string StrTelephone = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.MaskedTextBoxExGetText(this.txtClientTelephone);
string StrClientNumber = "";
if (!string.IsNullOrEmpty(StrClientName))
{
StrClientName += "/";
}
if (!string.IsNullOrEmpty(StrClientTelephone))
{
StrClientTelephone += "/";
}
StrClientName += this.txtClientName.Text.ToString().Trim();
StrClientTelephone += this.txtClientTelephone.Text.ToString().Trim().Replace(" ", "");
if (this.txtClientName.Tag != null)
{
StrClientNumber = this.txtClientName.Tag.ToString().Trim();
return new Command.Result>()
{
Status = true,
StatusMsg = StrClientNumber
};
}
else
{
if (ctbll.Exists("Cus_Telephone", StrTelephone) == true)//判断手机存在
{
MessageBoxCustom.Show("客户手机已经存在");
return new Command.Result>()
{
Status = false,
StatusMsg = "客户手机已经存在"
};
}
LYFZ.Model.Model_ErpCustomer model = new Model.Model_ErpCustomer();
model.Cus_CustomerNumber = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime().ToString("yyyyMMddHHmmssfff") + indx.ToString();//获取新编号
model.Cus_DividedShop = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetLocalCompanyInfoID();
model.Cus_CustomizeNumber = "";
model.Cus_Type = "订单客户";
model.Cus_ServiceType = "Clothing";
model.Cus_Name = this.txtClientName.Text.ToString().Trim();
model.Cus_Telephone = this.txtClientTelephone.Text.ToString().Trim().Replace(" ","");
model.Cus_QQ = this.txtClientQQ.Text.ToString().Trim();
model.Cus_Address = this.txtClientAddress.Text.ToString().Trim();
model.Cus_WorkUnit = this.txtClientWorkUnit.Text.ToString().Trim();
model.Cus_Birthday = this.txtClientBirthday.StrValue.Trim();
if (this.chkClientBirthdayLunar.Checked == true)
{ model.Cus_BirthdayLunar = "1"; }
else
{ model.Cus_BirthdayLunar = "0"; }
model.Cus_DayForMarriage = this.txtClientDayForMarriage.StrValue.ToString();
if (this.chkClientDayForMarriageLunar.Checked == true)
{ model.Cus_DayForMarriageLunar = "1"; }
else
{ model.Cus_DayForMarriageLunar = "0"; }
model.Cus_CreateDateTime = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime();
model.Cus_CreateName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
clist.Add(ctbll.GetAddCommandInfo(model));
StrClientNumber = model.Cus_CustomerNumber;
return new Command.Result>()
{
Status = true,
StatusMsg = StrClientNumber,
clist = clist
};
}
#endregion
}
public string StrOrderNumber { get; set; }
public bool IsUpdateClientData = true;
public void ReBindOrderNumber()
{
if (!string.IsNullOrEmpty(StrOrderNumber))
{
this.btnClientSelect.Visible = false;
this.txtClientName.Width = this.txtClientQQ.Width;
btn_CustomerEdit.Visible = false;
//buttonForm1.Visible = false;
}
}
public LYFZ.Command.Result CheckCustomerData()
{
if (string.IsNullOrEmpty(this.txtClientName.Text.Trim()))
{
MessageBoxCustom.Show("客户名称不能为空!");
return new LYFZ.Command.Result()
{
Status = false,
StatusMsg = "客户名称不能为空!"
};
}
string StrTelephone = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.MaskedTextBoxExGetText(this.txtClientTelephone);
if (string.IsNullOrEmpty(StrTelephone))
{
MessageBoxCustom.Show("客户手机号码不能为空!");
return new LYFZ.Command.Result()
{
Status = false,
StatusMsg = "客户手机号码不能为空!"
};
}
else
{
if (StrTelephone.Length != 11)
{
MessageBoxCustom.Show("客户手机号码长度不足11位!");
return new LYFZ.Command.Result()
{
Status = false,
StatusMsg = "客户手机号码长度不足11位!"
};
}
}
int intMasse = this.txtClientBirthday.CheckDateValue(this.txtClientBirthday, this.chkClientBirthdayLunar);
if (intMasse == 1)
{
MessageBoxCustom.Show("生日日期日期格式输入错误");
return new LYFZ.Command.Result()
{
Status = false,
StatusMsg = "生日日期日期格式输入错误"
};
}
else if (intMasse == 2)
{
MessageBoxCustom.Show("生日日期:" + this.txtClientBirthday.StrValue.Trim() + "不是公历日期,若要保存请勾上农历");
return new LYFZ.Command.Result()
{
Status = false,
StatusMsg = "生日日期:" + this.txtClientBirthday.StrValue.Trim() + "不是公历日期,若要保存请勾上农历"
};
}
intMasse = this.txtClientDayForMarriage.CheckDateValue(this.txtClientDayForMarriage, this.chkClientDayForMarriageLunar);
if (intMasse == 1)
{
MessageBoxCustom.Show("婚期日期日期格式输入错误");
return new LYFZ.Command.Result()
{
Status = false,
StatusMsg = "婚期日期日期格式输入错误"
};
}
else if (intMasse == 2)
{
MessageBoxCustom.Show("婚期日期:" + this.txtClientDayForMarriage.StrValue.Trim() + "不是公历日期,若要保存请勾上农历");
return new LYFZ.Command.Result()
{
Status = false,
StatusMsg = "婚期日期:" + this.txtClientDayForMarriage.StrValue.Trim() + "不是公历日期,若要保存请勾上农历"
};
}
return new LYFZ.Command.Result()
{
Status = true
};
}
///
/// 清空选择的客户
///
///
///
void txtClientName_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Back)
{
if (this.txtClientName.Tag != null && string.IsNullOrEmpty(this.StrOrderNumber) && this.IsUpdateClientData)
{ this.ClearClientData(); }
}
}
///
/// 客户工作单位输入限制
///
///
///
void txtClientWorkUnit_KeyPress(object sender, KeyPressEventArgs e)
{
if (Convert.ToString(e.KeyChar) == "-")
{ }
else if (!Char.IsNumber(e.KeyChar) && !Char.IsControl(e.KeyChar) && !Char.IsLetterOrDigit(e.KeyChar))
{ e.Handled = true; }
}
///
/// 客户姓名输入限制
///
///
///
void txtClientName_KeyPress(object sender, KeyPressEventArgs e)
{
if (!Char.IsNumber(e.KeyChar) && !Char.IsControl(e.KeyChar) && !Char.IsLetterOrDigit(e.KeyChar) && e.KeyChar != '_' && e.KeyChar != ' ')
{ e.Handled = true; }
}
///
/// 客户固定电话输入限制
///
///
///
void txtClientFixedPhone_KeyPress(object sender, KeyPressEventArgs e)
{
if (Convert.ToString(e.KeyChar) == "-")
{ }
else if (!Char.IsNumber(e.KeyChar) && !Char.IsControl(e.KeyChar))
{ e.Handled = true; }
}
///
/// 客户QQ输入限制
///
///
///
void txtClientQQ_KeyPress(object sender, KeyPressEventArgs e)
{
if (!Char.IsNumber(e.KeyChar) && !Char.IsControl(e.KeyChar))
{ e.Handled = true; }
}
///
/// 清空客户信息
///
void ClearClientData()
{
this.txtClientName.Text = "";
this.txtClientName.Tag = null;
this.txtClientTelephone.Text = "";
this.txtClientFixedPhone.Text = "";
this.txtClientQQ.Text = "";
this.txtClientAddress.Text = "";
this.txtClientWorkUnit.Text = "";
this.txtClientBirthday.Text = "";
this.chkClientBirthdayLunar.Checked = false;
this.txtClientDayForMarriage.Text = "";
this.chkClientDayForMarriageLunar.Checked = false;
this.txtClientName.ReadOnly = false;
this.txtClientTelephone.ReadOnly = false;
this.txtClientQQ.ReadOnly = false;
this.txtClientAddress.ReadOnly = false;
this.txtClientWorkUnit.ReadOnly = false;
this.txtClientBirthday.ReadOnly = false;
this.chkClientBirthdayLunar.Enabled = true;
this.txtClientDayForMarriage.ReadOnly = false;
this.chkClientDayForMarriageLunar.Enabled = true;
this.txtClientFixedPhone.ReadOnly = false;
btn_CustomerEdit.Visible = false;
btn_CustomerEdit.Text = " 编辑";
//buttonForm1.Visible = false;
}
///
/// 拨打电话
///
///
///
void btnDial_Click(object sender, EventArgs e)
{
LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.PhoneCall(LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.MaskedTextBoxExGetText(this.txtClientTelephone));
}
///
/// QQ呼叫
///
///
///
void btnQQCall_Click(object sender, EventArgs e)
{
LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.QQCall(this.txtClientQQ.Text.Trim());
}
///
/// 选择客户
///
///
///
void btnClientSelect_Click(object sender, EventArgs e)
{
LYFZ.Software.MainBusiness.Dresses.DressManagement.FrmCusSelect frm = new DressManagement.FrmCusSelect();
frm.ShowDialog();
if (!string.IsNullOrEmpty(frm.StrClientNumber))
{ this.GetClientData(frm.StrClientNumber); }
}
///
/// 获取客户资料
///
///
///
public void GetClientData(string StrClientNumber)
{
if (!string.IsNullOrEmpty(StrClientNumber))
{
DataTable dt = orbll.GetView_Custom("tb_ErpCustomer", StrWhere: "Cus_CustomerNumber='" + StrClientNumber + "'", ShowColumnName: "Cus_Name,Cus_CustomerNumber,Cus_Telephone,Cus_FixedPhone,Cus_QQ,Cus_Address,Cus_WorkUnit,Cus_Birthday,Cus_BirthdayLunar,Cus_DayForMarriage,Cus_DayForMarriageLunar").Tables[0];
if (dt.Rows.Count > 0)
{
this.txtClientName.Text = dt.Rows[0]["Cus_Name"].ToString().Trim();
this.txtClientName.Tag = dt.Rows[0]["Cus_CustomerNumber"].ToString().Trim();
this.txtClientTelephone.Text = dt.Rows[0]["Cus_Telephone"].ToString().Trim();
this.txtClientFixedPhone.Text = dt.Rows[0]["Cus_FixedPhone"].ToString().Trim();
this.txtClientQQ.Text = dt.Rows[0]["Cus_QQ"].ToString().Trim();
this.txtClientAddress.Text = dt.Rows[0]["Cus_Address"].ToString().Trim();
this.txtClientWorkUnit.Text = dt.Rows[0]["Cus_WorkUnit"].ToString().Trim();
this.txtClientBirthday.Text = dt.Rows[0]["Cus_Birthday"].ToString().Trim();
if (dt.Rows[0]["Cus_BirthdayLunar"].ToString().Trim() == "1")
{ this.chkClientBirthdayLunar.Checked = true; }
else
{ this.chkClientBirthdayLunar.Checked = false; }
this.txtClientDayForMarriage.Text = dt.Rows[0]["Cus_DayForMarriage"].ToString().Trim();
if (dt.Rows[0]["Cus_DayForMarriageLunar"].ToString().Trim() == "1")
{ this.chkClientDayForMarriageLunar.Checked = true; }
else
{ this.chkClientDayForMarriageLunar.Checked = false; }
this.txtClientName.ReadOnly = true;
this.txtClientTelephone.ReadOnly = true;
this.txtClientQQ.ReadOnly = true;
this.txtClientAddress.ReadOnly = true;
this.txtClientWorkUnit.ReadOnly = true;
this.txtClientBirthday.ReadOnly = true;
this.chkClientBirthdayLunar.Enabled = false;
this.txtClientDayForMarriage.ReadOnly = true;
this.chkClientDayForMarriageLunar.Enabled = false;
this.txtClientFixedPhone.ReadOnly = true;
btn_CustomerEdit.Visible = true;
//buttonForm1.Visible = true;
}
}
}
void btn_CustomerEdit_Click(object sender, EventArgs e)
{
LYFZ.ComponentLibrary.ButtonEx btnEx = (LYFZ.ComponentLibrary.ButtonEx)sender;
if (btnEx.Text.Trim() == "编辑")
{
this.SetCustomerEditEnable(false);
btnEx.Text = " 保存";
}
else if (btnEx.Text.Trim() == "保存")
{
if (MessageBoxCustom.Show("如果修改客户信息,当前客户所关联的订单客户信息也会有变化\n是否继续?", "提示", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
{
LYFZ.Model.Model_ErpCustomer model = new Model.Model_ErpCustomer();
BLL.BLL_ErpCustomer customerBll = new BLL.BLL_ErpCustomer();
model = customerBll.GetModel("Cus_CustomerNumber", this.txtClientName.Tag.ToString().Trim());
model.Cus_Name = this.txtClientName.Text.ToString().Trim();
model.Cus_Telephone = this.txtClientTelephone.Text.ToString().Trim();
model.Cus_QQ = this.txtClientQQ.Text.ToString().Trim();
model.Cus_Address = this.txtClientAddress.Text.ToString().Trim();
model.Cus_WorkUnit = this.txtClientWorkUnit.Text.ToString().Trim();
model.Cus_Birthday = this.txtClientBirthday.StrValue.Trim();
if (this.chkClientBirthdayLunar.Checked == true)
{ model.Cus_BirthdayLunar = "1"; }
else
{ model.Cus_BirthdayLunar = "0"; }
model.Cus_DayForMarriage = this.txtClientDayForMarriage.StrValue.ToString();
if (this.chkClientDayForMarriageLunar.Checked == true)
{ model.Cus_DayForMarriageLunar = "1"; }
else
{ model.Cus_DayForMarriageLunar = "0"; }
if (customerBll.Update(model))
{
MessageBoxCustom.Show("修改成功!");
}
this.SetCustomerEditEnable(true);
btnEx.Text = " 编辑";
}
}
}
public void SetCustomerEditEnable(bool bRead)
{
this.txtClientName.ReadOnly = bRead;
this.txtClientTelephone.ReadOnly = bRead;
this.txtClientQQ.ReadOnly = bRead;
this.txtClientAddress.ReadOnly = bRead;
this.txtClientWorkUnit.ReadOnly = bRead;
this.txtClientBirthday.ReadOnly = bRead;
this.chkClientBirthdayLunar.Enabled = true;
this.txtClientDayForMarriage.ReadOnly = bRead;
this.chkClientDayForMarriageLunar.Enabled = true;
this.txtClientFixedPhone.ReadOnly = bRead;
}
public void BindShowAndHideDelete(bool b)
{
buttonForm1.Visible = b;
}
}
}