//加载文件数据 void LoadData(DataGridView dg1, string name) { if (opSingleLoad == null) { opSingleLoad = new OpenFileDialog(); opSingleLoad.InitialDirectory = ConstantMethod.GetAppPath(); opSingleLoad.Filter = "文件(csv文件)|*.csv"; } if (File.Exists(name)) { DataTable dt = csvop.OpenCSV(name); if (dt != null) { dg1.DataSource = dt; } } else if (opSingleLoad.ShowDialog() == DialogResult.OK) { DataTable dt = csvop.OpenCSV(opSingleLoad.FileName); if (dt != null) { dg1.DataSource = dt; } } }
public bool ReadFileDemo(string filename) { DataTable dt = new DataTable(); if (string.IsNullOrWhiteSpace(filename)) { dt = csvSaveDemo.OpenCSV(Constant.SaveFileDemo); } else { dt = csvSaveDemo.OpenCSV(filename); } rtbResult.Clear(); if (dt.Rows.Count == 1) { valueCol.Clear(); foreach (DataRow dr in dt.Rows) { for (int i = 0; i < dr.ItemArray.Length; i++) { int s = 0; if (int.TryParse(dr.ItemArray[i].ToString(), out s)) { valueCol.Add(s); } else { MessageBox.Show("指定列错误,错误列号:" + (i + 1).ToString()); return(false); } } } ConstantMethod.ShowInfo(rtbResult, "尺寸====>第" + valueCol[0] + "列"); ConstantMethod.ShowInfo(rtbResult, "设定数量====>第" + valueCol[1] + "列"); ConstantMethod.ShowInfo(rtbResult, "条码====>第" + valueCol[2] + "列"); for (int i = 3; i < valueCol.Count; i++) { ConstantMethod.ShowInfo(rtbResult, "参数" + (i - 2).ToString() + "====>第" + valueCol[i] + "列"); } } else { MessageBox.Show("加载模板数据错误!"); return(false); } return(true); }
/// <summary> /// 如果用户需要重新制定读取一些D区 M区的话可以先设置保存读取PLC 内容的文件 /// 读取后生成命令 /// </summary> public void SetPlcReadDMData(string filename) { if (CSVData != null) { CSVData.Dispose(); CSVData = null; } CSVData = new CsvStreamReader(); string s = Path.GetExtension(filename); if (File.Exists(filename) && (Path.GetExtension(filename).Equals(Constant.CSVFileEX))) { CSVData.FileName = filename; } //确认表格 //这个要隔离出来 方便以后可以单独调用 针对用户更改读取内容 if (CSVData.CheckCSVFile(Constant.PLCstrCol)) { dataForm = CSVData.OpenCSV(CSVData.FileName); if (dataForm != null && dataForm.Rows.Count > 0) { PackCmdReadDMDataOut(dataForm); //在建立连接的时候 切换表格数据源 } } //GC.Collect(); //GC.WaitForPendingFinalizers(); }
void dataLoad(string fileName) { CsvStreamReader op = new CsvStreamReader(); if (File.Exists(fileName)) { dtData = op.OpenCSV(fileName); dgv.DataSource = dtData; } }
public void GetPlcDataTableFromFile(List <string> strfile) { if (strfile != null && strfile.Count > 0) { foreach (string s in strfile) { if (ConstantMethod.FileIsUsed(s)) { MessageBox.Show(Constant.FileIsInUse); // ConstantMethod.AppExit(); } if (File.Exists(s) && (Path.GetExtension(s).Equals(Constant.CSVFileEX))) { CSVData.FileName = s; } //确认表格 //这个要隔离出来 方便以后可以单独调用 针对用户更改读取内容 if (CSVData.CheckCSVFile(Constant.PLCstrCol)) { DataTable dataForm0 = new DataTable(); dataForm0 = CSVData.OpenCSV(CSVData.FileName); if (dataForm0 != null && dataForm0.Rows.Count > 0) { DataFormLst.Add(dataForm0); } else { MessageBox.Show(Constant.ReadPlcInfoFail); //ConstantMethod.AppExit(); } } else { MessageBox.Show(Constant.ReadPlcInfoFail); //Application.Exit(); //System.Environment.Exit(0); } } } }
public Device(string filename, ServerInfo serverParam, int plcid) { CsvStreamReader csvFile = new CsvStreamReader(); DataTable dt = csvFile.OpenCSV(filename); plcId = plcid; plcLstD = new List <PlcSimple>(); plcLstM = new List <PlcSimple>(); if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { PlcSimple plcSimple = new PlcSimple(dt.Rows[i].ItemArray[1].ToString(), dt.Rows[i].ItemArray[0].ToString()); plcSimple.SetParam(getStrArr(dt.Rows[i].ItemArray)); if (plcSimple.Area.Equals(Constant.D_ID)) { plcLstD.Add(plcSimple); } else { plcLstM.Add(plcSimple); } plcSimple.SetPlcAddressOffset(plcId); } } else { MessageBox.Show(Constant.ErrorPlcFile + filename); ConstantMethod.AppExit(); } //获取serverip 和 port //serverParam = ConstantMethod.LoadServerParam(serverfile); dtTool = new DataTransform(serverParam); dtTool.SetDPlcSimple(plcLstD); dtTool.SetMPlcSimple(plcLstM); dtTool.StartGetData(); }
void InitOppeinFormula() { if (File.Exists(Constant.OpeeinFormulaFile)) { CsvStreamReader csvop = new CsvStreamReader(); DataTable dt = csvop.OpenCSV(Constant.OpeeinFormulaFile); // 门型 尺寸范围 宽度 高度 参数1 参数2 参数3 参数4 if (dt != null && dt.Rows.Count > 0) { OpfLst = new List <OpeeinFormula>(); foreach (DataRow dr in dt.Rows) { OpeeinFormula op = new OpeeinFormula(Constant.OpeeinFormulaFile); string doorLst = dr[0].ToString(); string[] con = dr[1].ToString().Split('-'); string wdithOffset = dr[2].ToString(); string heightOffset = dr[3].ToString(); op.DoorLst.AddRange(doorLst.Split('/')); //宽度 高度 if (con.Length == 2) { double l = 0; double h = 0; if (double.TryParse(con[0].ToString(), out l)) { if (l > 0) { op.ConditonRange.Add(l); } else { continue; } } if (double.TryParse(con[1].ToString(), out h)) { if (h > 0) { op.ConditonRange.Add(h); } else { continue; } } } else { continue; } double wo = 0; if (double.TryParse(wdithOffset, out wo)) { if (wo >= 0) { op.Width_offset = wo; } else { continue; } } else { continue; } double ho = 0; if (double.TryParse(heightOffset, out ho)) { if (ho >= 0) { op.Height_offset = ho; } else { continue; } } else { continue; } for (int i = 4; i < dr.ItemArray.Length; i++) { op.ParamLst.Add(dr[i].ToString()); } OpfLst.Add(op); } } } }
void Init(string name) { paramLst = new List <string>(); csvop = new CsvStreamReader(); materialData = csvop.OpenCSV(name); }