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
{
///
/// 862
///
public partial class FrmReceive : Form
{
public FrmReceive()
{
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.DetailColl = new List();
}
if (n >= 3)//表头
{
clsZOCT_Detail862 oSub = new clsZOCT_Detail862();
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.MessageReferenceNum = 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.DockCode = oAL[13].ToString();
oSub.LineFeed = oAL[14].ToString();
oSub.ReserveLineFeed = oAL[15].ToString();
oSub.ContactName = oAL[16].ToString();
oSub.ContactTelephone = oAL[17].ToString();
oSub.LastReceivedASNNum = oAL[18].ToString();
oSub.LastShippedQTY = DBUtility.ClsPub.isDoule(oAL[19].ToString());
oSub.LastShippedDate = DateFormatToString(oAL[20].ToString());
oSub.CumShippedQTY = DBUtility.ClsPub.isDoule(oAL[21].ToString());
oSub.CumStartDate = DateFormatToString(oAL[22].ToString());
oSub.CumEndDate = DateFormatToString(oAL[23].ToString());
oSub.ForecastCumQTY = DBUtility.ClsPub.isDoule(oAL[24].ToString());
oSub.ForecastNetQTY = DBUtility.ClsPub.isDoule(oAL[25].ToString());
oSub.UOM = oAL[26].ToString();
oSub.ForecastStatus = oAL[27].ToString();
oSub.ForecastDate = DateFormatToString(oAL[28].ToString());
oSub.ForecastTime = DBUtility.ClsPub.isLong(oAL[29].ToString());
BillNew.DetailColl.Add(oSub);
}
}
//
Int64 sInterID = 0;
if (BillNew.AddBill(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 FrmReceive_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");
}
}
}