/// <summary> /// 通过socket获取DataTable数据 /// </summary> /// <param name="sql"></param> /// <returns></returns> private DataTable getDataTable(string sql) { try { DataTable sqlData_Table = new DataTable(); //发送请求入库数据Socket string sqlResultValue = clientSocket.SendData("{getDataTable;" + "1201;" + sql + "}"); string[] values = sqlResultValue.Split(new char[] { ';' }); if (values.Length < 3) { return(sqlData_Table); } //给DataTable添加列名 string[] columnValues = values[2].Split('!'); foreach (string columnName in columnValues) { sqlData_Table.Columns.Add(columnName, typeof(string)); } //验证没有列名就返回NULL if (sqlData_Table.Columns.Count == 0) { return(sqlData_Table); } int iLoop = Convert.ToInt32(values[1]); if (values[3].ToString().Trim() != string.Empty)//如果查询出来的数据是空的直接返回一个带列名的DataTable { string[] rowData = values[3].Split('!'); //给DataTable填充数据 for (int i = 0; i < rowData.Length; i += iLoop) { DataRow dr = sqlData_Table.NewRow(); for (int loop = 0; loop < iLoop; loop++) { //dr[columnValues[loop]] = rowData[i + loop]; dr[loop] = rowData[i + loop]; } sqlData_Table.Rows.Add(dr); } } return(sqlData_Table); } catch (Exception ex) { return(null); } }
private void SetFujiTrax() { int success = 0; int index = 0; StringBuilder sbMat = new StringBuilder(); foreach (DataGridViewRow dgvr in gridExcelData.Rows) { string uid = dgvr.Cells["MATERIAL_BIN_NUMBER"].FormattedValue.ToString().Trim(); string partNumber = dgvr.Cells["PART_NUMBER"].FormattedValue.ToString().Trim(); string VendorCode = dgvr.Cells["VENDOR_CODE"].FormattedValue.ToString().Trim(); string LotNr = dgvr.Cells["LOT_NR"].FormattedValue.ToString().Trim(); string DateCode = dgvr.Cells["DATE_CODE"].FormattedValue.ToString().Trim(); string CreatedDate = dgvr.Cells["CREATED_DATE"].FormattedValue.ToString().Trim(); sbMat.Append("'" + uid + "',"); if (index == 100) { index = 0; success += 101; this.lblResult.Text = success.ToString(); Application.DoEvents(); string sqlResultValue = clientSocket.SendData("{InsertFUJIBYPC;" + "1201;" + sbMat.ToString().TrimEnd(',') + "}"); sbMat.Clear(); } else { index++; } } //会有部分凑不齐101所以后面要记得补上这些数据 郑培聪 2017/10/18 string sqlResultValue2 = clientSocket.SendData("{InsertFUJIBYPC;" + "1201;" + sbMat.ToString().TrimEnd(',') + "}"); if (tbxUID.Text.Trim() == string.Empty) { tbLog.AppendText("Success--->" + selectTime.ToString() + "\n"); } else { tbLog.AppendText("Success--->" + tbxUID.Text.Trim().ToUpper() + "\n"); } tbLog.ScrollToCaret(); }
/// <summary> /// 获取成品入库数据 /// </summary> /// <returns></returns> private DataTable GetFPData() { try { DataTable dt = new DataTable(); dt.Columns.Add("FPNO", typeof(string)); dt.Columns.Add("FPSEQ", typeof(int)); dt.Columns.Add("FPReceiveDate", typeof(string)); dt.Columns.Add("FPInspectionDate", typeof(string)); dt.Columns.Add("FPWoType", typeof(string)); dt.Columns.Add("FPwoNumber", typeof(string)); dt.Columns.Add("FPPartNumber", typeof(string)); dt.Columns.Add("FPPartDEsc", typeof(string)); dt.Columns.Add("FPNumberNo", typeof(string)); dt.Columns.Add("FPQty", typeof(string)); dt.Columns.Add("FPUnit", typeof(string)); dt.Columns.Add("FPInspectionNo", typeof(string)); dt.Columns.Add("FPProcessState", typeof(string)); dt.Columns.Add("FPInpsectionState", typeof(string)); CommonFunction commonHandler = new CommonFunction(sessionContext, this); //获取本厂厂别编码 string plantNo = commonHandler.GetSiteNoByStationNo(config.StationNumber); //发送请求入库数据Socket string iqcValue = clientSocket.SendData("{getFPResultData;" + plantNo + "}"); LogHelper.Info("Receive message :" + iqcValue); string[] values = iqcValue.Split(new char[] { ';' }); if (values.Length < 4) { LogHelper.Error("No Finish Production data"); return(null); } int iCount = Convert.ToInt32(values[1]); int iLoop = 11; string strValue = values[3].TrimEnd(new char[] { '#' }); string[] fpItems = strValue.TrimEnd(new char[] { '}' }).Split(new char[] { '!' }); int iSEQ = 0; for (int i = 0; i < fpItems.Length; i += iLoop) { iSEQ++; DataRow row = dt.NewRow(); LogHelper.Debug("Row index:" + iSEQ); //LogHelper.Debug("Row data:" + fpItems[i] + ";" + fpItems[i + 1] + ";" + fpItems[i + 2] + ";" + fpItems[i + 3] + fpItems[i + 4] + ";" + fpItems[i + 5] + ";" + fpItems[i + 6] + ";" + fpItems[i + 7] + fpItems[i + 8]); row["FPNO"] = iSEQ; row["FPReceiveDate"] = GetDateTimeStringValue(fpItems[i]); row["FPInspectionDate"] = GetDateTimeStringValue(fpItems[i + 1]); row["FPwoNumber"] = fpItems[i + 2]; row["FPPartNumber"] = fpItems[i + 3]; row["FPPartDEsc"] = fpItems[i + 4]; row["FPNumberNo"] = fpItems[i + 5]; row["FPQty"] = fpItems[i + 6]; row["FPUnit"] = fpItems[i + 7]; row["FPInspectionNo"] = fpItems[i + 8]; row["FPInpsectionState"] = string.IsNullOrWhiteSpace(row["FPInspectionDate"].ToString()) ? "未检验" : "检验完成"; row["FPSEQ"] = GetFPSEQValue(fpItems[i + 9]); row["FPWoType"] = fpItems[i + 10]; dt.Rows.Add(row); } return(dt); } catch (Exception ex) { LogHelper.Error(ex); return(null); } }
private DataTable GetIQCData(int inclusive, int exclusive) { try { DataTable dt = new DataTable(); dt.Columns.Add("IQCNO", typeof(string)); dt.Columns.Add("IQCReceiveDate", typeof(string)); dt.Columns.Add("IQCInspectionDate", typeof(string)); dt.Columns.Add("IQCVenderName", typeof(string)); dt.Columns.Add("IQCPartNumber", typeof(string)); dt.Columns.Add("IQCPartDEsc", typeof(string)); dt.Columns.Add("IQCPurchNo", typeof(string)); dt.Columns.Add("IQCUnit", typeof(string)); dt.Columns.Add("IQCQty", typeof(string)); dt.Columns.Add("IQCMatDocNo", typeof(string)); dt.Columns.Add("IQCBatchNo", typeof(string)); dt.Columns.Add("IQCProcessState", typeof(string)); //dt.Columns.Add("IQCProcessStateDesc", typeof(string)); dt.Columns.Add("IQCInpsectionState", typeof(string)); CommonFunction commonHandler = new CommonFunction(sessionContext, this); string plantNo = commonHandler.GetSiteNoByStationNo(config.StationNumber); string iqcValue = clientSocket.SendData("#11;" + plantNo + ";" + inclusive + ";" + exclusive + "#"); LogHelper.Info("Receive message :" + iqcValue); string[] values = iqcValue.Split(new char[] { ';' }); if (values.Length < 4) { LogHelper.Error("No IQC data"); return(null); } int iCount = Convert.ToInt32(values[1]); int iLoop = Convert.ToInt32(values[2]); string strValue = values[3].TrimEnd(new char[] { '#' }); string[] iqcItems = strValue.Split(new char[] { ',' }); int iSEQ = 0; for (int i = 0; i < iqcItems.Length; i += iLoop) { iSEQ++; DataRow row = dt.NewRow(); row["IQCNO"] = iSEQ; row["IQCReceiveDate"] = Convert.ToDateTime(iqcItems[i]).ToString("yyyy/MM/dd HH:mm:ss"); row["IQCInspectionDate"] = Convert.ToDateTime(iqcItems[i + 1]).ToString("yyyy/MM/dd HH:mm:ss"); row["IQCVenderName"] = iqcItems[i + 2]; row["IQCPartNumber"] = iqcItems[i + 3]; row["IQCPartDEsc"] = iqcItems[i + 4]; row["IQCPurchNo"] = iqcItems[i + 5]; row["IQCUnit"] = iqcItems[i + 6]; row["IQCQty"] = iqcItems[i + 7]; row["IQCMatDocNo"] = iqcItems[i + 8]; row["IQCBatchNo"] = iqcItems[i + 9]; row["IQCProcessState"] = iqcItems[i + 11]; //row["IQCProcessStateDesc"] = iqcItems[i + 10] == "0" ? "未检验" : "已检验"; row["IQCInpsectionState"] = GetInspectionState(iqcItems[i + 11]); dt.Rows.Add(row); } return(dt); } catch (Exception ex) { LogHelper.Error(ex); return(null); } }