⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 telcallingcontrol.cs

📁 汽车销售公司ERP进销存系统 汽车销售公司ERP进销存系统
💻 CS
📖 第 1 页 / 共 2 页
字号:
			// 
			// btnReset
			// 
			this.btnReset.Location = new System.Drawing.Point(768, 44);
			this.btnReset.Name = "btnReset";
			this.btnReset.TabIndex = 50;
			this.btnReset.Text = "清空";
			this.btnReset.Click += new System.EventHandler(this.btnReset_Click);
			// 
			// btnSave
			// 
			this.btnSave.Location = new System.Drawing.Point(768, 72);
			this.btnSave.Name = "btnSave";
			this.btnSave.TabIndex = 51;
			this.btnSave.Text = "保存";
			this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
			// 
			// TelCallingControl
			// 
			this.AutoScroll = true;
			this.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(237)), ((System.Byte)(244)), ((System.Byte)(250)));
			this.panelControl1.Controls.Add(this.cmbCSex);
			this.panelControl1.Controls.Add(this.tbCcomment);
			this.panelControl1.Controls.Add(this.tbCAddress);
			this.panelControl1.Controls.Add(this.tbCEmail);
			this.panelControl1.Controls.Add(this.tbCFax);
			this.panelControl1.Controls.Add(this.tbCcontact);
			this.panelControl1.Controls.Add(this.tbCName);
			this.panelControl1.Controls.Add(this.tbCallingTime);
			this.panelControl1.Controls.Add(this.tbTelCNo);
			this.panelControl1.Controls.Add(this.label2);
			this.panelControl1.Controls.Add(this.cmbCustmType);
			this.panelControl1.Controls.Add(this.label1);
			this.panelControl1.Controls.Add(this.label3);
			this.panelControl1.Controls.Add(this.label5);
			this.panelControl1.Controls.Add(this.label6);
			this.panelControl1.Controls.Add(this.label8);
			this.panelControl1.Controls.Add(this.label9);
			this.panelControl1.Controls.Add(this.label10);
			this.panelControl1.Controls.Add(this.label4);
			this.panelControl1.Controls.Add(this.label7);
			this.Controls.Add(this.panelControl1);
			this.Name = "TelCallingControl";
			this.Size = new System.Drawing.Size(872, 117);
			this.Load += new System.EventHandler(this.TelCallingControl_Load);
			((System.ComponentModel.ISupportInitialize)(this.tbTelCNo.Properties)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.tbCallingTime.Properties)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.panelControl1)).EndInit();
			this.panelControl1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.tbCName.Properties)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.tbCcontact.Properties)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.tbCFax.Properties)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.tbCEmail.Properties)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.tbCAddress.Properties)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.tbCcomment.Properties)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.cmbCSex.Properties)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		#region method

		//来电事件
		private void OnCustomerInfoChanged(object o,bool canSave){
			if(CustomerInfoChanged!=null && o is CustomerInfo){
				CustomerInfoChangedEventArgs ev = new CustomerInfoChangedEventArgs();
				ev.customerInfo = (CustomerInfo)o;
				ev.canSave = canSave;
				CustomerInfoChanged(this,ev);
			}
		}

		private void InitializeCmbSex(){
			if(this.cmbCSex.Properties.Items.Count>0){
				this.cmbCSex.SelectedIndex=0;
			}
		}
		//初始化客户类型下拉列表
		private void InitializeCmbCustmType(){
			IList list = this.customerBLL.getCustomerType();
			if(list.Count>0){
				this.cmbCustmType.DataSource = list;
				this.cmbCustmType.ValueMember ="ctype";
				this.cmbCustmType.DisplayMember = "ctname";

				//客户类型
				if(this.cmbCustmType.Items.Count>0){
					try{
						//普通用户
						this.cmbCustmType.SelectedValue = 3;
					}catch(Exception ex){
						MessageBox.Show(ex.Message);
						this.cmbCustmType.SelectedIndex = 0;
					}
				}
			}
		}

		private void DownLoadCustomerInfo(CustomerInfo  customerInfo){
		
			if(customerInfo!=null){
				this.customerId = customerInfo.id;
				//this.tbTelCNo.Text = customerInfo.ctelnumber;
				this.tbCName.Text = customerInfo.cname.ToString();
				//this.cmbCustmType.Text = customerInfo.ctname;
				this.cmbCustmType.SelectedValue = (int)customerInfo.ctype;
				this.tbCFax.Text = customerInfo.cfax.Trim().ToString();
				this.tbCEmail.Text = customerInfo.cemail;
				this.tbCcontact.Text = customerInfo.ccontact;
				this.cmbCSex.Text = customerInfo.csex;
				this.tbCAddress.Text = customerInfo.caddress;
				this.tbCcomment.Text = customerInfo.ccomment;
				//this.tbCallingTime.Text = DateTime.Now.ToString();
				this.isNewTel=false;
				this.m_customerInfo = customerInfo;
			}
		}

		private void UpLoadCustomerInfo(CustomerInfo customerInfo){
		
			customerInfo.id = this.customerId;
			customerInfo.ctelnumber = this.tbTelCNo.Text.Trim();
			customerInfo.cname=this.tbCName.Text ;
			customerInfo.ctype =this.CustomerCtype;
			customerInfo.ctname = this.cmbCustmType.Text;
			customerInfo.cfax= this.tbCFax.Text;
			customerInfo.cemail=this.tbCEmail.Text;
			customerInfo.ccontact = this.tbCcontact.Text;
			customerInfo.csex=this.cmbCSex.Text;
			customerInfo.caddress = this.tbCAddress.Text;
			customerInfo.ccomment = this.tbCcomment.Text;
		}
		private void DefaultFormValues(){
			this.tbTelCNo.Text = this.ctelnumber;
			//this.tbCallingTime.Text = DateTime.Now.ToString();
			this.customerId=-1;
			this.tbCName.Text = "";
			this.tbCFax.Text ="";
			this.tbCEmail.Text = "";
			this.tbCcontact.Text ="";
			this.cmbCSex.Text = "";
			this.tbCAddress.Text = "";
			this.tbCcomment.Text= "";
			this.isNewTel=true;

			//客户类型
			if(this.cmbCustmType.Items.Count>0){
				try{
					//普通用户
					this.cmbCustmType.SelectedValue = 3;
				}catch(Exception ex){
					MessageBox.Show(ex.Message);
					this.cmbCustmType.SelectedIndex = 0;
				}
			}
			m_customerInfo=null;
			TelCallingControl.CurrentCustomerInfo = null;
		}

		//来电调用的方法
		public void TelCalling(string telNo){
			IList customerList;
			CustomerInfo customerInfo=null;
			if(telNo!=null){
				ctelnumber = telNo;
				customerInfo = new CustomerInfo();
				customerInfo.ctelnumber=telNo;
				customerList = customerBLL.queryCustomer(customerInfo);
				this.tbTelCNo.Text = customerInfo.ctelnumber;
				this.tbCallingTime.Text = DateTime.Now.ToString();

				if(customerList.Count==1){
					//该号码对应一个用户,直接提数据
					customerInfo=(CustomerInfo)customerList[0];
					DownLoadCustomerInfo(customerInfo);
					//启动事件
					OnCustomerInfoChanged(customerInfo,true);
					TelCallingControl.CurrentCustomerInfo = customerInfo;
				}
				else if(customerList.Count>1){
					//this.DefaultFormValues();
					SelectCustomerForm selectCustomerForm = new SelectCustomerForm(customerList);
					DialogResult dlg = selectCustomerForm.ShowDialog();
					if(dlg==DialogResult.Yes){
						OnCustomerInfoChanged(selectCustomerForm.GetCustomerInfo,true);
						TelCallingControl.CurrentCustomerInfo = selectCustomerForm.GetCustomerInfo;
						DownLoadCustomerInfo(selectCustomerForm.GetCustomerInfo);
					}
				}
				else{
					this.DefaultFormValues();
//					MessageBox.Show("没有该用户!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
				}
			}
		}
		
		private bool Save(){

			bool canSave = ValidateCInfo();
			if(!canSave){
				return false;
			}
			try{
				CustomerInfo customerInfo = new CustomerInfo();
				UpLoadCustomerInfo(customerInfo);
				//修改
				if(this.customerId>0){
					this.customerBLL.updateCustomer(customerInfo);
				}
				else{
					this.customerId = this.customerBLL.addCustomer(customerInfo);
				}
				//启动事件
				OnCustomerInfoChanged(customerInfo,true);
				TelCallingControl.CurrentCustomerInfo = customerInfo;
				this.m_customerInfo = customerInfo;
				MessageBox.Show("保存成功","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
				return true;
			}catch(Exception ex){
				MessageBox.Show(ex.Message);
				MessageBox.Show("保存失败","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				return false;
			}
		}
		
		/// <summary>
		/// 检索用户信息
		/// </summary>
		private void RetrieveCtmInfo(){
			CustomerInfo customerInfo =new CustomerInfo();
			UpLoadCustomerInfo(customerInfo);
			customerInfo.ctelnumber="";
			IList list=this.customerBLL.queryCustomer(customerInfo);
			SelectCustomerForm selectCustomerForm = new SelectCustomerForm(list);
			DialogResult dlg = selectCustomerForm.ShowDialog();
			if(dlg==DialogResult.Yes){
				if(this.tbTelCNo.Text.Equals("") || !this.tbTelCNo.Text.Equals(selectCustomerForm.GetCustomerInfo.ctelnumber)){
					//this.tbCallingTime.Text="";
					OnCustomerInfoChanged(selectCustomerForm.GetCustomerInfo,false);
				}
				else{
					OnCustomerInfoChanged(selectCustomerForm.GetCustomerInfo,true);
				}
				TelCallingControl.CurrentCustomerInfo = selectCustomerForm.GetCustomerInfo;
				DownLoadCustomerInfo(selectCustomerForm.GetCustomerInfo);
			}
		}

		/// <summary>
		/// 检查用户信息是否有修改过
		/// </summary>
		/// <returns>修改过:true</returns>
		private bool CheckCstmModified(){
			if(this.m_customerInfo!=null){
				if(!m_customerInfo.ctelnumber.Equals(this.tbTelCNo.Text.Trim())){
					return true;
				}
				if(!m_customerInfo.cname.Equals(this.tbCName.Text.Trim())){
					return true;
				}
				if(!m_customerInfo.csex.Equals(this.cmbCSex.Text.Trim())){
					return true;
				}
				if(m_customerInfo.ctype!=this.CustomerCtype){
					return true;
				}
				if(!m_customerInfo.caddress.Equals(this.tbCAddress.Text.Trim())){
					return true;
				}
				if(!m_customerInfo.cemail.Equals(this.tbCEmail.Text.Trim())){
					return true;
				}
				if(!m_customerInfo.ccontact.Equals(this.tbCcontact.Text.Trim())){
					return true;
				}
				if(!m_customerInfo.cfax.Equals(this.tbCFax.Text.Trim())){
					return true;
				}
				if(!m_customerInfo.ccomment.Equals(this.tbCcomment.Text.Trim())){
					return true;
				}
				return false;
			}
			return true;
		}
		private bool ValidateCInfo(){
			if(this.tbCName.Text.Trim().Equals("")){
				MessageBox.Show("请输入用户姓名","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
				return false;
			}
			if(this.tbTelCNo.Text.Trim().Equals("")){
				MessageBox.Show("没有来电号码!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
				return false;
			}
			if(this.tbCName.Text.Trim().Length>30){
				MessageBox.Show("用户姓名的长度不能大于30个字符","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
				return false;
			}
			if(this.tbCcontact.Text.Trim().Length>50){
				MessageBox.Show("联系方式的长度不能大于50个字符","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
				return false;
			}
			if(this.tbCFax.Text.Trim().Length>20){
				MessageBox.Show("传真的长度不能大于20个字符","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
				return false;
			}
			if(this.tbCEmail.Text.Trim().Length>20){
				MessageBox.Show("电子邮件的长度不能大于20个字符","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
				return false;
			}
			if(this.tbCAddress.Text.Trim().Length>100){
				MessageBox.Show("地址的长度不能大于100个字符","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
				return false;
			}
			if(this.tbCcomment.Text.Trim().Length>500){
				MessageBox.Show("备注的长度不能大于500个字符","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
				return false;
			}
			if(CheckCstmInfoSaved()){
				MessageBox.Show("你没有修改不需要保存","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
				return false;
			}
			return true;
		}
		/// <summary>
		/// 校验用户信息是否保存过
		/// </summary>
		/// <returns>已保存:true</returns>
		private bool CheckCstmInfoSaved(){
			if(this.isNewTel){
				return false;
			}
			else if(CheckCstmModified()){
				return false;
			}
			return true;
		}
		#endregion

		#region events
		private void TelCallingControl_Load(object sender, System.EventArgs e) {
		
		}

		//保存
		private void btnSave_Click(object sender, System.EventArgs e) {
			Save();
		}

		//新建
		private void btnNew_Click(object sender, System.EventArgs e) {
			DefaultFormValues();

		}
		//检索
		private void btnRetrieve_Click(object sender, System.EventArgs e) {
			RetrieveCtmInfo();
		}

		private void btnReset_Click(object sender, System.EventArgs e) {
			DefaultFormValues();
			this.tbTelCNo.Text="";
			this.tbCallingTime.Text="";
		}
		#endregion
	}

	/// <summary>
	/// 自定义事件,当有来电时或查询时启动该事件
	/// author:yanqingxi
	/// </summary>
	public class CustomerInfoChangedEventArgs : EventArgs
	{
		public CustomerInfo customerInfo=null;
		public bool canSave=false;
	}
	public delegate void CustomerInfoChangedHandler(object sender,CustomerInfoChangedEventArgs ev);

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -