public FrmQuery_FastIn(string ID) { InitializeComponent(); ROWNO.DataPropertyName = "RowNo"; PLANT_NAME.DataPropertyName = "PlantName"; STORE_LOC.DataPropertyName = "StorageLoc"; txt_VOUCHERNO.Enabled = false; txt_sapdoc.Enabled = false; txt_taskno.Enabled = false; txt_time.Enabled = false; txt_poe.Enabled = false; txt_poe.Text = Common.Common_Var.CurrentUser.UserName; txt_business.Focus(); txt_time.Value = DateTime.Now; WebService.Task_Model head = new WebService.Task_Model(); head.ID = Convert.ToInt32(ID); List <WebService.TaskDetails_Model> body = new List <WebService.TaskDetails_Model>(); string newTaskNo = string.Empty; string ErrMsg = string.Empty; //获取TASK表头和表体 WebService.Task_Model sourceTask = null; WebService.TaskVoucher sourceVoucher = null; bool bSucc = WMS.Common.WMSWebService.service.GetFastInByID(ID, ref sourceTask, ref sourceVoucher, ref ErrMsg); if (!bSucc) { MessageBox.Show("加载数据失败" + ErrMsg); return; } txt_sapdoc.Text = sourceTask.MaterialDoc; txt_taskno.Text = sourceTask.TaskNo; txt_time.Value = sourceTask.CreateDateTime; txt_businessName.Text = sourceTask.SupCusName; txt_business.Text = sourceTask.SupCusNo; txt_reason.Text = sourceTask.Reason; txt_remark.Text = sourceTask.Remark; txt_poe.Text = sourceTask.CreateUserNo; if (sourceVoucher != null) { txt_VOUCHERNO.Text = sourceVoucher.VoucherNo; chensCheckBox1.Checked = true; } else { if (sourceTask.ShelvePost.Equals("过账")) { chensCheckBox1.Checked = true; txt_VOUCHERNO.Enabled = true; } } head = sourceTask; if (sourceVoucher != null && sourceVoucher.body != null && sourceVoucher.body.Count == sourceTask.lstTaskDetails.Count) { for (int i = 0; i < sourceTask.lstTaskDetails.Count; i++) { sourceTask.lstTaskDetails[i].RowNo = sourceVoucher.body[i].RowNo; sourceTask.lstTaskDetails[i].PlantName = sourceVoucher.body[i].Factory; sourceTask.lstTaskDetails[i].StorageLoc = sourceVoucher.body[i].Store; } cmb_store.Items.Add(sourceVoucher.body[0].Store); cmb_store.SelectedItem = sourceVoucher.body[0].Store; } body = sourceTask.lstTaskDetails; bindingSource1.DataSource = body; bindingSource1.ResetBindings(true); this.Refresh(); }
private void txt_VOUCHERNO_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (bhaveVoucher && sourceVoucher != null) { MessageBox.Show("只能加载一张单据表单!"); return; } //判断单据号是否在其它TASK表上 WebService.TaskVoucher temptv = null; string strErrMsg = string.Empty; bool bSucc = WMS.Common.WMSWebService.service.GetVoucherByNo(txt_VOUCHERNO.Text, ref temptv, ref strErrMsg); if (bSucc) { MessageBox.Show("该单号已用在其它任务单上!"); txt_VOUCHERNO.SelectAll(); txt_VOUCHERNO.Focus(); return; } //获取采购订单 WebService.DeliveryReceive_Model tempDM = new WebService.DeliveryReceive_Model(); //bSucc = JingXinWMS.Common.WMSWebService.service.GetPOInfoForSAP(txt_VOUCHERNO.Text, ref tempDM, ref strErrMsg); //if(!bSucc) //{ // MessageBox.Show("单据号错误!"); // txt_VOUCHERNO.SelectAll(); // txt_VOUCHERNO.Focus(); // return; //} //匹配表体数据 if (body != null && body.Count == tempDM.lstDeliveryDetail.Count) { //如果是新建TASK,则自动生成Voucher表头和表体 if (bNewTask) { bhaveVoucher = true; head.VoucherNo = txt_VOUCHERNO.Text; head.SupCusNo = tempDM.SupCode; head.SupCusName = tempDM.SupName; txt_businessName.Text = head.SupCusName; txt_business.Text = head.SupCusNo.TrimStart('0'); sourceVoucher = new WebService.TaskVoucher(); sourceVoucher.VoucherNo = txt_VOUCHERNO.Text; sourceVoucher.body = new List <WebService.TaskVoucherDetails>(); foreach (WebService.DeliveryReceiveDetail_Model drdm in tempDM.lstDeliveryDetail) { //匹配body的物料号和数量 WebService.TaskDetails_Model tdm = body.Find(delegate(WebService.TaskDetails_Model v) { return(v.MaterialNo == drdm.MaterialNo && v.TaskQty == drdm.CurrentlyDeliveryNum); }); if (tdm == null) { MessageBox.Show("该任务的表单物料明细与单据表体不匹配!"); txt_VOUCHERNO.SelectAll(); txt_VOUCHERNO.Focus(); return; } tdm.RowNo = drdm.RowNo; tdm.PlantName = drdm.PlantName; tdm.StorageLoc = drdm.StorageLoc; WebService.TaskVoucherDetails tvd = new WebService.TaskVoucherDetails(); tvd.MaterialNo = drdm.MaterialNo; tvd.MaterialDesc = drdm.MaterialDesc; tvd.Factory = drdm.Plant; tvd.FactoryName = drdm.PlantName; tvd.Store = drdm.StorageLoc; tvd.Qty = drdm.CurrentlyDeliveryNum; tvd.RowNo = drdm.RowNo; sourceVoucher.body.Add(tvd); } bindingSource1.DataSource = body; bindingSource1.ResetBindings(true); this.Refresh(); if (sourceVoucher.body[0].Store == null || sourceVoucher.body[0].Store.Equals("")) { //List<WebService.StorageLoc_Model> lstStorage = null; //bSucc = JingXinWMS.Common.WMSWebService.service.GetStorageLocByPlantForSAP(sourceVoucher.body[0].Factory, ref lstStorage, ref strErrMsg); //if (bSucc) //{ // WebService.StorageLoc_Model NullStorage = new WebService.StorageLoc_Model(); // NullStorage.StorageLoc = ""; // lstStorage.Insert(0, NullStorage); // cmb_store.DataSource = lstStorage; // cmb_store.DisplayMember = "StorageLoc"; // cmb_store.ValueMember = "StorageLoc"; // //MessageBox.Show("请选择库存地点"); //} //else //{ // MessageBox.Show("获取库存地点列表失败!"); // return; //} //cmb_store.Items.Add("1101"); //MessageBox.Show("请选择库存地点"); } } else//否则通过SAP数据匹配已有的表体数据(原有临时物料匹配SAP物料) { if (sourceTask.lstTaskDetails.Count != tempDM.lstDeliveryDetail.Count) { MessageBox.Show("该任务的表单明细行数与单据表体行数不匹配!"); txt_VOUCHERNO.SelectAll(); txt_VOUCHERNO.Focus(); return; } if (!sourceTask.SupCusNo.TrimStart('0').Equals(txt_business.Text.TrimStart('0'))) { MessageBox.Show("PO供应商错误,重新检查PO单号"); txt_VOUCHERNO.SelectAll(); txt_VOUCHERNO.Focus(); return; } foreach (WebService.TaskDetails_Model tdm in sourceTask.lstTaskDetails) { int index = tempDM.lstDeliveryDetail.FindIndex(delegate(WebService.DeliveryReceiveDetail_Model v) { return(v.MaterialNo.Equals(tdm.MaterialNo) && v.CurrentlyDeliveryNum == tdm.TaskQty); }); if (index < 0) { WebService.TempMaterial tempmaterial = null; bSucc = WMS.Common.WMSWebService.service.GetTempMaterialByTempNo(tdm.TMaterialNo, ref tempmaterial, ref strErrMsg); if (bSucc) { index = tempDM.lstDeliveryDetail.FindIndex(delegate(WebService.DeliveryReceiveDetail_Model v) { return(v.MaterialNo.Equals(tempmaterial.MaterialNo) && v.CurrentlyDeliveryNum == tdm.TaskQty); }); if (index < 0) { MessageBox.Show("该任务的表单物料明细与单据表体不匹配!"); txt_VOUCHERNO.SelectAll(); txt_VOUCHERNO.Focus(); return; } tdm.MaterialNo = tempDM.lstDeliveryDetail[index].MaterialNo; tdm.MaterialDesc = tempDM.lstDeliveryDetail[index].MaterialDesc; tdm.TMaterialNo = tempmaterial.TempMaterialNo; tdm.TMaterialDesc = tempmaterial.TempMaterialDesc; tdm.TaskQty = tempDM.lstDeliveryDetail[index].CurrentlyDeliveryNum; tdm.RowNo = tempDM.lstDeliveryDetail[index].RowNo; tdm.Plant = tempDM.lstDeliveryDetail[index].Plant; tdm.PlantName = tempDM.lstDeliveryDetail[index].PlantName; tdm.StorageLoc = tempDM.lstDeliveryDetail[index].StorageLoc; } else { MessageBox.Show("获取临时物料对应关系失败!"); txt_VOUCHERNO.SelectAll(); txt_VOUCHERNO.Focus(); return; } } else { tdm.MaterialNo = tempDM.lstDeliveryDetail[index].MaterialNo; tdm.MaterialDesc = tempDM.lstDeliveryDetail[index].MaterialDesc; tdm.TaskQty = tempDM.lstDeliveryDetail[index].CurrentlyDeliveryNum; tdm.RowNo = tempDM.lstDeliveryDetail[index].RowNo; tdm.Plant = tempDM.lstDeliveryDetail[index].Plant; tdm.PlantName = tempDM.lstDeliveryDetail[index].PlantName; tdm.StorageLoc = tempDM.lstDeliveryDetail[index].StorageLoc; } } bhaveVoucher = true; head.SupCusNo = tempDM.SupCode; head.SupCusName = tempDM.SupName; txt_businessName.Text = head.SupCusName; txt_business.Text = head.SupCusNo.TrimStart('0'); sourceVoucher = new WebService.TaskVoucher(); sourceVoucher.VoucherNo = txt_VOUCHERNO.Text; sourceVoucher.body = new List <WebService.TaskVoucherDetails>(); foreach (WebService.DeliveryReceiveDetail_Model drdm in tempDM.lstDeliveryDetail) { WebService.TaskVoucherDetails tvd = new WebService.TaskVoucherDetails(); tvd.MaterialNo = drdm.MaterialNo; tvd.MaterialDesc = drdm.MaterialDesc; tvd.Factory = drdm.Plant; tvd.FactoryName = drdm.PlantName; tvd.Store = drdm.StorageLoc; tvd.Qty = drdm.CurrentlyDeliveryNum; tvd.RowNo = drdm.RowNo; sourceVoucher.body.Add(tvd); } body = sourceTask.lstTaskDetails; bindingSource1.DataSource = body; bindingSource1.ResetBindings(true); this.Refresh(); if (sourceVoucher.body[0].Store == null || sourceVoucher.body[0].Store.Equals("")) { //List<WebService.StorageLoc_Model> lstStorage = null; //bSucc = JingXinWMS.Common.WMSWebService.service.GetStorageLocByPlantForSAP(sourceVoucher.body[0].Factory, ref lstStorage, ref strErrMsg); //if (bSucc) //{ // WebService.StorageLoc_Model NullStorage = new WebService.StorageLoc_Model(); // NullStorage.StorageLoc = ""; // lstStorage.Insert(0, NullStorage); // cmb_store.DataSource = lstStorage; // cmb_store.DisplayMember = "StorageLoc"; // cmb_store.ValueMember = "StorageLoc"; // //MessageBox.Show("请选择库存地点"); //} //else //{ // MessageBox.Show("获取库存地点列表失败!"); // return; //} //cmb_store.Items.Add("1101"); //MessageBox.Show("请选择库存地点"); } else { cmb_store.Items.Add(sourceVoucher.body[0].Store); cmb_store.SelectedItem = sourceVoucher.body[0].Store; } } } else { MessageBox.Show("单据表单数据匹配错误!"); txt_VOUCHERNO.SelectAll(); txt_VOUCHERNO.Focus(); return; } } }