public string UploadMasterWeight(string Plant, string Model, string GrossWeight, string NetWeight, string Unit, out string errorText) { BaseLog.LoggingInfo(logger, "Plant: \r{0}", Plant); BaseLog.LoggingInfo(logger, "Model: \r{0}", Model); BaseLog.LoggingInfo(logger, "GrossWeight: \r{0}", GrossWeight); BaseLog.LoggingInfo(logger, "NetWeight: \r{0}", NetWeight); BaseLog.LoggingInfo(logger, "Unit: \r{0}", Unit); string errorCode = "0"; errorText = ""; string connectionDB = "SD_DBServer"; string connectionDB_BK = "SD_DBServer_BK"; string methodName = MethodBase.GetCurrentMethod().Name; string Remark1 = ""; NetWeight = (NetWeight == null ? "" : NetWeight); NetWeight = (NetWeight == "0" ? "0.00" : NetWeight); BaseLog.LoggingBegin(logger, methodName); try { SAPMasterWeightWS.ZWS_MASTER_WEIGHT_UPLOADClient SAPMasterWeightClient = new SAPMasterWeightWS.ZWS_MASTER_WEIGHT_UPLOADClient("SAPMasterWeight"); SAPMasterWeightClient.ClientCredentials.UserName.UserName = ConfigurationManager.AppSettings["SAPUserName"].ToString(); SAPMasterWeightClient.ClientCredentials.UserName.Password = ConfigurationManager.AppSettings["SAPUserPwd"].ToString(); List<SAPMasterWeightWS.ZwsMasterWeightInLine> MasterWeightInlist = new List<SAPMasterWeightWS.ZwsMasterWeightInLine>(); string TxnId = string.Format("{0:yyyyMMddHHmmssfff}", DateTime.Now); SQL.InsertMasterWeightLog(connectionDB_BK, 0, TxnId, Plant, Model, GrossWeight, NetWeight, Unit, Remark1, "Receive", "Success", "", "FIS"); SAPMasterWeightWS.ZwsMasterWeightInLine item1 = new SAPMasterWeightWS.ZwsMasterWeightInLine(); item1.Serialnumber = Model.Trim()+"-"+TxnId; item1.Plant = Plant; item1.Id = Model; item1.Grossweight = GrossWeight; item1.Netweight = NetWeight; item1.Unit = Unit; item1.Remark1 = Remark1; MasterWeightInlist.Add(item1); SQL.InsertSendData_DB(connectionDB, 0, "SendMasterWeight", item1.Id.Trim(), item1.Plant.Trim(), item1.Serialnumber.Trim(), item1.Grossweight + "," + item1.Netweight + "," + item1.Unit + "," + item1.Remark1, IMES.Service.Common.EnumMsgState.Sending, DateTime.Now); SAPMasterWeightWS.ZwsMasterWeightOutLine[] MasterWeightOutLine = SAPMasterWeightClient.ZwsMasterWeightUpload(MasterWeightInlist.ToArray()); //bool rt; //rt = true; foreach (SAPMasterWeightWS.ZwsMasterWeightOutLine item in MasterWeightOutLine) { if (item.Result == "I" || item.Result == "U") { SQL.InsertTxnDataLog_DB(connectionDB, 0, IMES.Service.Common.EnumMsgCategory.Receive, "ReceiveMasterWeight", item.Id, item.Plant.Trim(), item.Serialnumber.Trim(), item.Result, item.Message, IMES.Service.Common.EnumMsgState.Success, ""); SQL.InsertMasterWeightLog(connectionDB_BK, 0, item.Serialnumber.Trim(), item.Plant.Trim(), item.Id, "", "", "", "", "Response", "Success", "", "SAP"); errorCode = item.Result; } else { SQL.InsertTxnDataLog_DB(connectionDB, 0, IMES.Service.Common.EnumMsgCategory.Receive, "ReceiveMasterWeight", item.Id, item.Plant.Trim(), item.Serialnumber.Trim(), item.Result, item.Message, IMES.Service.Common.EnumMsgState.Fail, ""); SQL.InsertMasterWeightLog(connectionDB_BK, 0, item.Serialnumber.Trim(), item.Plant.Trim(), item.Id, "", "", "", "", "Response", "Fail", item.Message, "SAP"); errorCode = item.Result; } BaseLog.LoggingInfo(logger, "Serialnumber: \r{0}", item.Serialnumber); BaseLog.LoggingInfo(logger, "Model: \r{0}", Model); BaseLog.LoggingInfo(logger, "Plant: \r{0}", Plant); BaseLog.LoggingInfo(logger, "Result: \r{0}", item.Result); BaseLog.LoggingInfo(logger, "Errortext: \r{0}", item.Message); errorText = item.Message; } return errorCode; } catch (Exception e) { BaseLog.LoggingError(logger, MethodBase.GetCurrentMethod(), e); errorCode = "9"; errorText = e.Message; return errorCode; } finally { BaseLog.LoggingEnd(logger, methodName); } }
private static void SendSAPMasterWeight(SAPWeightDef def, List<SAPMasterWeight> weightList) { string methodName = MethodBase.GetCurrentMethod().Name; BaseLog.LoggingBegin(logger, methodName); try { SAPMasterWeightWS.ZWS_MASTER_WEIGHT_UPLOADClient SAPWeightClient = new SAPMasterWeightWS.ZWS_MASTER_WEIGHT_UPLOADClient("SAPMasterWeight"); SAPWeightClient.ClientCredentials.UserName.UserName = ConfigurationManager.AppSettings["SAPUserName"].ToString(); SAPWeightClient.ClientCredentials.UserName.Password = ConfigurationManager.AppSettings["SAPUserPwd"].ToString(); List<SAPMasterWeightWS.ZwsMasterWeightInLine> weightlist = new List<SAPMasterWeightWS.ZwsMasterWeightInLine>(); //string IDList=""; string TxnId = string.Format("{0:yyMMddHHmmssfff}", DateTime.Now); foreach (SAPMasterWeight item in weightList) { SAPMasterWeightWS.ZwsMasterWeightInLine item1 = new SAPMasterWeightWS.ZwsMasterWeightInLine(); item1.Serialnumber = (item.ID.ToString().Trim() + "-" + TxnId).PadRight(33).Substring(0, 33); //item1.Serialnumber = TxnId.PadRight(25); item1.Plant = def.PlantCode; item1.Id = item.ID; item1.Grossweight = item.GrossWeight; item1.Netweight = item.NetWeight; item1.Unit = def.WeightUnit; item1.Remark1 = ""; weightlist.Add(item1); SQL.InsertSendData("SendMasterWeight", item.ID, def.PlantCode, item1.Serialnumber.Trim(), item.ID + ";" + item.GrossWeight + ";" + item.NetWeight + ";" + def.WeightUnit + ";" + def.DBName, IMES.Service.Common.EnumMsgState.Sending, DateTime.Now); } logger.DebugFormat("*** Send MasterWeight SAP ~ Start ~***"); SAPMasterWeightWS.ZwsMasterWeightOutLine[] weightOutList = SAPWeightClient.ZwsMasterWeightUpload(weightlist.ToArray()); logger.DebugFormat("*** Send MasterWeight SAP ~ End ~***"); List<string> IdOKList = new List<string>(); List<string> IdFailList = new List<string>(); foreach (SAPMasterWeightWS.ZwsMasterWeightOutLine item in weightOutList) { logger.DebugFormat("SAP Return Result :[" + item.Result+ "]"); logger.DebugFormat("SAP Return Message :[" + item.Message + "]"); string dataId = (item.Serialnumber.Split(new char[] { '-' }))[0].Trim(); if (item.Result == "S") { //IdOKList.Add(dataId); SQL.InsertTxnDataLog(EnumMsgCategory.Receive, "ReceiveMasterWeight", item.Id.Trim(), item.Plant.Trim(), item.Serialnumber.Trim(), item.Result, item.Message, EnumMsgState.Success, item.Id.Trim() + ";" + item.Id.Trim() + ";" + def.DBName); SQL.UpdateSAPMasterWeightStatus(def.ConnectionStr, def.DBName, item.Id.Trim(), "OK"); } else { //IdFailList.Add(dataId); SQL.InsertTxnDataLog(EnumMsgCategory.Receive, "ReceiveMasterWeight", item.Id.Trim(), item.Plant.Trim(), item.Serialnumber.Trim(), item.Result, item.Message, IMES.Service.Common.EnumMsgState.Fail, item.Id.Trim() + ";" + item.Id.Trim() + ";" + def.DBName); SQL.UpdateSAPMasterWeightStatus(def.ConnectionStr, def.DBName, item.Id.Trim(), "Fail"); } } //Update FISTOSAP_WEIGHT status //if (IdOKList.Count > 0) SQL.UpdateSAPMasterWeightStatus(def.ConnectionStr, def.DBName, IdOKList, "OK"); //if (IdFailList.Count > 0) SQL.UpdateSAPMasterWeightStatus(def.ConnectionStr, def.DBName, IdFailList, "Fail"); } catch (Exception e) { BaseLog.LoggingError(logger, MethodBase.GetCurrentMethod(), e); } finally { BaseLog.LoggingEnd(logger, methodName); } }