public bool OpenFile(string path) { m_dt = CSVFileHelper.OpenCSV(path); if (m_dt == null) { return(false); } FieldInfo[] optionFields = typeof(AssetBundleInfo).GetFields(); foreach (DataRow dr in m_dt.Rows) { AssetBundleInfo data_temp = new AssetBundleInfo(); foreach (var field in optionFields) { if (!field.IsPublic || field.IsStatic) { continue; } field.SetValue(data_temp, dr[field.Name]); } AddDicAseetsData(data_temp, dr); } return(true); }
private void ReadDataFromStore() { dataTableToShow = CSVFileHelper.OpenCSV(dataFile); //if (this.batteryList.Count > 0) //{ // List<string> addrList = new List<string>(); // foreach(var b in this.batteryList) // { // addrList.Add("'" + b.address + "'"); // } // while (dataTable.Select("地址 IN (" + string.Join(",", addrList) + ")").Count() > 0) // { // var time = ""; // foreach (var b in this.batteryList) // { // var dr = dataTable.Select("地址 = " + b.address); // if (dr != null && dr.Count() > 0) // { // time = dr[0]["采集时间"].ToString(); // break; // } // } // if(!string.IsNullOrEmpty(time)) // { // DataRow newRow = dataTableToShow.NewRow(); // newRow["采集时间"] = time; // // 前后一分钟的数据为同一批次数据 // var dateStart = DateTime.Parse(time).AddMinutes(-1); // var dateEnd = DateTime.Parse(time).AddMinutes(1); // int index = 0; // foreach (var b in this.batteryList) // { // var drs = dataTable.Select("地址 = " + b.address + " AND 采集时间 >= #" + dateStart + "# AND 采集时间 <= #" + dateEnd + "#"); // if (drs != null && drs.Count() > 0) // { // var dr = drs[0]; // for (var i = 2; i < dr.ItemArray.Length; i++) // { // newRow[++index] = dr[i]; // } // dataTable.Rows.Remove(dr); // } // else // { // for (var i = 0; i < 24; i++) // { // newRow[++index] = null; // } // } // } // dataTableToShow.Rows.Add(newRow); // } // } //} }
private void button1_Click(object sender, EventArgs e) { //首先选择一个文件,然后就读取啦 if (openFileDialog1.ShowDialog() == DialogResult.OK) { string strCsvFile = openFileDialog1.FileName; dataGridView1.DataSource = CSVFileHelper.OpenCSV(strCsvFile, '\t'); } }
static void Main(string[] args) { DataTable dt = CSVFileHelper.OpenCSV(@"e:\TRTWork\ExeceCamer\1234.csv"); double rg_max; double rg_min; double rg_eviation; double rg_mean; GetData(dt, "R/G_1", out rg_max, out rg_min, out rg_eviation, out rg_mean); Console.WriteLine(rg_max.ToString()); //for (int i = 0; i < dt.Rows.Count; i++) //{ // R_G_1.Add(Convert.ToDouble(dt.Rows[i]["R/G_1"])); // R_G_2.Add(Convert.ToDouble(dt.Rows[i]["R/G_2"])); // R_G_3.Add(Convert.ToDouble(dt.Rows[i]["R/G_3"])); //} //double[] R_G_1_value = R_G_1.Cast<double>().ToArray(); //double[] R_G_2_value = R_G_2.Cast<double>().ToArray(); //double[] R_G_3_value = R_G_3.Cast<double>().ToArray(); ////计算每列数据的 最大值 最小值 平均值 标准偏差值 //Console.WriteLine("**********************************************"); //Console.WriteLine("最大值="+R_G_1_value.Maximum().ToString()); //Console.WriteLine("最小值="+R_G_1_value.Minimum().ToString()); //Console.WriteLine("均值=" + R_G_1_value.Mean().ToString()); //Console.WriteLine("标准偏差值="+R_G_1_value.StandardDeviation().ToString());//标准偏差值 //Console.WriteLine("**********************************************"); //Console.WriteLine("最大值=" + R_G_2_value.Maximum().ToString()); //Console.WriteLine("最小值=" + R_G_2_value.Minimum().ToString()); //Console.WriteLine("均值=" + R_G_2_value.Mean().ToString()); //Console.WriteLine("标准偏差值=" + R_G_2_value.StandardDeviation().ToString());//标准偏差值 //Console.WriteLine("**********************************************"); //Console.WriteLine("最大值=" + R_G_3_value.Maximum().ToString()); //Console.WriteLine("最小值=" + R_G_3_value.Minimum().ToString()); //Console.WriteLine("均值=" + R_G_3_value.Mean().ToString()); //Console.WriteLine("标准偏差值=" + R_G_3_value.StandardDeviation().ToString());//标准偏差值 Console.Read(); }
public void TestInsertDB() { #warning 指定csv文件路径 DataTable dtA = CSVFileHelper.OpenCSV("C:/DEMO/temp/0729.csv"); DataTable dtB = CSVFileHelper.OpenCSV("C:/DEMO/temp/2019-07-29Data.csv"); #warning 指定主键 var keyFilids = new string[] { "AgentAcc", "VipAcc" }; var dicDifference = new Dictionary <int, DataTable>(); accountingMatching.Match(dtA, dtB, keyFilids, ref dicDifference); DAL dal = new DAL(connectString); foreach (var dic in dicDifference) { dal.InsertData2DB(dic); } }
private void LoadCsvFile_Click(object sender, EventArgs e) { dt = CSVFileHelper.OpenCSV(@"e:\TRTWork\ExeceCamer\12.csv"); //openFileDialog1.InitialDirectory = "e:\\"; //openFileDialog1.Filter = "(*.*)|*.*"; //openFileDialog1.RestoreDirectory = true; //if (openFileDialog1.ShowDialog() == DialogResult.OK) //{ // string fileName = openFileDialog1.FileName; // filePath = System.Windows.Forms.Application.StartupPath; // dt = CSVFileHelper.OpenCSV(fileName); //} }
private void LoadCsvFile_Click(object sender, EventArgs e) { HildControl(save_flag); openFileDialog1.InitialDirectory = "e:\\"; openFileDialog1.Filter = "(*.*)|*.*"; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == DialogResult.OK) { fileName = openFileDialog1.FileName; dt = CSVFileHelper.OpenCSV(fileName); save_flag = true; } HildControl(save_flag); save_flag = false; }
public string[] MemberName(string fileName) { var path = @"..\..\..\TMS_App_CodeTests\TestData\" + fileName; var dt = CSVFileHelper.OpenCSV(path); string[] username = new string[100000]; int count = 0; foreach (DataRow dr in dt.Rows) { if (dr[0].ToString() != null) { username[count] = dr[0].ToString(); count++; } } return(username); }
private void CreateShowTable() { dataTableToShow = CSVFileHelper.OpenCSV(dataFile); if (dataTableToShow == null) { dataTableToShow = new DataTable(); DataColumn dc = new DataColumn("采集时间"); dataTableToShow.Columns.Add(dc); int len = this.batteryList.Count * 24; for (var i = 0; i < len; i++) { DataColumn col = new DataColumn("单体电压" + (i + 1)); dataTableToShow.Columns.Add(col); } } dataGrid.ItemsSource = dataTableToShow.DefaultView; }
public static DataRow LoadProject(string name) { DataTable dt = CSVFileHelper.OpenCSV(PROJECTS_CONFIG_FILE); if (dt == null) { return(null); } foreach (DataRow dr in dt.Rows) { if (string.Compare(name, dr["ProjectName"].ToString(), true) == 0) { return(dr); } } return(null); }
private bool CompleteDescRecord(DBAccess.Model.BatteryModuleModel modBattery, ref string restr) { try { string testResultPath = string.Format(@"\\{0}\MESReport\PullTestResult\{1}_{2}.csv", welderIP, modBattery.palletID, modBattery.batModuleID); if (!System.IO.File.Exists(testResultPath)) { currentTaskDescribe = string.Format(this.nodeName + "铝丝焊结果文件:{0}不存在", testResultPath); return(false); } DataTable dt = CSVFileHelper.OpenCSV(testResultPath); string checkRes = ""; for (int j = 0; j < dt.Rows.Count; j++) { if (dt.Rows[j]["Traceability - integrated pull test - passed"].ToString().ToUpper() == "FALSE") { checkRes = "NG"; break; } } if (checkRes == "NG") { modBattery.checkResult = 2; modBattery.palletBinded = false; modBattery.tag3 = this.nodeName; //标识在哪个工位产生的NG,(共有三个工位,1#铝丝焊、2#铝丝焊、DCIR检测) } else { modBattery.checkResult = 1; } modBll.Update(modBattery); return(true); } catch (Exception ex) { restr = ex.Message; return(false); } }
public SiteMemberInfo MemberData(string UserName) { SiteMemberInfo sm = new SiteMemberInfo(); var path = @"..\..\..\TMS_App_CodeTests\TestData\ProviderTypeData_AddProviderType.csv"; var dt = CSVFileHelper.OpenCSV(path); foreach (DataRow dr in dt.Rows) { string username = dr[0].ToString(); if (UserName == username) { sm.UserName = dr[0].ToString(); sm.UserPwd = dr[1].ToString(); sm.RealName = dr[2].ToString(); sm.HeadPicPath = dr[3].ToString(); sm.Sex = dr[4].ToString(); sm.MobileNum = dr[5].ToString(); sm.IDNum = dr[6].ToString(); sm.Email = dr[7].ToString(); sm.QQ = dr[8].ToString(); sm.WeChat = dr[9].ToString(); sm.TotalCost = Convert.ToDecimal(dr[10].ToString()); sm.TotalPoints = Convert.ToInt32(dr[11].ToString()); sm.UsedPoints = Convert.ToInt32(dr[12].ToString()); sm.AddTime = Convert.ToDateTime(dr[13].ToString()); sm.Remarks = dr[14].ToString(); sm.InviteNum = dr[15].ToString(); sm.InviterUserName = dr[16].ToString(); sm.InviterRealName = dr[17].ToString(); } else { sm = null; } } return(sm); }
private void StartBackTest() { DateTime today = btParameter.StartDate.Date; MarketTimeRange marketRange = MarketTimeRange.getTimeRange(securityInfo.Market); int totalcount = this.policys.Count; DataMonitor da = new DataMonitor(); Parallel.For(0, totalcount, (j, LoopState) => { RunningPolicy policy = policys[j]; Guid g = policy.PolicyGuid; string backtesttitle = policy.getBackTestTitle(); PolicyStarted(new BackTestStartEventArgs(backtesttitle, g)); policy.PolicyResult_Arrival += policy_PolicyResult_Arrival; }); while (today <= btParameter.EndDate.Date) { string name = ConfigFileName.HistoryDataFileName + "\\Okex%" + securityInfo.Code + "%" + today.ToString("yyyyMMdd") + ".csv"; //string name = ConfigFileName.HistoryDataFileName + "\\XBTUSD-" + today.ToString("yyyyMMdd") + ".csv"; PolicyLoading(name); DataTable tickdatas = CSVFileHelper.OpenCSV(name); List <TickData> list_tickdata = new List <TickData>(); for (int i = 0; i < tickdatas.Rows.Count; i++) { DataRow dr = tickdatas.Rows[i]; DateTime tickTime = System.Convert.ToDateTime(dr["timestamp"].ToString().Replace("D", " ").Substring(0, 23)); //TickData tickdata = TickData.ConvertFromDataRow(dr); TickData tickdata = new TickData(); tickdata.Code = dr["symbol"].ToString(); tickdata.SecInfo = this.securityInfo; tickdata.Time = tickTime; tickdata.Preclose = 0; tickdata.Open = 0; tickdata.High = 0; tickdata.Low = 0; tickdata.Ask = System.Convert.ToDouble(dr["askPrice"]); tickdata.Bid = System.Convert.ToDouble(dr["bidPrice"]); tickdata.Last = (tickdata.Ask + tickdata.Bid) / 2; tickdata.Volume = 0; tickdata.Amt = 0; tickdata.IsReal = false; tickdata.Asks[0] = tickdata.Ask; tickdata.Bids[0] = tickdata.Bid; list_tickdata.Add(tickdata); } Parallel.For(0, totalcount, (j, LoopState) => { RunningPolicy policy = policys[j]; //policy.PolicyMessage_Arrival += policy_PolicyMessage_Arrival; //da.Simulator(tickdatas, policy.PolicyDataReceiver, policy.Inteval); da.BackSimulator(list_tickdata, policy.PolicyDataReceiver, 0); PolicyDataFinished(); }); list_tickdata.Clear(); today = today.AddDays(1); } Parallel.For(0, totalcount, (j, LoopState) => { Stopwatch sw = new Stopwatch(); RunningPolicy policy = policys[j]; Guid g = policy.PolicyGuid; PolicyFinished(g, sw.Elapsed); policy.PolicyResult_Arrival -= policy_PolicyResult_Arrival; sw.Stop(); }); RaiseFinished(new EventArgs()); }
public void Simulator(SecurityInfo si, DateTime startDate, DateTime endDate, DataReceiver da, int interval, bool needSimulte = false) { if (needSimulte) { DateTime today = startDate.Date; MarketTimeRange marketRange = MarketTimeRange.getTimeRange(si.Market); while (today <= endDate) { //DataTable tickdatas = CSVFileHelper.OpenCSV(ConfigFileName.HistoryDataFileName + "\\Okex%" + si.Code + "%" + today.ToString("yyyyMMdd") + ".csv"); //DataTable tickdatas = CSVFileHelper.OpenCSV(ConfigFileName.HistoryDataFileName + "\\" + si.Code + "-" + today.ToString("yyyyMMdd") + ".csv"); DataTable tickdatas = new DataTable(); try { tickdatas = CSVFileHelper.OpenCSV(ConfigFileName.HistoryDataFileName + "\\" + si.Code + "%" + today.ToString("yyyyMMdd") + ".csv"); } catch { } if (tickdatas.Rows.Count > 0) { for (int i = 0; i < tickdatas.Rows.Count; i++) { try { DataRow dr = tickdatas.Rows[i]; DateTime tickTime = System.Convert.ToDateTime(dr["timestamp"].ToString()); //DateTime tickTime = System.Convert.ToDateTime(dr["timestamp"].ToString().Replace("D", " ").Substring(0, 23)); TickData tickdata = new TickData(); tickdata.Code = si.Code; tickdata.SecInfo = GlobalValue.GetFutureByCodeAndMarket(tickdata.Code, si.Market); tickdata.Time = tickTime; tickdata.Preclose = 0; tickdata.Open = 0; tickdata.High = 0; tickdata.Low = 0; tickdata.Ask = System.Convert.ToDouble(dr["askPrice"].ToString()); tickdata.Bid = System.Convert.ToDouble(dr["bidPrice"].ToString()); //tickdata.Last = System.Convert.ToDouble(dr["lastPrice"].ToString()); tickdata.Last = (tickdata.Ask + tickdata.Bid) / 2; tickdata.Volume = 0; tickdata.Amt = 0; tickdata.IsReal = false; for (int j = 0; j < 10; j++) { tickdata.Asks[j] = tickdata.Ask; tickdata.Bids[j] = tickdata.Bid; tickdata.Asksizes[j] = System.Convert.ToDouble(dr["askSize"]); tickdata.Bidsizes[j] = System.Convert.ToDouble(dr["bidSize"]); } da.DataArrival(tickdata); if (interval != 0) { Thread.Sleep(interval); } } catch { } } } today = today.AddDays(1); } //DataTable tickdatas = CSVFileHelper.OpenCSV(ConfigFileName.HistoryDataFileName + "\\rb15.csv"); ////DataTable tickdatas = CSVFileHelper.OpenCSV(ConfigFileName.HistoryDataFileName + "\\XBTUSD-" + today.ToString("yyyyMMdd") + ".csv"); //if (tickdatas.Rows.Count > 0) //{ // for (int i = 0; i < tickdatas.Rows.Count; i++) // { // DataRow dr = tickdatas.Rows[i]; // DateTime tickTime = System.Convert.ToDateTime(dr["timestamp"].ToString()); // //TickData tickdata = TickData.ConvertFromDataRow(dr); // TickData tickdata = new TickData(); // tickdata.Code = "rb"; // tickdata.SecInfo = GlobalValue.GetFutureByCode(tickdata.Code); // tickdata.Time = tickTime; // tickdata.Preclose = 0; // tickdata.Open = 0; // tickdata.High = 0; // tickdata.Low = 0; // tickdata.Ask = System.Convert.ToDouble(dr["open"]); // tickdata.Bid = System.Convert.ToDouble(dr["high"]); // tickdata.Last = System.Convert.ToDouble(dr["close"]); // tickdata.Volume = 0; // tickdata.Amt = 0; // tickdata.IsReal = false; // for (int j = 0; j < 10; j++) // { // tickdata.Asks[j] = tickdata.Ask; // tickdata.Bids[j] = tickdata.Bid; // } // da.DataArrival(tickdata); // if (interval != 0) // Thread.Sleep(interval); // } //} } TickData td = new TickData(); td.Code = string.Empty; try { da.DataArrival(td); } catch { } }
private void UploadBatteryModToMes(object objModBattery) { try { DBAccess.Model.BatteryModuleModel modBattery = objModBattery as DBAccess.Model.BatteryModuleModel; string M_WORKSTATION_SN = ""; if (this.nodeID == "OPB004") { M_WORKSTATION_SN = "Y00101701"; } else { M_WORKSTATION_SN = "Y00102001"; } if (modBattery.palletBinded == false && modBattery.tag3 != null && modBattery.tag3 != this.nodeName) { string restr = this.nodeName + ":模块没有绑定!"; logRecorder.AddDebugLog(nodeName, string.Format("焊接完成反馈数据处理失败:{0}", restr)); return; } string testResultPath = string.Format(@"\\{0}\MESReport\BondParameters\{1}_{2}.csv", welderIP, modBattery.palletID, modBattery.batModuleID); if (!System.IO.File.Exists(testResultPath)) { string restr = string.Format(this.nodeName + "铝丝焊参数文件:{0}不存在", testResultPath); logRecorder.AddDebugLog(nodeName, string.Format("焊接完成反馈数据处理失败:{0}", restr)); return; } DataTable dt = CSVFileHelper.OpenCSV(testResultPath); string pullTestPath = string.Format(@"\\{0}\MESReport\PullTestResult\{1}_{2}.csv", welderIP, modBattery.palletID, modBattery.batModuleID); if (!System.IO.File.Exists(pullTestPath)) { string restr = string.Format(this.nodeName + "铝丝焊拉力结果参数文件:{0}不存在", testResultPath); logRecorder.AddDebugLog(nodeName, string.Format("焊接完成反馈数据处理失败:{0}", restr)); return; } DataTable dtPull = CSVFileHelper.OpenCSV(pullTestPath); int M_FLAG = 3; string M_DEVICE_SN = ""; string M_SN = modBattery.batModuleID; string M_UNION_SN = ""; string M_CONTAINER_SN = ""; string M_LEVEL = ""; string M_ITEMVALUE = GetItemVal(dt, dtPull); //上传数据 RootObject rObj = new RootObject(); string strJson = ""; rObj = DevDataUpload(M_FLAG, M_DEVICE_SN, M_WORKSTATION_SN, M_SN, M_UNION_SN, M_CONTAINER_SN, M_LEVEL, M_ITEMVALUE, ref strJson); currentTaskDescribe = rObj.RES + "," + M_FLAG + "," + M_WORKSTATION_SN + "," + M_ITEMVALUE + this.nodeName + rObj.CONTROL_TYPE; Console.WriteLine(rObj.RES); Console.WriteLine(M_ITEMVALUE); if (rObj.RES.ToUpper().Contains("NG")) //返回NG处理 { modBattery.checkResult = 2; //NG处理 modBattery.palletBinded = false; //NG要解绑 modBll.Update(modBattery); } logRecorder.AddDebugLog(nodeName, "上传mes数据:" + M_ITEMVALUE); this.WriteTxtLog(modBattery.batModuleID, "上传mes数据:" + M_ITEMVALUE + "返回结果:" + rObj.RES); logRecorder.AddDebugLog(nodeName, string.Format("上传MES,返回结果:{0}", rObj.RES)); } catch (Exception ex) { logRecorder.AddDebugLog(nodeName, string.Format("上传MES错误:{0}", ex.Message)); } }
private void btConvert_Click(object sender, EventArgs e) { if (this.txtPath.Text == null || this.txtPath.Text == String.Empty) { MessageBox.Show("请填选择导入文件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } try { string selectFile = this.txtPath.Text.Trim(); if (selectFile == null || selectFile == string.Empty) { MessageBox.Show("未获导入数据信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //if (openFileDialog.ShowDialog() == DialogResult.Yes) //{ // csvTable = CSVFileHelper.OpenCSV(selectFile); //} //else //{ // this.txtPath.Text = String.Empty; // this.lbContent.Text = String.Empty; //} DataTable csvTable = null; csvTable = CSVFileHelper.OpenCSV(selectFile); if (csvTable == null || csvTable.Rows.Count <= 1) { MessageBox.Show("未获导入数据信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (csvTable.Columns == null) { MessageBox.Show("未获导入正确数据信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (csvTable.Columns.Count != 5) { MessageBox.Show("未获导入正确数据信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (csvTable.Columns[0].ColumnName != "PN") { MessageBox.Show("未获导入正确数据信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (MessageBox.Show("请确保产线为非生产状态,确定更新请选择‘是’", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No) { return; } ProductDal dal = new ProductDal(); int countAdd = 0; int countRef = 0; int count = csvTable.Rows.Count; double div = (double)count / 100; double pogressValue = 0; foreach (DataRow row in csvTable.Rows) { ProductionMDL mdl = new ProductionMDL(); mdl = ProductionMDL.ParseDataRow(row); int ret = -1; pogressValue += div; if (dal.IsExist(mdl.PN) > 0) { ret = dal.UpdateProduction(mdl); if (ret > 0) { countRef++; UpdateContentInfo(mdl.PN + "更新成功", (int)div); } else { UpdateContentInfo(mdl.PN + "更新失败", (int)div); } } else { ret = dal.InsertProduction(mdl); if (ret > 0) { countAdd++; UpdateContentInfo(mdl.PN + "入库成功", (int)div); } else { UpdateContentInfo(mdl.PN + "入库失败", (int)div); } } } // UpdateContentInfo((countAdd+countRef).ToString() + "记录入库成功!"); MessageBox.Show((countAdd + countRef).ToString() + "记录入库成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (System.Exception ex) { MessageBox.Show(ex.Message.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }