public static DataTable List2Dt( ref List<DB.Stru.老龄办.敬老优待证> lst ) { DB.Orm.老龄办.敬老优待证 orm = new DB.Orm.老龄办.敬老优待证(); DataTable dt = orm.GetBlank(); foreach ( DB.Stru.老龄办.敬老优待证 o in lst ) { DataRow dr = dt.Rows.Add(); o.Stru2Dr( ref dr ); } return dt; }
public void ExcelIn() { //选择导入证件类型 Comm.SelectType fmType = new SelectType(); if ( fmType.ShowDialog() != DialogResult.OK ) return; string strType = fmType.Type; // DB.DA.老龄办.敬老优待证 da = new DB.DA.老龄办.敬老优待证(); DataTable dtDB = da.GetBlank(); //定义Excel表匹配列 List<IntStr> lstIS = new List<IntStr>() { new IntStr(1,"姓名"), new IntStr(2,"性别"), new IntStr(3,"出生日期"), new IntStr(4,"单位或住址"), new IntStr(5,"身份证号码"), new IntStr(6,"电话"), new IntStr(7,"证件编号"), new IntStr(8,"照片回执号"), new IntStr(9,"街道"), }; //导入Excel FrontFlag.EXCEL2 Factory = new FrontFlag.EXCEL2(); Factory.strSqlConn = DB.DBParam.Sql.Connect; DataTable dtExcel = Factory.GetExcelData(); 福田民政.Fun.Comm.CopyDt( dtExcel, dtDB, lstIS ); List<DB.Stru.老龄办.敬老优待证> lstDB = new List<敬老优待证>(); lstDB = DB.Stru.老龄办.敬老优待证.Dt2List( ref dtDB ); if ( lstDB.Count == 0 ) { FF.Ctrl.MsgBox.Show( "导入失败!\n没有可以导入的数据!" ); return; } //补加数据 foreach ( DB.Stru.老龄办.敬老优待证 stru in lstDB ) { stru.CreateDate = FF.Str.Date.GetNow_yyyyMMddHHmmss(); stru.Crerator = GL.User.Name; stru.优待证类别 = strType; } //保存数据 DB.Orm.老龄办.敬老优待证 Orm = new DB.Orm.老龄办.敬老优待证(); Orm.Save( lstDB ); FF.Ctrl.MsgBox.Show( "导入成功。" ); return; }