using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Collections; using System.IO; namespace EDI { public partial class FrmReceive830 : Form { public FrmReceive830() { InitializeComponent(); } string HToPath = @"E:\浙江长华\CSV格式\830\"; string HFromPath = @"E:\浙江长华\CSV格式\862\"; string HPath; string HFileName; public clsEnvelop BillNew = new clsEnvelop(); //选择文件路径 private void AddRow_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = "E:\\"; openFileDialog.Filter = "CSV文件|*.csv"; openFileDialog.RestoreDirectory = true; openFileDialog.FilterIndex = 1; if (openFileDialog.ShowDialog() == DialogResult.OK) { txtHPath.Text = openFileDialog.FileName; txtHPathName.Text = openFileDialog.SafeFileName; //label3.Text = openFileDialog.FileName.Substring(openFileDialog.FileName.LastIndexOf("\\") + 1); } else { txtHPath.Text = ""; txtHPathName.Text = ""; } } public string DateFormatToString(string s) { if (s.Trim() == "") { return ""; } try { DateTime d = DateTime.ParseExact(s, "yyyyMMdd", null, System.Globalization.DateTimeStyles.AllowWhiteSpaces); ; return d.ToShortDateString(); } catch (Exception e) { return ""; } } private void xz_Click(object sender, EventArgs e) { if (DBUtility.ClsPub.isStrNull(txtHPath.Text) == "" || DBUtility.ClsPub.isStrNull(txtHPathName.Text) == "") { MessageBox.Show("路径不能为空!"); return; } int n = 0; CsvStreamReader o = new CsvStreamReader(txtHPath.Text); clsEnvelop oEnvelop = new clsEnvelop(); foreach (ArrayList oAL in o.rowAL) { n = n + 1; if (n == 1)//表头 { //oZOCT_EnvelopR.EnvelopRID = oAL[0].ToString(); //oZOCT_EnvelopR.GenerateID = oAL[0].ToString(); //oZOCT_EnvelopR.EnvelopRCompleted = oAL[0].ToString(); BillNew.omodel.EnvelopRFile = txtHPath.Text; BillNew.omodel.MessageTypeCode = oAL[0].ToString(); BillNew.omodel.MessageType = oAL[1].ToString(); BillNew.omodel.SenderIDTitle = oAL[2].ToString(); BillNew.omodel.SenderID = oAL[3].ToString(); BillNew.omodel.ReceiverIDTitle = oAL[4].ToString(); BillNew.omodel.ReceiverID = oAL[5].ToString(); } if (n == 2) { BillNew.DetailColl830 = new List(); } if (n >= 3)//表头 { clsEDI_DESADV oSub = new clsEDI_DESADV(); //oSub.InterchangeControlNum = oAL[0].ToString(); //oSub.MessageReleaseNum = oAL[1].ToString(); //oSub.MessageReleaseDate = DateFormatToString(oAL[2].ToString()); //oSub.MessagePurpose = oAL[3].ToString(); //oSub.ScheduleType = oAL[4].ToString(); //oSub.HorizonStartDate = DateFormatToString(oAL[5].ToString()); //oSub.HorizonEndDate = DateFormatToString(oAL[6].ToString()); //oSub.CommentNote = oAL[7].ToString(); //oSub.ShipToGSDBCode = oAL[8].ToString(); //oSub.ShipFromGSDBCode = oAL[9].ToString(); //oSub.IntermediateConsignee = oAL[10].ToString(); //oSub.PartNum = oAL[11].ToString(); //oSub.PurchaseOrderNum = oAL[12].ToString(); //oSub.PartReleaseStatus = oAL[13].ToString(); //oSub.DockCode = oAL[14].ToString(); //oSub.LineFeed = oAL[15].ToString(); //oSub.ReserveLineFeed = oAL[16].ToString(); //oSub.ContactName = oAL[17].ToString(); //oSub.ContactTelephone = oAL[18].ToString(); //oSub.FabAuthQty = DBUtility.ClsPub.isDoule(oAL[19].ToString()); //oSub.FabAuthStartDate = DateFormatToString(oAL[20].ToString()); //oSub.FabAuthEndDate = DateFormatToString(oAL[21].ToString()); //oSub.MatAuthQty = DBUtility.ClsPub.isDoule(oAL[22].ToString()); //oSub.MatAuthStartDate = DateFormatToString(oAL[23].ToString()); //oSub.MatAuthEndDate = DateFormatToString(oAL[24].ToString()); //oSub.LastReceivedASNNum = oAL[25].ToString(); //oSub.LastShippedQty = DBUtility.ClsPub.isDoule(oAL[26].ToString()); //oSub.LastShippedDate = DateFormatToString(oAL[27].ToString()); //oSub.CumShippedQty = DBUtility.ClsPub.isDoule(oAL[28].ToString()); //oSub.CumStartDate = DateFormatToString(oAL[29].ToString()); //oSub.CumEndDate = DateFormatToString(oAL[30].ToString()); //oSub.ForecastCumQty = DBUtility.ClsPub.isDoule(oAL[31].ToString()); //oSub.ForecastNetQty = DBUtility.ClsPub.isDoule(oAL[32].ToString()); //oSub.UOM = oAL[33].ToString(); //oSub.ForecastStatus = oAL[34].ToString(); //oSub.ForecastDate = DateFormatToString(oAL[35].ToString()); //oSub.FlexibleForcastStartDate = DateFormatToString(oAL[36].ToString()); //oSub.FlexibleForcastEndDate = DateFormatToString(oAL[37].ToString()); //oSub.ForecastDateQualr = oAL[38].ToString(); BillNew.DetailColl830.Add(oSub); } } // Int64 sInterID = 0; if (BillNew.AddBill830(ref DBUtility.ClsPub.sExeReturnInfo, ref sInterID, HFromPath + txtHPathName.Text, HToPath, txtHPathName.Text)) { //移动文件 if (MoveFile(HFromPath + txtHPathName.Text, HToPath + txtHPathName.Text, ref DBUtility.ClsPub.sExeReturnInfo) == false) { MessageBox.Show("移动文件失败!" + DBUtility.ClsPub.sExeReturnInfo, "提示"); return; } // MessageBox.Show("单据存盘完毕!", "提示"); Display(sInterID); return; } } 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; } } private void tc_Click(object sender, EventArgs e) { this.Close(); } public void Display(Int64 sInterID) { SQLHelper.ClsCN SubCn = new SQLHelper.ClsCN(); DataSet DSet; DataSet DSetSub; DSet = SubCn.RunProcReturn("select * from h_v_EDI_ZOCT_EnvelopR where EnvelopRID=" + sInterID.ToString(), "h_v_EDI_ZOCT_EnvelopR", ref DBUtility.ClsPub.sExeReturnInfo); //生成首行标题 if (DSet == null) { //MessageBox.Show("没有返回任何结果,请与!" + DBUtility.ClsPub.sExeReturnInfo); grdMain.DataSource = null; return; } //绑定 grdMain.DataSource = DSet.Tables[0].DefaultView; // DSetSub = SubCn.RunProcReturn("select * from h_v_EDI_ZOCT_Detail862 where EnvelopRID=" + sInterID.ToString(), "h_v_EDI_ZOCT_Detail862", ref DBUtility.ClsPub.sExeReturnInfo); //生成首行标题 if (DSetSub == null) { //MessageBox.Show("没有返回任何结果,请与!" + DBUtility.ClsPub.sExeReturnInfo); grdSub.DataSource = null; return; } //绑定 grdSub.DataSource = DSetSub.Tables[0].DefaultView; // DBUtility.Xt_BaseBillFun.GetGrid(grdMain, this.Name); DBUtility.Xt_BaseBillFun.GetGrid(grdSub, this.Name + "grdSub"); } private void FrmReceive830_Load(object sender, EventArgs e) { DBUtility.Xt_BaseBillFun.initGridList(grdMain, this.Name); DBUtility.Xt_BaseBillFun.initGridList(grdSub, this.Name + "grdSub"); } private void bclk_Click(object sender, EventArgs e) { //保存列宽 DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name); DBUtility.Xt_BaseBillFun.SaveGrid(grdSub, this.Name + "grdSub"); } private void mrlk_Click(object sender, EventArgs e) { DBUtility.Xt_BaseBillFun.DefaultGridView(grdMain, this.Name); DBUtility.Xt_BaseBillFun.DefaultGridView(grdSub, this.Name + "grdSub"); } } }