/// <summary> /// 按键事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ClickEvent(object sender, RoutedEventArgs e) { string errText = string.Empty; //验证用户名&密码 if ((errText = GetUserInfo()).Length > 0) { MessageBox.Show(errText, "ERROR"); return; } DataSet ds = DbInf.LogOnSystem(_userId, _password, ref errText); if (errText.Length > 0) { MessageBox.Show(errText, "ERROR"); return; } User.CurrUser = new User(ds); //验证权限 if ((errText = HaveAuthority(User.CurrUser)).Length > 0) { MessageBox.Show(errText, "ERROR"); System.Environment.Exit(0); } DialogResult = true; }
private string BindOPCDb() { string errText = string.Empty; DataSet ds = DbInf.GetOPCDbInfo(ref errText); if (errText.Length > 0) { return(errText); } int itemNum = 0; //创建同步组 DataRow[] drs = ds.Tables[0].Select("type = 'SYNC'"); if ((itemNum = drs.Length) > 0) { _idAim = new string[itemNum]; _syncItemHandle = new int[itemNum]; //添加组 errText = _opcDaConn.AddSyncGroup(out _syncGroupOpcInfo); if (errText.Length > 0) { return(errText); } //组装对象 OpcRcw.Da.OPCITEMDEF[] items = new OpcRcw.Da.OPCITEMDEF[itemNum]; for (int i = 0; i < itemNum; i++) { items[i].szAccessPath = ""; items[i].bActive = 1; items[i].dwBlobSize = 1; items[i].pBlob = IntPtr.Zero; items[i].hClient = i; items[i].vtRequestedDataType = (short)VarEnum.VT_BSTR; items[i].szItemID = drs[i]["db_str"].ToString(); _idAim[i] = drs[i]["id"].ToString() + _idAimSplitStr + drs[i]["db_aim"].ToString(); } //添加对象 errText = _opcDaConn.AddSyncItems(_syncGroupOpcInfo.SyncGroupObj, items, _syncItemHandle); if (errText.Length > 0) { return(errText); } } //创建异步组 drs = ds.Tables[0].Select("type = 'ASYNC'"); if ((itemNum = drs.Length) > 0) { _idAim = new string[itemNum]; //添加组 errText = _opcDaConn.AddAsyncGroup(out _asyncGroupOpcInfo); if (errText.Length > 0) { return(errText); } //组装对象 OpcRcw.Da.OPCITEMDEF[] items = new OpcRcw.Da.OPCITEMDEF[itemNum]; for (int i = 0; i < itemNum; i++) { items[i].szAccessPath = ""; items[i].bActive = 1; items[i].dwBlobSize = 1; items[i].pBlob = IntPtr.Zero; items[i].hClient = i; items[i].vtRequestedDataType = (short)VarEnum.VT_BSTR; items[i].szItemID = drs[i]["db_str"].ToString(); AsyncItemHandleToDeviceDic.Add(i, drs[i]["id"].ToString() + _idAimSplitStr + drs[i]["db_aim"].ToString()); } //添加对象 int[] itemHandle = new int[itemNum]; _opcDaConn.AddAsyncItems(_asyncGroupOpcInfo.AsyncGroupObj, items, itemHandle); if (errText.Length > 0) { return(errText); } } return(errText); }
private void DealInfFile(string fullPath) { string errText = string.Empty; string tmpFullPath = fullPath.Replace(".csv", "tmp.csv"); string sourceFileName = Path.GetFileName(fullPath).Replace("loading", ""); string tableName = Path.GetFileName(fullPath).Replace(".csv", "").Substring(0, 31); string import_s_time = DateTime.Now.ToString("yyyyMMddHHmmssfff"); try { //转化临时excel FileHelper.ConvertExcel(fullPath, tmpFullPath, ref errText); if (errText.Length <= 0) { string extractSqlStr = string.Empty;; string sqlStr = string.Empty; //2.1.1.1 站点标签信息 if (fullPath.Contains("STINFO")) { extractSqlStr = @"select F1 as send_time,F2 as batch_id,F3 as tag_id,F4 as tag_attribute,F5 as station_id,F6 as customer_id,'" + sourceFileName + "' as interface_way,'" + import_s_time + "' as import_s_time from [" + tableName + "$]"; sqlStr = "select t.station_id,t.tag_id,t.tag_attribute,t.batch_id,t.customer_id,t.send_time,t.interface_way,t.import_s_time from inf_tag t where 1=0"; } else if (fullPath.Contains("BOINFO")) //2.1.1.2 批次拣选数据 { extractSqlStr = @"select F1 as send_time,F2 as batch_id,F3 as sku,F4 as order_qty,F5 as line_id,F6 as customer_id,F7 as wave_id,F8 as flag,'" + sourceFileName + "' as interface_way,'" + import_s_time + "' as import_s_time from [" + tableName + "$]"; sqlStr = "select t.batch_id,t.wave_id,t.customer_id,t.sku,t.order_qty,t.flag,t.send_time,t.interface_way,t.import_s_time,t.line_id from inf_order t where 1=0"; } else if (fullPath.Contains("SKU")) //2.1.6 SKU Master { string flag = (fullPath.Contains("DELETE")) ? "OFF" : "ON"; extractSqlStr = @"select F1 as sku,F2 as sku_name,F3 as sku_description,F4 as sku_attribute,F5 as weight,F6 as length,F7 as width,F8 as height,F9 as pack_unit_size,'" + flag + "' as flag,'" + sourceFileName + "' as interface_way,'" + import_s_time + "' as import_s_time from [" + tableName + "$]"; sqlStr = "select t.sku,t.sku_name,t.sku_description,t.sku_attribute,t.weight,t.length,t.width,t.height,t.pack_unit_size,t.flag,t.interface_way,t.import_s_time from inf_sku t where 1=0"; } else if (fullPath.Contains("UPC")) //2.1.7 UPC Master { string flag = (fullPath.Contains("DELETE")) ? "OFF" : "ON"; extractSqlStr = @"select F1 as sku,F2 as upc,'" + flag + "' as flag,'" + sourceFileName + "' as interface_way,'" + import_s_time + "' as import_s_time from [" + tableName + "$]"; sqlStr = "select t.upc,t.sku,t.flag,t.interface_way,t.import_s_time from inf_upc t where 1=0"; } else { errText = "interface file name does not include agreed string"; } if (sqlStr.Length > 0 && extractSqlStr.Length > 0) { DbInf.BatchImport(tmpFullPath, false, extractSqlStr, sqlStr, ref errText); } #region batch import other implement //DataTable dt = DbInf.GetTemplate("STINFO", ref errText).Tables[0]; //if (errText.Length > 0) //{ // return; //} //FileHelper.InputFromExcel(tmpFullPath, false, extractSqlStr, ref dt, ref errText); //if (errText.Length > 0) //{ // return; //} //DbInf.BatchImportTag(dt, sqlStr, ref errText); //if (errText.Length > 0) //{ // return; //} #endregion } } catch (Exception ex) { errText = ex.Message; } finally { string resultFileName = string.Empty; if (errText.Length > 0) { resultFileName = fullPath.Replace("loading", "fail"); } else { resultFileName = fullPath.Replace("loading", "success"); } File.Move(fullPath, resultFileName); if (File.Exists(tmpFullPath)) { File.Delete(tmpFullPath); } } }