问题描述
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingLY.TEC.Framework.Common.Client;usingWM.SPMS.Interface.SpareParts;usingWM.SPMS.DBCommon;usingLY.TEC.Framework.Common.Container;usingSystem.IO;usingC1.Win.C1FlexGrid;usingWM.SPMS.Common;usingWM.SPMS.Common.Enums;namespaceWM.SPMS.WinUI.SpareParts{publicpartialclassFrmContacts:BaseForm{privateDataTablemList;privateIContactermContact;privateAdminLogmAdminlog=AdminLog.Instance();publicFrmContacts(){InitializeComponent();//系统自动加的,用来初始化窗体、及其窗体中的控件,使之可视化的一个函数,一般在xxx.designer.cs中}privatevoidFrmContacts_Load(objectsender,EventArgse)//处理FrmConstacts的加载事件{cmbCustomer.Tag=ConstantStr.XML_Customer;cmbCustomer.DisplayMember="customer_name";cmbCustomer.ValueMember="customer_id";mContact=ContainerContext.Container.Resolve<IContacter>("IContacter");DataTabledtCustomer=mContact.QueryData(newstring[]{true.ToString()},ConstantStr.XML_Customer);DataRowrow=dtCustomer.NewRow();row["customer_id"]=ConstantStr.ID;row["customer_name"]=ConstantStr.ALL;dtCustomer.Rows.InsertAt(row,0);AptitudeBindingControl(newDataTable[]{dtCustomer});BindData();}privatevoidBindData(){Dictionary<string,string>param=newDictionary<string,string>();if(cmbCustomer.Text.Trim()!=ConstantStr.ALL){param["#customer_id#"]=cmbCustomer.SelectedValue.ToString();}if(tbName.Text.Trim()!=string.Empty){param["#contact_name#"]=tbName.Text.Trim().ToString();}try{mList=mContact.GetContacter(param);mList=DataFormat.SortDataTable("customer_namedesc",mList);mList.Columns.Add(DataFormat.CreateNewColumn("isSelected","System.Boolean"));DataFormat.CreateSeriNOINTD(refmList);mList.TableName="ContactsList";this.gdList.Tag="ContactsList-选择:isSelected:false:left:50,客户名称:customer_name:false:left:150,姓名:contact_name:false:left:60,"+"性别:sex:false:left:60,称呼:title:false:left:80,电话:telephone:false:left:100,传真:fax:false:left:100,手机:mobilephone:false:left:100,"+"电子邮件:email:false:center:120,备注:comment:false:left:150,:LAST_UPDATED_DATE:false:center:0,:customer_id:false:left:0,:enabled:false:left:0,:contact_id:false:left:0,:user_id:false:left:0";base.AptitudeBindingControl(newDataTable[]{mList});base.SetCheckBoxCellStyle(this.gdList,0);}catch(Exceptionexception){BaseForm.MessageBoxShow(this,"错误信息:"+exception.Message,"",MessageBoxButtons.OK,1);}}privatevoidtsAdd_Click(objectsender,EventArgse){IDictionary<string,string>dic=newDictionary<string,string>();dic[ConstantStr.ID]=this.Text;FrmContactEditcontact=newFrmContactEdit(true,dic);contact.ShowDialog();boolmOperationSuccess=contact.mOperationSuccess;contact.Close();if(mOperationSuccess){this.tsQuery_Click(null,null);}}privatevoidtsEdit_Click(objectsender,EventArgse){Dictionary<string,string>dic=newDictionary<string,string>();intnum=0;for(inti=1;i<this.gdList.Rows.Count;i++){if(this.gdList.Rows[i]["isSelected"].ToString().ToLower()=="true"){num++;if(num>1){break;}Rowrow=this.gdList.Rows[i];dic["contact_id"]=row["contact_id"].ToString();dic["contact_name"]=row["contact_name"].ToString();dic["customer_id"]=row["customer_id"].ToString();dic["sex"]=row["sex"].ToString();dic["enabled"]=row["enabled"].ToString();dic["title"]=row["title"].ToString();dic["telephone"]=row["telephone"].ToString();dic["fax"]=row["fax"].ToString();dic["mobilephone"]=row["mobilephone"].ToString();dic["email"]=row["email"].ToString();dic["comment"]=row["comment"].ToString();dic["user_id"]=row["user_id"].ToString();}}if(num!=1){BaseForm.MessageBoxShow(this,"请选择一行","温馨提示",MessageBoxButtons.OK,1);}else{dic[ConstantStr.ID]=this.Text;FrmContactEditedit=newFrmContactEdit(false,dic);edit.ShowDialog();boolmOperationSuccess=edit.mOperationSuccess;edit.Close();if(mOperationSuccess){this.tsQuery_Click(null,null);}}}privatevoidtsDelete_Click(objectsender,EventArgse){stringname=string.Empty;DataTabletable=mContact.DuplicateDataTable(newstring[]{"contact_id","enabled","last_updated_date"});intnum=0;for(inti=1;i<gdList.Rows.Count;i++){if(gdList.Rows[i]["isSelected"].ToString().ToLower()=="true"){DataRowrow=table.NewRow();row["contact_id"]=gdList.Rows[i]["contact_id"].ToString();row["last_updated_date"]=this.GetLastUpdateDate(row["contact_id"].ToString());if(name==string.Empty){name=String.Format("Id:{0}Name:{1}",gdList.Rows[i]["contact_id"].ToString(),gdList.Rows[i]["contact_name"].ToString());}else{name=name+","+String.Format("Id:{0}Name:{1}",gdList.Rows[i]["contact_id"].ToString(),gdList.Rows[i]["contact_name"].ToString());}num++;table.Rows.Add(row);row.AcceptChanges();row.SetModified();}}if(num==0){BaseForm.MessageBoxShow(this,"请选择要删除的数据","温馨提示",MessageBoxButtons.OK,1);}elseif(BaseForm.MessageBoxShow(this,"是否确定要删除所选的联系人记录?","温馨提示",MessageBoxButtons.OKCancel,1)!=DialogResult.Cancel){try{IDictionary<string,object>dic=newDictionary<string,object>();dic["table"]=table;mContact.DeleteData(dic);mAdminlog.SaveLog(LY.TEC.SysBasic.WinUILoader.Instance.UserInfo.UserID,LY.TEC.SysBasic.WinUILoader.Instance.ClientIpAddress,System.Environment.MachineName,this.Text,(int)OperateType.otDelete,"删除联系人记录"+table.Rows.Count+"条。["+name+"]");}catch(Exceptionexception){BaseForm.MessageBoxShow(this,"删除失败!n"+exception.Message,"温馨提示",MessageBoxButtons.OK,1);return;}BaseForm.MessageBoxShow(this,"删除成功!","温馨提示",MessageBoxButtons.OK,1);tsQuery_Click(sender,e);}}privatevoidtsExport_Click(objectsender,EventArgse){try{if(gdList.Rows.Count==1){BaseForm.MessageBoxShow(this,"没有可供导出的数据。","温馨提示",MessageBoxButtons.OK,1);return;}using(FlexGridExporterexporter=newFlexGridExporter()){gdList.Cols["isSelected"].Visible=(false);exporter.MappingFlexGridToNewSheet(this.gdList,"联系人列表",newFlexGridExporter.StartPosition(1,1),"联系人列表",null,true);gdList.Cols["isSelected"].Visible=(true);stringfilename=exporter.SaveToExcel();if((filename!="")&&(File.Exists(filename))){mAdminlog.SaveLog(LY.TEC.SysBasic.WinUILoader.Instance.UserInfo.UserID,LY.TEC.SysBasic.WinUILoader.Instance.ClientIpAddress,System.Environment.MachineName,this.Text,(int)OperateType.otExport,"导出联系人记录。");}}}catch(Exceptionexception){BaseForm.MessageBoxShow(this,exception.Message,"温馨提示",MessageBoxButtons.OK,1);}finally{gdList.Cols["isSelected"].Visible=(true);}}privatevoidtsExit_Click(objectsender,EventArgse){this.Close();}}}
解决方案
解决方案二:
一个可编辑的数据列表FrmContacts_Load初始化加载,BindData();绑定刷新数据,另外几个就是添加删除导出什么咯
解决方案三:
谁写的后台,你让谁给你讲讲不就行了。这就是基本的新增,修改,删除,导出功能。
解决方案四:
引用1楼wish907的回复:
一个可编辑的数据列表FrmContacts_Load初始化加载,BindData();绑定刷新数据,另外几个就是添加删除导出什么咯
我就是有点不知道comCustomer到binddata这里
解决方案五:
引用2楼SlowlyHeart的回复:
谁写的后台,你让谁给你讲讲不就行了。这就是基本的新增,修改,删除,导出功能。
经理不在,我有点地方不懂,就是从加载到绑定数据那块。
解决方案六:
都是最最简单的代码,要是你是我的同事,你问我这种问题,我马上就去找HR抱怨了。人人都有自己的工作,你应该自己去研究。何况这么简单,找本书都能看懂的东西。
解决方案七:
还有你这种胡乱就把自己公司的项目的代码成堆地贴在网上的做法,你的老板和同事也会引起反感。你真得问问自己,是干嘛的了。
解决方案八:
引用5楼caozhy的回复:
都是最最简单的代码,要是你是我的同事,你问我这种问题,我马上就去找HR抱怨了。人人都有自己的工作,你应该自己去研究。何况这么简单,找本书都能看懂的东西。
呵呵,你也是很屌。这就是拿来练手的东西,你非要说是项目我也没办法。我虽然写这个不多,才转过来,但是也知道公司项目不能随便发出来。你动不动去找hr抱怨,你也真把自己当回事了,我来论坛是来解决问题的。你能回答就回答,不能回答就可以走了。我给分,有人答就答,没人答就算了。就跟你去工作有人给钱就干,没人给就不干一个意思。
解决方案九:
这个应该是最基本的代码,只要学过面向对象编程不会看不懂吧。。。。。