using System; using System.Collections.Generic; using System.Text; using System.Data; using System.IO; namespace EDI { public class clsEnvelop { public clsZOCT_EnvelopR omodel = new clsZOCT_EnvelopR(); public List DetailColl = new List(); public List DetailColl830 = new List(); SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); public string DateIsNull(string s) { if (s == "" || s.Trim().Length == 0) { return " null "; } else { return "'" + s + "'"; } } public string IntIsNull(Int64 s) { if (s == 0 ) { return " null "; } else { return s.ToString(); } } //ÐÂÔö 862 public bool AddBill(ref string sReturn, ref Int64 sBackID, string sPath, string HTo862Path, string sFileName) { try { // oCn.BeginTran(); //Ö÷±í DataSet ds= oCn.RunProcReturn("Insert Into ZOCT_EnvelopR " + "(EnvelopRCompleted,EnvelopRFile,MessageTypeCode,MessageType" + ",SenderIDTitle,SenderID,ReceiverIDTitle,ReceiverID" + ") " + " values(" + DBUtility.ClsPub.BoolToString(omodel.EnvelopRCompleted) + ",'" + omodel.EnvelopRFile + "','" + omodel.MessageTypeCode + "','" + omodel.MessageType + "'" + ",'" + omodel.SenderIDTitle + "','" + omodel.SenderID + "','" + omodel.ReceiverIDTitle + "','" + omodel.ReceiverID + "'" + ") select sid=@@IDENTITY", "ZOCT_EnvelopR"); // if (ds == null || ds.Tables[0].Rows.Count == 0) { sReturn = "дÈëÖ÷±íʧ°Ü£¡"; oCn.RollBack(); return false; } Int64 IEnvelopRID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0][0]); if (IEnvelopRID <= 0) { sReturn = "дÈëÖ÷±íʧ°Ü2£¡"; oCn.RollBack(); return false; } //²åÈë×Ó±í foreach (clsZOCT_Detail862 oSub in DetailColl) { oCn.RunProc("Insert into ZOCT_Detail862 " + " (EnvelopRID,GenerateID,InterchangeControlNum,MessageReleaseNum" + ",MessageReleaseDate,MessagePurpose,ScheduleType" + ",HorizonStartDate,HorizonEndDate,MessageReferenceNum,ShipToGSDBCode,ShipFromGSDBCode,IntermediateConsignee,PartNum" + ",PurchaseOrderNum,DockCode,LineFeed," + "ReserveLineFeed,ContactName,ContactTelephone,LastReceivedASNNum," + "LastShippedQTY,LastShippedDate,CumShippedQTY,CumStartDate" + ",CumEndDate,ForecastCumQTY,ForecastNetQTY" + ",UOM,ForecastStatus,ForecastDate,ForecastTime" + ") values(" + IEnvelopRID.ToString() + ",null,'" + oSub.InterchangeControlNum + "','" + oSub.MessageReleaseNum + "'" + "," + DateIsNull(oSub.MessageReleaseDate) + ",'" + oSub.MessagePurpose + "','" + oSub.ScheduleType + "'," + DateIsNull(oSub.HorizonStartDate) + "," + DateIsNull(oSub.HorizonEndDate) + ",'" + oSub.MessageReferenceNum + "','" + oSub.ShipToGSDBCode + "','" + oSub.ShipFromGSDBCode + "','" + oSub.IntermediateConsignee + "','" + oSub.PartNum + "','" + oSub.PurchaseOrderNum + "','" + oSub.DockCode + "','" + oSub.LineFeed + "'" + ",'" + oSub.ReserveLineFeed + "','" + oSub.ContactName + "','" + oSub.ContactTelephone + "','" + oSub.LastReceivedASNNum + "'" + "," + oSub.LastShippedQTY.ToString() + "," + DateIsNull(oSub.LastShippedDate) + "," + oSub.CumShippedQTY.ToString() + "," + DateIsNull(oSub.CumStartDate) + "," + DateIsNull(oSub.CumEndDate) + "," + oSub.ForecastCumQTY.ToString() + "," + oSub.ForecastNetQTY.ToString() + "" + ",'" + oSub.UOM.ToString() + "','" + oSub.ForecastStatus.ToString() + "'," + DateIsNull(oSub.ForecastDate) + "," + IntIsNull(oSub.ForecastTime) + ") "); } // sReturn = "ÐÂÔöµ¥¾Ý³É¹¦£¡"; //ÒÆ¶¯Îļþ if (MoveFile(sPath, HTo862Path + sFileName, ref DBUtility.ClsPub.sExeReturnInfo) == false) { oCn.RollBack(); DBUtility.ClsPub.Add_Log("¸ù¾Ý·¾¶½«CSVдÈë862±íʧ°Ü,ÒÆ¶¯Îļþʧ°Ü!" + DBUtility.ClsPub.sExeReturnInfo, "·¾¶ToTable", "Sysytem"); return false; } // // oCn.Commit(); sBackID = IEnvelopRID; return true; } catch (Exception e) { sReturn = e.Message; oCn.RollBack(); return false; } } public bool MoveFile(string oldFile, string NewFile, ref string sReturn) { try { File.Move(oldFile, NewFile); return true; } catch (Exception e) { sReturn = e.Message; return false; } } //ÐÂÔö 830 public bool AddBill830(ref string sReturn, ref Int64 sBackID, string sPath, string HTo830Path, string sFileName) { try { // oCn.BeginTran(); //Ö÷±í DataSet ds = oCn.RunProcReturn("Insert Into ZOCT_EnvelopR " + "(EnvelopRCompleted,EnvelopRFile,MessageTypeCode,MessageType" + ",SenderIDTitle,SenderID,ReceiverIDTitle,ReceiverID" + ") " + " values(" + DBUtility.ClsPub.BoolToString(omodel.EnvelopRCompleted) + ",'" + omodel.EnvelopRFile + "','" + omodel.MessageTypeCode + "','" + omodel.MessageType + "'" + ",'" + omodel.SenderIDTitle + "','" + omodel.SenderID + "','" + omodel.ReceiverIDTitle + "','" + omodel.ReceiverID + "'" + ") select sid=@@IDENTITY", "ZOCT_EnvelopR"); // if (ds == null || ds.Tables[0].Rows.Count == 0) { sReturn = "дÈëÖ÷±íʧ°Ü£¡"; oCn.RollBack(); return false; } Int64 IEnvelopRID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0][0]); if (IEnvelopRID <= 0) { sReturn = "дÈëÖ÷±íʧ°Ü2£¡"; oCn.RollBack(); return false; } //²åÈë×Ó±í foreach (clsEDI_DESADV oSub in DetailColl830) { //oCn.RunProc("Insert into ZOCT_Detail830 " + // " (EnvelopRID,GenerateID,InterchangeControlNum,MessageReleaseNum" + // ",MessageReleaseDate,MessagePurpose,ScheduleType,HorizonStartDate" + // ",HorizonEndDate,CommentNote,ShipToGSDBCode,ShipFromGSDBCode" + // ",IntermediateConsignee,PartNum,PurchaseOrderNum,PartReleaseStatus" + // ",DockCode,LineFeed,ReserveLineFeed,ContactName" + // ",ContactTelephone,FabAuthQty,FabAuthStartDate,FabAuthEndDate" + // ",MatAuthQty,MatAuthStartDate,MatAuthEndDate,LastReceivedASNNum" + // ",LastShippedQty,LastShippedDate,CumShippedQty,CumStartDate" + // ",CumEndDate,ForecastCumQty,ForecastNetQty" + // ",UOM,ForecastStatus,ForecastDate" + // ",FlexibleForcastStartDate,FlexibleForcastEndDate,ForecastDateQualr" + // ") values(" // + IEnvelopRID.ToString() + ",null,'" + oSub.InterchangeControlNum + "','" + oSub.MessageReleaseNum + "'" + // "," + DateIsNull(oSub.MessageReleaseDate) + ",'" + oSub.MessagePurpose + "','" + oSub.ScheduleType + "'," + DateIsNull(oSub.HorizonStartDate) + // "," + DateIsNull(oSub.HorizonEndDate) + ",'" + oSub.CommentNote + "','" + oSub.ShipToGSDBCode + "','" + oSub.ShipFromGSDBCode + "'" + // ",'" + oSub.IntermediateConsignee + "','" + oSub.PartNum + "','" + oSub.PurchaseOrderNum + "','" + oSub.PartReleaseStatus + "'" + // ",'" + oSub.DockCode + "','" + oSub.LineFeed + "','" + oSub.ReserveLineFeed + "','" + oSub.ContactName + "'" + // ",'" + oSub.ContactTelephone + "'," + oSub.FabAuthQty.ToString() + "," + DateIsNull(oSub.FabAuthStartDate) + "," + DateIsNull(oSub.FabAuthEndDate) + // "," + oSub.MatAuthQty.ToString() + "," + DateIsNull(oSub.MatAuthStartDate) + "," + DateIsNull(oSub.MatAuthEndDate) + ",'" + oSub.LastReceivedASNNum + "'" + // "," + oSub.LastShippedQty.ToString() + "," + DateIsNull(oSub.LastShippedDate) + "," + oSub.CumShippedQty.ToString() + "," + DateIsNull(oSub.CumStartDate) + // "," + DateIsNull(oSub.CumEndDate) + "," + oSub.ForecastCumQty.ToString() + "," + oSub.ForecastNetQty.ToString() + // ",'" + oSub.UOM + "','" + oSub.ForecastStatus + "'," + DateIsNull(oSub.ForecastDate) + // "," + DateIsNull(oSub.FlexibleForcastStartDate) + "," + DateIsNull(oSub.FlexibleForcastEndDate) + ",'" + oSub.ForecastDateQualr + "'" + // ") "); } // sReturn = "ÐÂÔöµ¥¾Ý³É¹¦£¡"; //ÒÆ¶¯Îļþ if (MoveFile(sPath, HTo830Path + sFileName, ref DBUtility.ClsPub.sExeReturnInfo) == false) { oCn.RollBack(); DBUtility.ClsPub.Add_Log("¸ù¾Ý·¾¶½«CSVдÈë830±íʧ°Ü,ÒÆ¶¯Îļþʧ°Ü!" + DBUtility.ClsPub.sExeReturnInfo, "·¾¶ToTable", "Sysytem"); return false; } // oCn.Commit(); sBackID = IEnvelopRID; return true; } catch (Exception e) { sReturn = e.Message; oCn.RollBack(); return false; } } } }