private void ReadFileData2() { try { string fileName = txtFileName.InnerTextBox.Text.Trim(); string configFile = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "DataFileParser.xml"); BenQGuru.eMES.Material.DataFileParser parser = new BenQGuru.eMES.Material.DataFileParser(); parser.FormatName = "INVSHIP"; parser.ConfigFile = configFile; parser.CheckValidHandle = null; try { object[] objs = parser.Parse(fileName); if (objs != null && objs.Length > 0) { foreach (object obj in objs) { InvShip ship = obj as InvShip; if (ship != null) { this._tmpTable.Rows.Add(new string[] { ship.ShipNo.ToUpper(), ship.ShipSeq.ToString(), ship.ShipType, ship.PartnerCode.ToUpper(), ship.PartnerDesc, ship.CustomerOrderNo, ship.ShipMethod, FormatHelper.ToDateString(ship.ShipDate), ship.ItemCode.ToUpper(), ship.PlanQty.ToString(), FormatHelper.ToDateString(ship.PrintDate) }); } } } } finally { parser.CloseFile(); } } catch (System.IO.IOException ex) { this.ErrorMsg("$Error_FileReadError " + ex.Message); return; } }
// private void ReadFileData() // { // System.IO.FileStream fs = null; // System.IO.StreamReader sr = null; // try // { // this.Cursor = System.Windows.Forms.Cursors.WaitCursor; // // ClearDataRow(); // // fs = new System.IO.FileStream(txtFileName.InnerTextBox.Text.Trim(), // System.IO.FileMode.Open,System.IO.FileAccess.Read); // // sr = new System.IO.StreamReader(fs,System.Text.Encoding.Default); // // string line = sr.ReadLine(); // while(line != null && line != string.Empty) // { // string[] arr = line.Split(','); // if(arr.Length != 9) // { // this.ErrorMsg("文件中内容格式错误"); // return; // } // // arr[4] = DateStringConv(arr[4]); // arr[8] = DateStringConv(arr[8]); // // this._tmpTable.Rows.Add(arr); // line = sr.ReadLine(); // } // this.SucessMsg("文件读取结束"); // } // catch(System.IO.IOException ex) // { // this.ErrorMsg("读取文件出错 "+ex.Message); // return; // } // finally // { // if(sr != null) // sr.Close(); // if(fs != null) // fs.Close(); // // this.Cursor = System.Windows.Forms.Cursors.Default; // } // } // private string DateStringConv(string datefrom) // { // string[] strList = datefrom.Split(new char[]{'.','-','/'}); // if(strList.Length != 3) // throw new Exception("日期格式错误"); // // return strList[0] + "-" + strList[1] + "-" + strList[2]; // } #endregion #endregion #region 将出货单写到数据库中 private void btnSave_Click(object sender, System.EventArgs e) { try { this.Cursor = System.Windows.Forms.Cursors.WaitCursor; this.DataProvider.BeginTransaction(); BenQGuru.eMES.Material.InventoryFacade facade = new InventoryFacade(this.DataProvider); BenQGuru.eMES.MOModel.ItemFacade itemFacade = new ItemFacade(this.DataProvider); BenQGuru.eMES.MOModel.ModelFacade modelFacade = new ModelFacade(this.DataProvider); //一行行的写入 foreach (DataRow dr in this._tmpTable.Rows) { //判断是否已经做过采集 string shipNo = dr[0].ToString().ToUpper(); int shipSeq = int.Parse(dr[1].ToString()); string itemcode = dr["ItemCode"].ToString().ToUpper(); string partnercode = dr["PartnerCode"].ToString().ToUpper(); //判断此出货单是否存在(根据单号,产品代码,经销商代码) object[] objs = facade.QueryInvShip(shipNo, itemcode, partnercode); if (objs != null && objs.Length > 0) { InvShip shipt = objs[0] as InvShip; if (shipt != null) { if (shipt.ShipStatus == ShipStatus.Shipped) { throw new Exception(shipNo + " $CS_Inv_Ship_has_Shiped"); //已经完成出货了,不能重新导入 } if (shipt.ActQty > 0) { throw new Exception(shipNo + " $CS_Inv_Ship_has_Collected"); //已经做过出货采集,请先将采集的序列号删除 } facade.DeleteInvShip(shipNo, itemcode, partnercode); } } //int count = this.DataProvider.GetCount(new SQLCondition(string.Format("select count(*) from TBLINVRCARD where 1=1 and shipNo ='{0}' and shipSeq={1}" , shipNo,shipSeq))); //if(count > 0) // throw new Exception(shipNo + "这个出货单已经做过出货采集,不能重新导入"); //判断此出货单是否存在 //count = this.DataProvider.GetCount(new SQLCondition(string.Format("select count(*) from TBLINVSHIP where 1=1 and shipNo = '{0}' " , shipNo))); //if(count > 0) //{ // this.DataProvider.CustomExecute(new SQLCondition(string.Format("delete from tblinvship where shipNo='{0}'",shipNo))); //} //将这行数据写入到数据库 InvShip ship = facade.CreateNewInvShip(); ship.ActQty = 0; ship.ItemCode = dr[8].ToString(); BenQGuru.eMES.Domain.MOModel.Item item = itemFacade.GetItem(ship.ItemCode, GlobalVariables.CurrentOrganizations.First().OrganizationID) as BenQGuru.eMES.Domain.MOModel.Item; if (item != null) { ship.ItemDesc = item.ItemDescription; BenQGuru.eMES.Domain.MOModel.Model model = modelFacade.GetModelByItemCode(item.ItemCode) as BenQGuru.eMES.Domain.MOModel.Model; if (model != null) { ship.ModelCode = model.ModelCode; } else { ship.ModelCode = " "; } } else { ship.ItemDesc = string.Empty; } ship.MainitainUser = ApplicationService.Current().UserCode; //Laws Lu,2006/11/13 uniform system collect date DBDateTime dbDateTime; dbDateTime = FormatHelper.GetNowDBDateTime(DataProvider); ship.MaintainDate = dbDateTime.DBDate; ship.MaintainTime = dbDateTime.DBTime; ship.PartnerCode = dr[3].ToString().ToUpper(); ship.PartnerDesc = dr[4].ToString(); ship.PlanQty = int.Parse(dr[9].ToString()); ship.ShipDate = FormatHelper.TODateInt(dr[7].ToString()); ship.ShipNo = dr[0].ToString().ToUpper(); ship.ShipStatus = ShipStatus.Shipping; ship.ShipDesc = string.Empty; ship.ShipInnerType = BenQGuru.eMES.Material.ReceiveInnerType.Normal; ship.ShipType = dr[2].ToString(); ship.ShipUser = string.Empty; ship.PrintDate = FormatHelper.TODateInt(dr[10].ToString()); ship.ShipSeq = shipSeq; ship.CustomerOrderNo = dr[5].ToString().ToUpper(); ship.ShipMethod = dr[6].ToString().ToUpper(); facade.AddInvShip2(ship); } this.DataProvider.CommitTransaction(); this.SucessMsg("$CS_Save_Success"); } catch (System.Exception ex) { this.DataProvider.RollbackTransaction(); this.ErrorMsg(ex.Message); } finally { this.Cursor = System.Windows.Forms.Cursors.Default; } }