private static List <ActivityEquipment> LoadActivityEquipments(DataTable[] tables, string activityguid, string placeguid, string orgguid) { StringBuilder errormsg = new StringBuilder(); List <ActivityEquipment> equipments = new List <ActivityEquipment>(); //0:单位信息 //1:业务类型 for (int i = 0; i < tables.Length; i++) { DataTable table = tables[i]; string tablename = table.TableName; if (tablename == "单位信息" || tablename == "业务类型") { continue; } string tabname = ExcelImportHelper.TableNameConvert(table.TableName); string classId = ExcelImportHelper.GetEquipmentClassId(tabname); if (!string.IsNullOrEmpty(classId)) { List <ActivityEquipment> equs = LoadActivityEquFromTable(table, activityguid, placeguid, orgguid, classId); equipments.AddRange(equs); } } return(equipments); }
static void Main(string[] args) { //1.获取模块的完整路径。 //string path1 = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; //2.获取和设置当前目录(该进程从中启动的目录)的完全限定目录 string path2 = System.Environment.CurrentDirectory; ////3.获取应用程序的当前工作目录 //string path3 = System.IO.Directory.GetCurrentDirectory(); ////4.获取程序的基目录 //string path4 = System.AppDomain.CurrentDomain.BaseDirectory; ////5.获取和设置包括该应用程序的目录的名称 //string path5 = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase; Directory.SetCurrentDirectory(Directory.GetParent(path2).FullName); string path = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(Directory.GetParent(path).FullName); path = Directory.GetCurrentDirectory(); string newPath = Path.Combine(path, "execl测试.xlsx"); //Array array= Enum.GetValues(typeof(ESex)); //Console.WriteLine(System.Enum.GetName(typeof(ESex), 1)); //Console.WriteLine(System.Enum.GetName(typeof(ESex), 2)); //Console.WriteLine( Enum.Format(typeof(ESex), Enum.Parse(typeof(ESex), "女"), "D")); //Console.WriteLine(Enum.Format(typeof(ESex), Enum.Parse(typeof(ESex), "女"), "D")); ExcelImportHelper excelImportHelper = new ExcelImportHelper(); System.Diagnostics.Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); // 开始监视代码运行时间 List <SysUser> sysUserList = excelImportHelper.DataTableToList <SysUser>(@"C:\Users\chenke\Desktop\execl测试.xlsx"); stopwatch.Stop(); // 停止监视 TimeSpan timespan = stopwatch.Elapsed; // 获取当前实例测量得出的总时间 System.Console.WriteLine($"第一次转换 {timespan.TotalSeconds}"); System.Console.WriteLine($"第一次读取execl {sysUserList.Count}"); string json = JsonConvert.SerializeObject(sysUserList); Console.WriteLine(json); stopwatch.Reset(); stopwatch.Start(); // 开始监视代码运行时间 sysUserList = excelImportHelper.DataTableToList <SysUser>(@"C:\Users\chenke\Desktop\execl测试.xlsx"); stopwatch.Stop(); // 停止监视 timespan = stopwatch.Elapsed; // 获取当前实例测量得出的总时间 System.Console.WriteLine($"第二次转换 {timespan.TotalSeconds}"); System.Console.WriteLine($"第二次读取execl {sysUserList.Count}"); json = JsonConvert.SerializeObject(sysUserList); Console.WriteLine(json); System.Console.Read(); }
void ImportMapModify_Loaded(object sender, RoutedEventArgs e) { if (DataScript.FileType == "mdb") { AccessImportHelper helper = new AccessImportHelper(sourceFile); columnConnection.Source = helper.getDataTable(); } else if (DataScript.FileType == "db") { columnConnection.Source = SQLiteImportHelper.GetDataTable(sourceFile); } else if (DataScript.FileType == "xls/xlsx") { columnConnection.Source = ExcelImportHelper.GetDataTable(sourceFile); } else { columnConnection.Source = TextImportHelper.GetDataTable(sourceFile, this.DataScriptRule.getColSeperatorChar()); } columnConnection.Target = TableDAL.getTableStructure(this.DataScriptRule.DesTable); columnConnection.BusinessPK = DataScriptRule.DesBusinessPk; columnConnection.FID = FID; columnConnection.ShowComplete += columnConnection_ShowComplete; }
private static void ImportActivityEquipment(DataTable[] tables, ActivityOrganization activityorg) { StringBuilder error = new StringBuilder(); bool validresult = ExcelImportHelper.ValidateEquipmentTables(tables, out error); //验证设备信息 if (validresult) { List <ActivityEquipment> lstequ = LoadActivityEquipments(tables, SystemLoginService.CurrentActivity.Guid, SystemLoginService.CurrentActivityPlace.Guid, activityorg.Guid); if (lstequ == null || lstequ.Count == 0) { MessageBox.Show("请输入要导入的设备", "提示", MessageBoxButton.OK); return; } else { ImportEquipmentDelegate(activityorg, lstequ); } } else { ErrorDialog errordialog = new ErrorDialog(error.ToString()); errordialog.ShowDialog(); return; } }
static void Main(string[] args) { //Array array= Enum.GetValues(typeof(ESex)); //Console.WriteLine(System.Enum.GetName(typeof(ESex), 1)); //Console.WriteLine(System.Enum.GetName(typeof(ESex), 2)); //Console.WriteLine( Enum.Format(typeof(ESex), Enum.Parse(typeof(ESex), "女"), "D")); //Console.WriteLine(Enum.Format(typeof(ESex), Enum.Parse(typeof(ESex), "女"), "D")); ExcelImportHelper excelImportHelper = new ExcelImportHelper(); System.Diagnostics.Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); // 开始监视代码运行时间 List<SysUser> sysUserList = excelImportHelper.DataTableToList<SysUser>(@"C:\Users\chenke\Desktop\execl测试.xlsx"); stopwatch.Stop(); // 停止监视 TimeSpan timespan = stopwatch.Elapsed; // 获取当前实例测量得出的总时间 System.Console.WriteLine($"第一次转换 {timespan.TotalSeconds}"); System.Console.WriteLine($"第一次读取execl {sysUserList.Count}"); string json = JsonConvert.SerializeObject(sysUserList); Console.WriteLine(json); stopwatch.Reset(); stopwatch.Start(); // 开始监视代码运行时间 sysUserList = excelImportHelper.DataTableToList<SysUser>(@"C:\Users\chenke\Desktop\execl测试.xlsx"); stopwatch.Stop(); // 停止监视 timespan = stopwatch.Elapsed; // 获取当前实例测量得出的总时间 System.Console.WriteLine($"第二次转换 {timespan.TotalSeconds}"); System.Console.WriteLine($"第二次读取execl {sysUserList.Count}"); json = JsonConvert.SerializeObject(sysUserList); Console.WriteLine(json); System.Console.Read(); }
void DataScriptMapModify_Loaded(object sender, RoutedEventArgs e) { // columnConnection.Source = TextImportHelper.GetDataTable(@"G:\workspace\动控实现数据管理\src\TestData\data.txt", ','); //columnConnection.Target = TableDAL.getTableStructure("MDS_IMP_DATA_TEST"); if (DataScript.FileType == "mdb") { AccessImportHelper helper = new AccessImportHelper(this.DataScriptRule.DesFile); columnConnection.Source = helper.getDataTable(); } else if (DataScript.FileType == "db") { columnConnection.Source = SQLiteImportHelper.GetDataTable(this.DataScriptRule.DesFile); } else if (DataScript.FileType == "xls/xlsx") { columnConnection.Source = ExcelImportHelper.GetDataTable(this.DataScriptRule.DesFile); } else { columnConnection.Source = TextImportHelper.GetDataTable(this.DataScriptRule.DesFile, this.DataScriptRule.getColSeperatorChar()); } columnConnection.FID = FID; columnConnection.BusinessPK = this.DataScriptRule.DesBusinessPk; columnConnection.Target = TableDAL.getTableStructure(this.DataScriptRule.DesTable); }
/// <summary> /// 导入设备 /// </summary> /// <param name="tables"></param> /// <param name="orginfo"></param> private void ImportEquipment(DataTable[] tables, Organization orginfo) { StringBuilder error = new StringBuilder(); bool validresult = ExcelImportHelper.ValidateEquipmentTables(tables, out error); //验证设备信息 if (validresult) { List <Equipment> lstequ = this.LoadEquipments(tables, orginfo.Guid); if (lstequ == null || lstequ.Count == 0) { MessageBox.Show("请输入要导入的设备", "提示", MessageBoxButton.OK); return; } else { ImportEquipmentEvent(orginfo, lstequ); } } else { ErrorDialog errordialog = new ErrorDialog(error.ToString()); errordialog.ShowDialog(); return; } }
static void Main(string[] args) { ExcelImportHelper excelImportHelper = new ExcelImportHelper(); List <SysUser> sysUserList = excelImportHelper.DataTableToList <SysUser>(@"C:\Users\chenke\Desktop\execl测试.xlsx"); System.Console.WriteLine($"读取execl {sysUserList.Count}"); System.Console.Read(); }
/// <summary> /// XLS导入 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnImportEqu_Click(object sender, RoutedEventArgs e) { SecurityClass[] securityclasses = CO_IA.Client.Utility.GetSecurityClasses(); if (securityclasses == null || securityclasses.Length == 0) { MessageBox.Show("请先在基础数据设置中增加保障类别"); } else { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Excel文件(*.xls)|*.xls"; //dialog.Filter = "(*.xlsx)|*.xlsx|(*.xls)|*.xls"; //dialog.DefaultExt = "xlsx"; dialog.CheckFileExists = true; if (dialog.ShowDialog() == true) { DataTable[] tables = ExcelImportHelper.LoadDataFromExcel(dialog.FileName); if (tables != null && tables.Length > 0) { //单位信息 Organization orginfo = null; DataTable orgtable = tables.FirstOrDefault(r => r.TableName == "单位信息"); if (orgtable != null && ExcelImportHelper.ValidateORG(orgtable)) { orginfo = this.LoadORGFromTable(orgtable); } if (orginfo != null) { #region 验证单位名称 OrgQueryCondition condition = new OrgQueryCondition(); condition.Name = orginfo.Name; Organization[] orgs = this.GetORGSource(condition); Organization sameorg = orgs.FirstOrDefault(r => r.Name == orginfo.Name); #endregion if (sameorg != null) { MessageBoxResult result = MessageBox.Show(string.Format("'{0}'已经存在,是否将Excel中的设备导入到'{0}'中?", orginfo.Name), "提示", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { ImportEquipment(tables, sameorg); } else { MessageBox.Show("请修改单位名称"); } } else { ImportEquipment(tables, orginfo); } } } } } }
private void xls2db() { DataTable dataTable = ExcelImportHelper.GetDataTable(sourceFile); if (!insertDataTable(dataTable, structList, this.tableName)) { return; } }
private bool xls2db() { DataTable dt = ExcelImportHelper.GetDataTable(this.sourceFile); this.calColumnMap(dt); bool result = insertDataTable(dt, structList, this.tableName); return(result); }
static void Main(string[] args) { ExcelImportHelper excelImportHelper = new ExcelImportHelper(); List <SysUser> sysUserList = excelImportHelper.DataTableToList <SysUser>(@"C:\Users\chenke\Desktop\execl测试.xlsx"); System.Console.WriteLine($"读取execl {sysUserList.Count}"); string json = JsonConvert.SerializeObject(account); Console.WriteLine(json); System.Console.Read(); }
public static void Import(Action <ActivityOrganization, List <ActivityEquipment> > p_importEquips) { ImportEquipmentDelegate = p_importEquips; OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Excel文件(*.xls)|*.xls"; dialog.DefaultExt = "xls"; dialog.CheckFileExists = true; if (dialog.ShowDialog() == true) { DataTable[] tables = ExcelImportHelper.LoadDataFromExcel(dialog.FileName); if (tables != null && tables.Length > 0) { //单位信息 ActivityOrganization activityorg = null; DataTable orgtable = tables.FirstOrDefault(r => r.TableName == "单位信息"); if (orgtable != null && ExcelImportHelper.ValidateORG(orgtable)) { activityorg = LoadActivityORGFromTable(orgtable, SystemLoginService.CurrentActivity.Guid); } if (activityorg != null) { #region 验证单位名称 OrgQueryCondition condition = new OrgQueryCondition(); condition.ActivityGuid = SystemLoginService.CurrentActivity.Guid; condition.Name = activityorg.Name; ActivityOrganization[] orgs = DataOperator.GetActivityOrgSources(condition); ActivityOrganization sameorg = orgs.FirstOrDefault(r => r.Name == activityorg.Name); #endregion if (sameorg != null) { MessageBoxResult result = MessageBox.Show(string.Format("单位'{0}'已经存在,是否将Excel中的设备导入到现有的单位中?", activityorg.Name), "提示", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { ImportActivityEquipment(tables, sameorg); } else { MessageBox.Show("请修改单位名称"); } } else { ImportActivityEquipment(tables, activityorg); } } } } }
/// <summary> ///Cron表达式校验 /// </summary> /// <param name="e">校验参数</param> /// <returns>错误信息</returns> private static string CronVerify(ImportVerifyParam e, object extra) { string result = ""; result = ExcelImportHelper.GetCellMsg(e.CellValue, e.ColName, 200, true, true); if (string.IsNullOrEmpty(result)) { if (!QuartzHelper.ValidExpression(e.CellValue.ToString())) { result += "Cron表达式格式不正确"; } } return(result); }
static void Main(string[] args) { Console.WriteLine(Enum.ToObject(typeof(ESex), Enum.Parse(typeof(ESex), "男"))); Console.WriteLine(Enum.ToObject(typeof(ESex), Enum.Parse(typeof(ESex), "女"))); ExcelImportHelper excelImportHelper = new ExcelImportHelper(); List <SysUser> sysUserList = excelImportHelper.DataTableToList <SysUser>(@"C:\Users\chenke\Desktop\execl测试.xlsx"); System.Console.WriteLine($"读取execl {sysUserList.Count}"); string json = JsonConvert.SerializeObject(sysUserList); Console.WriteLine(json); System.Console.Read(); }
static void Main(string[] args) { foreach (object o in Enum.GetValues(typeof(ESex))) { Console.WriteLine("{0}:{1}", o, Enum.Format(typeof(ESex), o, "D")); } ExcelImportHelper excelImportHelper = new ExcelImportHelper(); List <SysUser> sysUserList = excelImportHelper.DataTableToList <SysUser>(@"C:\Users\chenke\Desktop\execl测试.xlsx"); System.Console.WriteLine($"读取execl {sysUserList.Count}"); string json = JsonConvert.SerializeObject(sysUserList); Console.WriteLine(json); System.Console.Read(); }
/// <summary> /// 批量保存数据 /// </summary> /// <param name="dt">数据</param> /// <param name="extraInfo">额外参数</param> /// <param name="userInfo">用户信息</param> public override object SaveImportData(DataTable dt, Dictionary <string, object> extraInfo, UserInfo userInfo) { string columnName = string.Empty; object objExtra = null; Dictionary <string, string> dict = null; object objCellValue = null; List <string> listAssetsId = new List <string>(); string strAssetsId = string.Empty; foreach (DataRow dr in dt.Rows) { foreach (DataColumn dc in dt.Columns) { columnName = dc.ColumnName; if (extraInfo.TryGetValue(columnName, out objExtra)) { dict = objExtra as Dictionary <string, string>; if (dict != null) { objCellValue = dr[columnName]; if (!ExcelImportHelper.ObjectIsNullOrEmpty(objCellValue)) { dr[columnName] = dict[objCellValue.ToString()]; } } } } } try { //保存任务数据 List <TaskUtil> list = dt.ToList <TaskUtil>(); foreach (var item in list) { TaskHelper.SaveTask(item); } return(dt); } catch (Exception ex) { throw ex; } }
/// <summary> ///下拉选项校验 /// </summary> /// <param name="e">校验参数</param> /// <returns>错误信息</returns> private static string SelectVerify(ImportVerifyParam e, object extra) { string result = ""; result = ExcelImportHelper.GetCellMsg(e.CellValue, e.ColName, 0, true); if (string.IsNullOrEmpty(result)) { var dict = extra as Dictionary <string, string>; if (dict != null) { if (!dict.ContainsKey(e.CellValue.ToString())) { result += e.ColName + "下拉选项" + e.CellValue + "不存在"; } } } return(result); }
static void Main(string[] args) { //Array array= Enum.GetValues(typeof(ESex)); //Console.WriteLine(System.Enum.GetName(typeof(ESex), 1)); //Console.WriteLine(System.Enum.GetName(typeof(ESex), 2)); //Console.WriteLine( Enum.Format(typeof(ESex), Enum.Parse(typeof(ESex), "女"), "D")); //Console.WriteLine(Enum.Format(typeof(ESex), Enum.Parse(typeof(ESex), "女"), "D")); ExcelImportHelper excelImportHelper = new ExcelImportHelper(); System.Diagnostics.Stopwatch stopwatch = new Stopwatch(); List <SysUser> sysUserList = excelImportHelper.DataTableToList <SysUser>(@"C:\Users\chenke\Desktop\execl测试.xlsx"); System.Console.WriteLine($"读取execl {sysUserList.Count}"); string json = JsonConvert.SerializeObject(sysUserList); Console.WriteLine(json); System.Console.Read(); }
private List <string> getHeaders() { List <string> result = new List <string>(); DataTable dt = new DataTable(); string fileType = System.IO.Path.GetExtension(this.sourceFile); if (fileType == ".xls" || fileType == ".xlsx") { dt = ExcelImportHelper.GetDataTable(this.sourceFile); } else { dt = TextImportHelper.GetDataTable(this.sourceFile, this.dataScriptRule.getColSeperatorChar()); } foreach (DataColumn column in dt.Columns) { result.Add(column.ColumnName); } return(result); }
private DataTable GetDataTable(string fileName) { DataTable dt; if (FileType.SelectedValue.ToString() == "mdb") { AccessImportHelper helper = new AccessImportHelper(fileName); dt = helper.getDataTable(); } else if (FileType.SelectedValue.ToString() == "xls/xlsx") { dt = ExcelImportHelper.GetDataTable(fileName); } else if (FileType.SelectedValue.ToString() == "db") { dt = SQLiteImportHelper.GetDataTable(fileName); } else { dt = TextImportHelper.GetDataTable(fileName, DataScriptRule.getColSeperatorChar(GetColSperator())); } return(dt); }
/// <summary> /// 导入 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnXLSImport_Click(object sender, RoutedEventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Excel 文件|*.xls;*.xlsx"; dialog.DefaultExt = "xls"; dialog.CheckFileExists = true; if (dialog.ShowDialog() == true) { DataTable[] tables = ExcelImportHelper.LoadDataFromExcel(dialog.FileName); if (tables != null && tables.Length > 0) { string imgPath = dialog.FileName.Substring(0, dialog.FileName.LastIndexOf('\\') + 1) + "车辆照片"; if (Directory.Exists(imgPath)) { List <DataRow> rows = VehicleImportHelper.GetEnableDataRow(tables); if (rows != null && rows.Count > 0) { VehicleImportHelper.ImageFilePath = imgPath; List <VehicleInfo> vehicles = null; bool result = false; vehicles = VehicleImportHelper.GetVehicleFromTable(rows, out result); //设备获取成功 if (result) { if (vehicles != null && vehicles.Count > 0) { List <VehicleInfo> samenolst = new List <VehicleInfo>(); //验证在数据库中是否存在相同的车辆编号 if (VehicleImportHelper.VerifyVehicleNotInDB(vehicles, out samenolst)) { try { BeOperationInvoker.Invoke <I_CO_IA_PlanDatabase> (channel => { channel.ImportVehicles(vehicles); }); GetVehicleInfos(); } catch (Exception ex) { MessageBox.Show(ex.GetExceptionMessage(), "导入失败"); } } else { StringBuilder errstr = new StringBuilder(); errstr.AppendLine("数据库存在相同的车牌号码:"); foreach (VehicleInfo item in samenolst) { errstr.AppendLine(item.VehicleNo); } errstr.AppendLine("是否进行替换?"); errstr.AppendLine("说明:如果车辆在监测实施中,存在设备。则不替换'监测车'属性"); MessageBoxResult msgresult = MessageBox.Show(errstr.ToString(), "提示", MessageBoxButton.YesNo); if (msgresult == MessageBoxResult.Yes) { BeOperationInvoker.Invoke <I_CO_IA_PlanDatabase> (channel => { channel.ImportVehicles(vehicles); }); GetVehicleInfos(); } else { return; } } } } } else { MessageBox.Show("车辆信息为空,请填写车辆信息", "提示", MessageBoxButton.OK); } } else { MessageBox.Show("车辆照片文件夹不存在,无法导入照片"); } } else { MessageBox.Show("车辆信息为空,请填写车辆信息", "提示", MessageBoxButton.OK); } } }
private void btnDownLoad_Click(object sender, RoutedEventArgs e) { ExcelImportHelper.TemplateDownLoad("设备导入模板.xls", "Template\\Equipment\\"); }
/// <summary> /// 创建ActivityEquipment对象 /// </summary> /// <param name="dr"></param> /// <param name="activityguid"></param> /// <param name="placeguid"></param> /// <param name="orgguid"></param> /// <param name="classId"></param> /// <returns></returns> private ActivityEquipment CreateActivityEquipment(DataRow dr, string activityguid, string placeguid, string orgguid) { ActivityEquipment equ = new ActivityEquipment(); equ.Key = System.Guid.NewGuid().ToString(); equ.OrgInfo.Guid = orgguid; equ.ActivityGuid = activityguid; equ.PlaceGuid = placeguid; equ.Name = dr["设备名称"].ToString(); equ.EquipmentClassID = ExcelImportHelper.GetEquipmentClassId(dr["业务类型"].ToString()); equ.EQUCount = Int32.Parse(dr["数量"].ToString()); //设备数量 equ.EquModel = dr["设备型号"].ToString(); //设备型号 equ.SeriesNumber = dr["设备编号"].ToString(); //设备编号 equ.IsMobile = dr["移动设备"].ToString() == "是" ? true : false; //移动设备 if (!equ.IsMobile) { equ.Longitude = double.Parse(dr["经度"].ToString()); equ.Latitude = double.Parse(dr["纬度"].ToString()); equ.Address = dr["地点"].ToString(); } equ.IsStation = dr["已建站"].ToString() == "是" ? true : false; if (equ.IsStation) { equ.StationName = dr["已建站名称"].ToString(); equ.StationTDI = dr["台站编号"].ToString(); } else { equ.StationName = string.Empty; equ.StationTDI = string.Empty; } equ.SendFreq = double.Parse(dr["发射频率(MHz)"].ToString()); //发射频率 if (string.IsNullOrWhiteSpace(dr["接收频率(MHz)"].ToString())) { equ.ReceiveFreq = null;//接收频率 } else { equ.ReceiveFreq = double.Parse(dr["接收频率(MHz)"].ToString());//接收频率 } if (string.IsNullOrEmpty(dr["备用频率(MHz)"].ToString())) { equ.SpareFreq = null;//备用频率 } else { equ.SpareFreq = double.Parse(dr["备用频率(MHz)"].ToString());//接收频率 } equ.IsTunable = dr["频率可调"].ToString() == "是" ? true : false;//频率可调 if (equ.IsTunable) { if (string.IsNullOrEmpty(dr["频率范围起始(MHz)"].ToString())) { equ.FreqRange.Little = null;//发射频率范围起始 } else { equ.FreqRange.Little = double.Parse(dr["频率范围起始(MHz)"].ToString());//发射频率范围起始 } if (string.IsNullOrEmpty(dr["频率范围终止(MHz)"].ToString())) { equ.FreqRange.Great = null;//发射频率范围终止 } else { equ.FreqRange.Great = double.Parse(dr["频率范围终止(MHz)"].ToString());//发射频率范围终止 } } else { equ.FreqRange = new Range <double?>(); } equ.Band_kHz = double.Parse(dr["波道带宽(kHz)"].ToString()); //必要带宽 equ.Power_W = double.Parse(dr["发射功率(W)"].ToString()); //发射功率 EMCS.Types.EMCModulationEnum modulat; if (Enum.TryParse(dr["调制方式"].ToString(), out modulat)) { equ.Modulation = modulat; } equ.Remark = dr["备注"].ToString(); return(equ); }
static void Main(string[] args) { ExcelImportHelper excelImportHelper = new ExcelImportHelper(); List <SysUser> sysUserList = }
private void openTemplateFile_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { dataScript = ScriptName.SelectedItem as DataScript; dataRule = DataScriptRuleDAL.getInfo(dataScript.FID); System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog(); if (FileType.SelectedValue.ToString() == "xls/xlsx") { dialog.Filter = "(Excel 文件)|*.xls;*.xlsx"; } else if (FileType.SelectedValue.ToString() == "dat") { dialog.Filter = "(dat 文件)|*.dat"; } else if (FileType.SelectedValue.ToString() == "db") { dialog.Filter = "(sqlite 文件)|*.db"; } else if (FileType.SelectedValue.ToString() == "mdb") { dialog.Filter = "(mdb 文件)|*.mdb"; } else if (FileType.SelectedValue.ToString() == "fws10") { dialog.Filter = "(fws10 文件)|*.fws10"; } else { dialog.Filter = "(文本文件)|*.txt"; } System.Windows.Forms.DialogResult result = dialog.ShowDialog(); DataTable dt = new DataTable(); if (result == System.Windows.Forms.DialogResult.OK) { txtTemplageFile.Text = dialog.FileName; if (FileType.SelectedValue.ToString() == "mdb") { AccessImportHelper helper = new AccessImportHelper(dialog.FileName); dt = helper.getDataTable(); } else if (FileType.SelectedValue.ToString() == "xls/xlsx") { dt = ExcelImportHelper.GetDataTable(dialog.FileName); } else if (FileType.SelectedValue.ToString() == "db") { dt = SQLiteImportHelper.GetDataTable(dialog.FileName); } else { dt = TextImportHelper.GetDataTable(dialog.FileName, dataRule.getColSeperatorChar()); } dataGrid.ItemsSource = dt.AsDataView(); importGrid.ItemsSource = dt; checkStruct(dt, dataScript); } }
static void Main(string[] args) { ExcelImportHelper excelImportHelper = new ExcelImportHelper(); List <SysUser> sysUserList = excelImportHelper.DataTableToList <SysUser>(@"C:\Users\chenke\Desktop\execl测试.xlsx"); }
private void nextButton_Click(object sender, RoutedEventArgs e) { string erromsg = ""; if (string.IsNullOrEmpty(txtTemplageFile.Text.Trim())) { erromsg += "请选择样例文件!\r\n"; } if (Des_Table.SelectedIndex == -1) { erromsg += "请选择目标数据表!\r\n"; } if (Des_Table.SelectedIndex == 0 && string.IsNullOrEmpty(txtTableName.Text)) { erromsg += "请输入数据表名称!\r\n"; } if (Des_Table.SelectedIndex == 0 && string.IsNullOrEmpty(txtTableCode.Text)) { erromsg += "请输入数据表代码!\r\n"; } if (cbSave.IsChecked.Value) { if (string.IsNullOrEmpty(MidsScriptCode.Text.Trim())) { erromsg += "请输入解析器编码!\r\n"; } else { if (!checkCode()) { erromsg += "解析器编码重复!\r\n"; } } if (string.IsNullOrEmpty(MidsScriptName.Text.Trim())) { erromsg += "请输入解析器名称!\r\n"; } } if (!string.IsNullOrEmpty(erromsg)) { MessageBox.Show(erromsg); return; } builderScript(); if (cbSave.IsChecked.Value) { insert(); } DataTable dt = new DataTable(); if (FileType.SelectedValue.ToString() == "xls/xlsx") { dt = ExcelImportHelper.GetDataTable(txtTemplageFile.Text.Trim()); } else { dt = TextImportHelper.GetDataTable(txtTemplageFile.Text.Trim(), DataScriptRule.getColSeperatorChar(GetColSperator())); } TableDAL.CreateTable(txtTableCode.Text.ToUpper(), dt); int count = ObjtableInfoDAL.Count(txtTableCode.Text.ToUpper()); if (count == 0) { ObjtableInfo oinfo = new ObjtableInfo(); oinfo.FID = Guid.NewGuid().ToString().Replace("-", ""); oinfo.CreatedBy = MainWindow.UserID; oinfo.LastUpdatedBy = MainWindow.UserID; oinfo.ObjectTableCode = txtTableCode.Text.ToUpper(); oinfo.ObjectTableName = txtTableName.Text; oinfo.Status = "02"; oinfo.Version = 1; oinfo.LastUpdateIp = "127.0.0.1"; oinfo.LastUpdateDate = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); oinfo.CreationDate = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); ObjtableInfoDAL.Insert(oinfo); } ImportMapModify mapModify = new ImportMapModify(); mapModify.FID = FID; mapModify.DataScriptRule = dRule; mapModify.DataScript = dScript; mapModify.sourceFile = txtTemplageFile.Text.Trim(); mapModify.isAutoDrawLine = true; ImportStack.Push(this); MainWindow window = App.Current.MainWindow as MainWindow; window.StartPage(mapModify); }
/// <summary> /// 下载 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnTemplateDownLoad_Click(object sender, RoutedEventArgs e) { ExcelImportHelper.TemplateDownLoad("车辆导入模板文件夹.zip", "Template\\Vehicle\\"); }