private void Setting_Load(object sender, EventArgs e) { var datatype = new Jsonhelp().readjson("DataType", AppDomain.CurrentDomain.BaseDirectory + "config.json"); if (datatype == "csv") { rdbCsv.Checked = true; } else if (datatype == "Access") { rdbAccess.Checked = true; } txtCSVPath.Text = new Jsonhelp().readjson("CSVFilePath", AppDomain.CurrentDomain.BaseDirectory + "config.json"); txtAccessPath.Text = new Jsonhelp().readjson("AccessFilePath", AppDomain.CurrentDomain.BaseDirectory + "config.json"); }
//access public byte[] QueryAccess(RFIDConstants configData, string lot) { ModuleInfo objModule = new ModuleInfo(); //读取配置文件 string path = new Jsonhelp().readjson("AccessFilePath", AppDomain.CurrentDomain.BaseDirectory + "config.json"); if (!System.IO.File.Exists(path)) { MessageBox.Show("没有找到Access文件"); paintBackgroundColor(statusType.FAIL); return(null); } string conn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Persist Security Info=False;"; //DbUtility sqlhelp = new DbUtility(conn, DbProviderType.OleDb); string sql = new Jsonhelp().readjson("AccessSql", AppDomain.CurrentDomain.BaseDirectory + "config.json"); sql = string.Format(sql, lot); OleDbConnection oConn = new OleDbConnection(); OleDbCommand oCom = new OleDbCommand(); oConn.ConnectionString = conn; oConn.Open(); oCom.Connection = oConn; oCom.CommandText = sql; IDataReader dataReader = oCom.ExecuteReader(); //IDataReader dataReader= sqlhelp.ExecuteReader(sql, null); string moduletime = string.Empty; if (dataReader.Read()) { moduletime = DateTime.Parse(dataReader["testtime"].ToString()).ToString("yyyy-MM-dd");//+ " " + DateTime.Parse(dataReader["Time"].ToString()).ToString("HH:mm:ss"); objModule.PackedDate = moduletime; //电池生产时间从配置文件获取 modify by xue lei on 2018-9-28 objModule.CellDate = configData.cell_mfg_date;//new Jsonhelp().readjson("CellProductionDate", AppDomain.CurrentDomain.BaseDirectory + "config.json"); //moduletime; objModule.Pmax = dataReader["Pmax"].ToString(); objModule.Voc = dataReader["Voc"].ToString(); objModule.Vpm = dataReader["Vpm"].ToString(); objModule.Ipm = dataReader["Ipm"].ToString(); objModule.Isc = dataReader["Isc"].ToString(); objModule.FF = dataReader["FF"].ToString(); objModule.Module_ID = lot; objModule.ProductType = configData.product_type; } else { DoFailStuff(m_sSerialNumber + " " + "未找到组件记录!"); oConn.Close(); return(null); } //dataReader.Close(); ShowIVCurves(double.Parse(objModule.Isc), double.Parse(objModule.Ipm), double.Parse(objModule.Vpm), double.Parse(objModule.Voc)); byte[] btData = TagDataFormat.CreateByteArray(objModule, configData); oModuleInfo = objModule; ShowModuleInfo(true, configData); paintBackgroundColor(statusType.PASS); oConn.Close(); return(btData); }
private void tbx_SerialWrite_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (chkbox_burningTag.Checked && cbx_customer.SelectedValue == null) { MessageBox.Show("请选择客户!!!"); return; } string customer = cbx_customer.SelectedValue.ToString(); RFIDConstants const_parameters = null; if (dic_customer_RFID_constants.ContainsKey(customer)) { const_parameters = dic_customer_RFID_constants[customer]; //ms_cfg_mfg_name = const_parameters.mfg_name; //ms_cfg_mfg_country = const_parameters.mfg_country; //ms_iec_date = const_parameters.iec_date; //ms_iec_verfy = const_parameters.iec_verfy; //ms_iso = const_parameters.iso_desc; //ms_producttype = const_parameters.product_type; //ms_cell_mfg = const_parameters.cell_mfg; //ms_cellsource_country = const_parameters.cellsource_country; //ms_iso9000_date = const_parameters.iso_9000_date; //ms_iso9000_name = const_parameters.iso_9000_name; //ms_iso14000_date = const_parameters.iso_14000_date; //ms_iso14000_name = const_parameters.iso_14000_name; //ms_polarity_of_terminal = const_parameters.polarity_of_terminal; //ms_max_sys_vol = const_parameters.max_sys_vol; //ms_cell_mfg_date = const_parameters.cell_mfg_date; } CleanIVCurves(); ShowModuleInfo(false, null); string ser = tbx_SerialWrite.Text.Trim().ToUpper(); //tbx_SerialWrite.Text = ""; if (ser.Length > 0) { paintBackgroundColor(statusType.START); tbx_SerialWrite.Enabled = false; SetLabelStatus(statusType.START); m_sSerialNumber = ser; //add by xue lei on 2019-1-6 数据源配置 var datatype = new Jsonhelp().readjson("DataType", AppDomain.CurrentDomain.BaseDirectory + "config.json"); if (datatype == "") { MessageBox.Show("请先配置数据源"); return; } if (chkbox_burningTag.Checked) { if (!GetTagUID()) { WriteLog(lrtxtLog, "没有发现标签!", 1); common.rf_beep(ReaderInfo.icdev, 20); paintBackgroundColor(statusType.FAIL); List <string> csvValueList = new List <string> { System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), m_sSerialNumber, "Fail", "" }; WriteCSVLog.WriteCSV(csvValueList); SetSerialTxtFocus(); Speech("烧录失败"); } else { if (datatype == "csv") { WriteRfid(QueryCSVToOdbc(const_parameters, ser)); } else if (datatype == "Access") { WriteRfid(QueryAccess(const_parameters, ser)); } else { #region query data from database WcfCaller.querySerialInfo((o, ex) => { if (ex == null) { if (o == null) { DoFailStuff(m_sSerialNumber + " " + "未找到组件记录!"); return; } #region chech region state if (string.IsNullOrEmpty(o.ProductType)) { o.ProductType = const_parameters.product_type; //DoFailStuff(m_sSerialNumber + " " + Resources.strPrompt01); //return; } if (string.IsNullOrEmpty(o.CellDate)) { o.CellDate = const_parameters.cell_mfg_date; //DoFailStuff(m_sSerialNumber + " " + Resources.strPrompt02); //return; } if (string.IsNullOrEmpty(o.PackedDate)) { DoFailStuff(m_sSerialNumber + " " + Resources.strPrompt03); return; } if (string.IsNullOrEmpty(o.Pmax)) { DoFailStuff(m_sSerialNumber + " " + Resources.strPrompt04); return; } if (string.IsNullOrEmpty(o.Voc)) { DoFailStuff(m_sSerialNumber + " " + Resources.strPrompt05); return; } if (string.IsNullOrEmpty(o.Vpm)) { DoFailStuff(m_sSerialNumber + " " + Resources.strPrompt06); return; } if (string.IsNullOrEmpty(o.Ipm)) { DoFailStuff(m_sSerialNumber + " " + Resources.strPrompt07); return; } if (string.IsNullOrEmpty(o.Isc)) { DoFailStuff(m_sSerialNumber + " " + Resources.strPrompt08); return; } #endregion ShowIVCurves(double.Parse(o.Isc), double.Parse(o.Ipm), double.Parse(o.Vpm), double.Parse(o.Voc)); o.customer = cbx_customer.SelectedValue.ToString(); //SetRFIDConstants(o.customer); byte[] btData = TagDataFormat.CreateByteArray(o, const_parameters); oModuleInfo = o; m_sBasicInfo = o.ProductType + "|" + o.PackedDate.Replace("-", ".") + "|" + o.Pivf + "|" + o.Module_ID + "|" + o.CellDate.Replace("-", ".") + "|3"; if (WriteData(btData)) { //WriteLog2DB(); paintBackgroundColor(statusType.PASS); WriteLog(lrtxtLog, m_sSerialNumber + " " + "烧录成功!", 0); common.rf_beep(ReaderInfo.icdev, 10); List <string> csvValueList = new List <string> { System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), m_sSerialNumber, "Pass", m_sTagUIDstring, m_sBasicInfo }; WriteCSVLog.WriteCSV(csvValueList); ShowModuleInfo(true, const_parameters); Speech("烧录成功"); } else { DoFailStuff(m_sSerialNumber + " " + "烧录失败!"); } } else { DoFailStuff("与服务器通讯发生异常" + ex.Message); } SetSerialTxtFocus(); }, new string[] { m_sSerialNumber, m_sTagUIDstring }); #endregion } } } else { if (datatype == "csv") { QueryCSVToOdbc(const_parameters, ser); } else if (datatype == "Access") { QueryAccess(const_parameters, ser); } else { #region query data from database WcfCaller.querySerialInfo((o, ex) => { if (ex == null) { if (o == null) { DoFailStuff(m_sSerialNumber + " " + "未找到组件记录!"); return; } #region chech region state if (string.IsNullOrEmpty(o.ProductType)) { o.ProductType = const_parameters.product_type; //DoFailStuff(m_sSerialNumber + " " + Resources.strPrompt01); //return; } if (string.IsNullOrEmpty(o.CellDate)) { o.CellDate = const_parameters.cell_mfg_date; //DoFailStuff(m_sSerialNumber + " " + Resources.strPrompt02); //return; } if (string.IsNullOrEmpty(o.PackedDate)) { DoFailStuff(m_sSerialNumber + " " + Resources.strPrompt03); return; } if (string.IsNullOrEmpty(o.Pmax)) { DoFailStuff(m_sSerialNumber + " " + Resources.strPrompt04); return; } if (string.IsNullOrEmpty(o.Voc)) { DoFailStuff(m_sSerialNumber + " " + Resources.strPrompt05); return; } if (string.IsNullOrEmpty(o.Vpm)) { DoFailStuff(m_sSerialNumber + " " + Resources.strPrompt06); return; } if (string.IsNullOrEmpty(o.Ipm)) { DoFailStuff(m_sSerialNumber + " " + Resources.strPrompt07); return; } if (string.IsNullOrEmpty(o.Isc)) { DoFailStuff(m_sSerialNumber + " " + Resources.strPrompt08); return; } #endregion ShowIVCurves(double.Parse(o.Isc), double.Parse(o.Ipm), double.Parse(o.Vpm), double.Parse(o.Voc)); o.customer = cbx_customer.SelectedValue.ToString(); //SetRFIDConstants(o.customer); oModuleInfo = o; paintBackgroundColor(statusType.PASS); ShowModuleInfo(true, const_parameters); WriteLog(lrtxtLog, m_sSerialNumber + " " + "获取功率信息成功!", 0); SetSerialTxtFocus(); } else { DoFailStuff("与服务器通讯发生异常" + ex.Message); //WriteLog(lrtxtLog, "与服务器通讯发生异常"+ex.Message, 1); //common.rf_beep(ReaderInfo.icdev, 20); //paintBackgroundColor(statusType.FAIL); //List<string> csvValueList = new List<string> { System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), m_sSerialNumber, "Fail", "" }; //WriteCSVLog.WriteCSV(csvValueList); //SetSerialTxtFocus(); //Speech("烧录失败"); } }, new string[] { m_sSerialNumber, m_sTagUIDstring }); #endregion } } } } } }
//读取csv /// <summary> /// Odbc查询CSV /// </summary> public byte[] QueryCSVToOdbc(RFIDConstants configData, string lot) { ModuleInfo objModule = new ModuleInfo(); //读取配置文件 string path = new Jsonhelp().readjson("CSVFilePath", AppDomain.CurrentDomain.BaseDirectory + "config.json"); //path = path.Replace("\\\\", "\\"); if (!System.IO.File.Exists(path)) { MessageBox.Show("没有找到CSV文件"); paintBackgroundColor(statusType.FAIL); return(null); } string newfilename = System.DateTime.Now.ToString("yyyyMMddHHmmss") + ".csv"; string newfilepath = AppDomain.CurrentDomain.BaseDirectory + newfilename; System.IO.File.Copy(path, newfilepath); //文件路径 string tableName = newfilepath.Substring(newfilepath.LastIndexOf('\\') + 1); string filePath = newfilepath.Substring(0, newfilepath.LastIndexOf('\\') + 1);//AppDomain.CurrentDomain.BaseDirectory; string pContent = string.Empty; OdbcConnection odbcConn = new OdbcConnection(); OdbcCommand odbcCmd = new OdbcCommand(); OdbcDataReader dataReader; try { string strConnOledb = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq="; strConnOledb += filePath; strConnOledb += ";Extensions=csv,txt;"; odbcConn.ConnectionString = strConnOledb; odbcConn.Open(); StringBuilder commandText = new StringBuilder("SELECT "); commandText.AppendFormat("Date,Time,Snr,Voc,Isc,Pmax,Vpmax,Ipmax,FF From {0} where Snr ='" + lot + "' ", tableName); odbcCmd.Connection = odbcConn; odbcCmd.CommandText = commandText.ToString(); dataReader = odbcCmd.ExecuteReader(CommandBehavior.CloseConnection); string moduletime = string.Empty; if (dataReader.Read()) { moduletime = DateTime.Parse(dataReader["Date"].ToString()).ToString("yyyy-MM-dd");//+ " " + DateTime.Parse(dataReader["Time"].ToString()).ToString("HH:mm:ss"); objModule.PackedDate = moduletime; //电池生产时间从配置文件获取 modify by xue lei on 2018-9-28 objModule.CellDate = configData.cell_mfg_date;//new Jsonhelp().readjson("CellProductionDate", AppDomain.CurrentDomain.BaseDirectory + "config.json"); //moduletime; objModule.Pmax = dataReader["Pmax"].ToString(); objModule.Voc = dataReader["Voc"].ToString(); objModule.Vpm = dataReader["Vpmax"].ToString(); objModule.Ipm = dataReader["Ipmax"].ToString(); objModule.Isc = dataReader["Isc"].ToString(); objModule.FF = dataReader["FF"].ToString(); objModule.Module_ID = lot; objModule.ProductType = configData.product_type; } else { DoFailStuff(m_sSerialNumber + " " + "未找到组件记录!"); } //dataReader.Close(); ShowIVCurves(double.Parse(objModule.Isc), double.Parse(objModule.Ipm), double.Parse(objModule.Vpm), double.Parse(objModule.Voc)); byte[] btData = TagDataFormat.CreateByteArray(objModule, configData); oModuleInfo = objModule; ShowModuleInfo(true, configData); paintBackgroundColor(statusType.PASS); return(btData); } catch (System.Exception ex) { MessageBox.Show(ex.Message); odbcConn.Close(); byte[] data = null; return(data); } finally { odbcConn.Close(); } }