예제 #1
0
        protected void cmdAdd_ServerClick(object sender, EventArgs e)
        {
            if (_WarehouseFacade == null)
            {
                _WarehouseFacade = new BenQGuru.eMES.Material.WarehouseFacade(base.DataProvider);
            }
            if (string.IsNullOrEmpty(txtStockCheckEdit.Text))
            {
                WebInfoPublish.Publish(this, "盘点单号不能为空!", this.languageComponent1); return;
            }
            if (string.IsNullOrEmpty(drpStorageCodeEdit.SelectedValue))
            {
                WebInfoPublish.Publish(this, "库位不能为空!", this.languageComponent1); return;
            }
            if (string.IsNullOrEmpty(drpCheckTypeEdit.SelectedValue))
            {
                WebInfoPublish.Publish(this, "盘点类型不能为空!", this.languageComponent1); return;
            }
            if (drpCheckTypeEdit.SelectedValue != "Portion")
            {
                if (!string.IsNullOrEmpty(txtBDateEdit.Text))
                {
                    WebInfoPublish.Publish(this, "盘点日期动盘时才可用!", this.languageComponent1); return;
                }
                if (!string.IsNullOrEmpty(txtEDateEdit.Text))
                {
                    WebInfoPublish.Publish(this, "盘点日期动盘时才可用!", this.languageComponent1); return;
                }
            }
            if (drpCheckTypeEdit.SelectedValue == "Portion")
            {
                if (string.IsNullOrEmpty(txtBDateEdit.Text))
                {
                    WebInfoPublish.Publish(this, "必须输入盘点日期!", this.languageComponent1); return;
                }
                if (string.IsNullOrEmpty(txtEDateEdit.Text))
                {
                    WebInfoPublish.Publish(this, "必须输入盘点日期!", this.languageComponent1); return;
                }
            }

            try
            {
                this.DataProvider.BeginTransaction();
                BenQGuru.eMES.Domain.Warehouse.StockCheck s = new BenQGuru.eMES.Domain.Warehouse.StockCheck();
                s.CheckNo     = txtStockCheckEdit.Text;
                s.CheckType   = drpCheckTypeEdit.SelectedValue;
                s.StorageCode = drpStorageCodeEdit.Text;
                s.REMARK1     = txtREMARKEdit.Text;
                s.STATUS      = "WaitCheck";
                s.FACCODE     = " ";
                s.SDATE       = FormatHelper.TODateInt(txtBDateEdit.Text);
                s.EDATE       = FormatHelper.TODateInt(txtEDateEdit.Text);
                s.MDATE       = FormatHelper.TODateInt(DateTime.Now);
                s.MTIME       = FormatHelper.TOTimeInt(DateTime.Now);
                s.MUSER       = GetUserCode();
                s.CDATE       = FormatHelper.TODateInt(DateTime.Now);
                s.CTIME       = FormatHelper.TOTimeInt(DateTime.Now);
                s.CUSER       = GetUserCode();
                _WarehouseFacade.AddStockCheck(s);

                BenQGuru.eMES.Material.Do[] ds;
                bool isPortion = false;
                if (drpCheckTypeEdit.SelectedValue == "Portion")
                {
                    ds        = _WarehouseFacade.GetPortionStorageQty(drpStorageCodeEdit.Text, s.SDATE, s.EDATE);
                    isPortion = true;
                }
                else
                {
                    ds = _WarehouseFacade.GetStorageQTY123(drpStorageCodeEdit.Text);
                }
                foreach (BenQGuru.eMES.Material.Do d in ds)
                {
                    BenQGuru.eMES.Domain.Warehouse.StockCheckDetail ss = new BenQGuru.eMES.Domain.Warehouse.StockCheckDetail();
                    ss.CheckNo     = txtStockCheckEdit.Text;
                    ss.StorageCode = drpStorageCodeEdit.SelectedValue;
                    ss.DQMCODE     = d.DQMCODE;

                    BenQGuru.eMES.Domain.MOModel.Material m = _WarehouseFacade.GetMaterialFromDQMCode(d.DQMCODE);
                    if (m == null)
                    {
                        throw new Exception(d.DQMCODE + "物料在物料表中不存在!");
                    }
                    ss.MDESC = m.MchshortDesc;
                    ss.UNIT  = m.Muom;

                    ss.STORAGEQTY   = d.sum;
                    ss.LocationCode = " ";
                    ss.CARTONNO     = string.IsNullOrEmpty(d.CARTONNO) ? " " : d.CARTONNO;
                    if (isPortion)
                    {
                        ss.LocationCode = d.LOCATIONCODE;
                        //StorageDetail storageDetail = (StorageDetail)_WarehouseFacade.GetStorageDetail(ss.CARTONNO);
                        //if (storageDetail != null)
                        //{
                        //    ss.LocationCode = storageDetail.LocationCode;
                        //}
                    }
                    ss.MDATE = FormatHelper.TODateInt(DateTime.Now);
                    ss.MTIME = FormatHelper.TOTimeInt(DateTime.Now);
                    ss.MUSER = GetUserCode();
                    ss.CDATE = FormatHelper.TODateInt(DateTime.Now);
                    ss.CTIME = FormatHelper.TOTimeInt(DateTime.Now);
                    ss.CUSER = GetUserCode();
                    _WarehouseFacade.AddStockCheckDetails(ss);
                }
                this.DataProvider.CommitTransaction();
            }
            catch (Exception ex)
            {
                this.DataProvider.RollbackTransaction();
                throw ex;
            }



            WebInfoPublish.Publish(this, "添加成功!", this.languageComponent1); return;
        }