protected override DataRow GetGridRow(object obj)
        {
            BenQGuru.eMES.Domain.Warehouse.PickDetail pick = (BenQGuru.eMES.Domain.Warehouse.PickDetail)obj;
            BenQGuru.eMES.Domain.Warehouse.Pick       s    = (BenQGuru.eMES.Domain.Warehouse.Pick)_WarehouseFacade.GetPick(pick.PickNo);

            DataRow row = this.DtSource.NewRow();

            row["PICKLINE"]        = pick.PickLine;
            row["STATUS"]          = languageComponent1.GetString(pick.Status);//dicStu.ContainsKey(pick.Status) ? dicStu[pick.Status] : string.Empty;
            row["MCODE"]           = pick.MCode;
            row["DQMCODE"]         = pick.DQMCode;
            row["MDESC"]           = pick.MDesc;
            row["CustMCode"]       = pick.VEnderItemCode;
            row["QTY"]             = pick.QTY;
            row["UNIT"]            = pick.Unit;
            row["OutCStorageCode"] = s.StorageCode;// dicStu.ContainsKey(s.StorageCode) ? dicStu[s.StorageCode] : string.Empty;
            row["SQTY"]            = pick.SQTY;
            row["OUTQTY"]          = pick.OutQTY;
            //row["Down_Time"] = FormatHelper.ToTimeString(pick.DownTime);
            row["CDATE"] = FormatHelper.ToDateString(pick.CDate);
            //row["REMARK1"] = pick.Remark1;
            row["CTIME"] = FormatHelper.ToTimeString(pick.CTime);
            row["CUSER"] = pick.CUser;
            row["MDATE"] = FormatHelper.ToDateString(pick.MaintainDate);
            row["MTIME"] = FormatHelper.ToTimeString(pick.MaintainTime);
            row["MUSER"] = pick.MaintainUser;

            //row["MUSER"] = pick.MaintainUser;
            return(row);
        }
        protected void cmdDelete_ServerClick(object sender, EventArgs e)
        {
            if (_WarehouseFacade == null)
            {
                _WarehouseFacade = new BenQGuru.eMES.Material.WarehouseFacade(base.DataProvider);
            }
            if (inventoryFacade == null)
            {
                inventoryFacade = new BenQGuru.eMES.Material.InventoryFacade(base.DataProvider);
            }
            ArrayList array = this.gridHelper.GetCheckedRows();

            if (array == null)
            {
                return;
            }
            List <BenQGuru.eMES.Domain.Warehouse.PickDetail> ll = new List <BenQGuru.eMES.Domain.Warehouse.PickDetail>();

            foreach (GridRecord row in array)
            {
                BenQGuru.eMES.Domain.Warehouse.PickDetail obj = (BenQGuru.eMES.Domain.Warehouse.PickDetail)_WarehouseFacade.GetPickdetail(txtPickNoQuery.Text, row.Items.FindItemByKey("PICKLINE").Text);

                if (obj.Status != "Release")
                {
                    WebInfoPublish.Publish(this, obj.PickNo + "状态不为初始化!", this.languageComponent1); return;
                }


                if (inventoryFacade.GetPickDetailMaterialsCount(obj.PickNo, obj.PickLine) > 0)
                {
                    WebInfoPublish.Publish(this, obj.PickNo + ":" + obj.PickLine + "正在拣料中,不能删除!", this.languageComponent1);
                    return;
                }

                ll.Add(obj);
            }

            try
            {
                this.DataProvider.BeginTransaction();

                foreach (BenQGuru.eMES.Domain.Warehouse.PickDetail p in ll)
                {
                    _WarehouseFacade.DeletePickToPo(p.PickNo, p.PickLine);  //add by sam
                    _WarehouseFacade.DeletePickdetail(p);
                }

                this.DataProvider.CommitTransaction();
            }
            catch (Exception ex)
            {
                this.DataProvider.RollbackTransaction();
                throw ex;
            }
        }
        protected override object GetEditObject()
        {
            if (_WarehouseFacade == null)
            {
                _WarehouseFacade = new BenQGuru.eMES.Material.WarehouseFacade(base.DataProvider);
            }
            BenQGuru.eMES.Domain.Warehouse.PickDetail d = (BenQGuru.eMES.Domain.Warehouse.PickDetail)_WarehouseFacade.GetPickdetail(txtPickNoQuery.Text, txtPickLineEdit.Text);

            d.DQMCode = txtDQMCodeEdit.Text;
            return(d);
        }
        protected override object GetEditObject(GridRecord row)
        {
            if (_WarehouseFacade == null)
            {
                _WarehouseFacade = new BenQGuru.eMES.Material.WarehouseFacade(base.DataProvider);
            }
            BenQGuru.eMES.Domain.Warehouse.PickDetail d = (BenQGuru.eMES.Domain.Warehouse.PickDetail)_WarehouseFacade.GetPickdetail(txtPickNoQuery.Text, row.Items.FindItemByKey("PICKLINE").Text.Trim());
            if (d != null)
            {
                return(d);
            }

            return(null);
        }
        protected override void SetEditObject(object obj)
        {
            if (obj == null)
            {
                txtPickLineEdit.Text = "";

                txtDQMCodeEdit.Text = "";
                txtDMESCEdit.Text   = "";
                txtInvLineEidt.Text = "";
                return;
            }


            BenQGuru.eMES.Domain.Warehouse.PickDetail d = (BenQGuru.eMES.Domain.Warehouse.PickDetail)obj;
            BenQGuru.eMES.Domain.MOModel.Material     m = _WarehouseFacade.GetMaterialFromDQMCode(d.DQMCode);
            txtPickLineEdit.Text = d.PickLine;
            txtDMESCEdit.Text    = m.MchlongDesc;
            txtDQMCodeEdit.Text  = d.DQMCode;

            txtInvLineEidt.Text = d.InvLine.ToString();
        }
        protected override void cmdAdd_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtWWPoSerialEdit.Text))
            {
                return;
            }
            if (_WarehouseFacade == null)
            {
                _WarehouseFacade = new BenQGuru.eMES.Material.WarehouseFacade(base.DataProvider);
            }



            BenQGuru.eMES.Domain.Warehouse.Pick p = (BenQGuru.eMES.Domain.Warehouse.Pick)_WarehouseFacade.GetPick(txtPickNoQuery.Text);


            if (p.Status != Pick_STATUS.Status_Release)
            {
                WebInfoPublish.Publish(this, p.PickNo + "拣货任务令的状态必须是初始化才能修改!", this.languageComponent1);
                return;
            }
            BenQGuru.eMES.Domain.Warehouse.PickDetail pick = new BenQGuru.eMES.Domain.Warehouse.PickDetail();

            string serialList = this.MoldidToSql(txtWWPoSerialEdit.Text);

            object[] wwpoList = _WarehouseFacade.QuerySelectedWWpoInvNo(serialList);


            #region 注释
            //pick.PickNo = txtPickNoEdit.Text;
            //pick.PickType = drpPickTypeEdit.SelectedValue;
            //pick.InvNo = txtInvNoEdit.Text;
            //pick.StorageCode = drpStorageCodeEdit.SelectedValue;
            //pick.ReceiverUser = txtReceiverUserEdit.Text;
            //pick.Receiveraddr = txtReceiverAddrEdit.Text;
            //pick.PlanDate = FormatHelper.TODateInt(txtPlanDateEdit.Text);
            //pick.Remark1 = txtREMARKEdit.Text;
            #endregion

            try
            {
                this.DataProvider.BeginTransaction();
                foreach (MesWWPOExc wwpo in wwpoList)
                {
                    //BenQGuru.eMES.Domain.MOModel.Material m = (BenQGuru.eMES.Domain.MOModel.Material)_WarehouseFacade.GetMaterialFromDQMCode(wwpo.DQMCode);
                    //if (m == null)
                    //{
                    //    this.DataProvider.RollbackTransaction();
                    //    WebInfoPublish.Publish(this, "鼎桥物料号不存在", this.languageComponent1);
                    //    return;
                    //}
                    #region add by sam Picktopo

                    PickToPo pickToPo = new PickToPo();
                    pickToPo.PickNo       = txtPickNoQuery.Text;
                    pickToPo.DQMCode      = wwpo.DQMCode; // txtDQMCodeEdit.Text;
                    pickToPo.PickLine     = (_WarehouseFacade.GetMaxLine(txtPickNoQuery.Text) + 1).ToString();
                    pickToPo.MCode        = wwpo.MCode;   // string.IsNullOrEmpty(m.MCode) ? " " : m.MCode;
                    pickToPo.MaintainDate = FormatHelper.TODateInt(DateTime.Now);
                    pickToPo.MaintainTime = FormatHelper.TOTimeInt(DateTime.Now);
                    pickToPo.MaintainUser = this.GetUserCode();


                    pickToPo.PoNo   = FormatHelper.CleanString(txtInvNoEidt.Text);
                    pickToPo.PoLine = wwpo.POLine.ToString();
                    _WarehouseFacade.AddPickToPo(pickToPo);

                    #endregion

                    #region add by sam 检查qty

                    //int invline = 0;
                    //if (!string.IsNullOrEmpty(txtInvLineEidt.Text))
                    //{
                    //    invline = Convert.ToInt32(txtInvLineEidt.Text);
                    //}
                    int     invline = wwpo.POLine;
                    string  mcode   = wwpo.MCode; // string.IsNullOrEmpty(m.MCode) ? " " : m.MCode;
                    string  invno   = FormatHelper.CleanString(txtInvNoEidt.Text);
                    decimal decqty  = 0;          // decimal.Parse(txtNumEdit.Text);
                    //decimal pickqty = _WarehouseFacade.GetPickDetailQty(invno, invline, mcode);
                    //decimal wwpoqty = _WarehouseFacade.GetWWPOQty(invno, invline, mcode);
                    //if (decqty + pickqty > wwpoqty)
                    //{
                    //    WebInfoPublish.Publish(this, "领料数量大于库存数量", this.languageComponent1);
                    //}
                    #endregion


                    pick.PickNo   = txtPickNoQuery.Text;
                    pick.DQMCode  = wwpo.DQMCode;// txtDQMCodeEdit.Text;
                    pick.MDesc    = wwpo.MChLongDesc;
                    pick.PickLine = (_WarehouseFacade.GetMaxLine(txtPickNoQuery.Text) + 1).ToString();
                    pick.MCode    = wwpo.MCode;// string.IsNullOrEmpty(m.MCode) ? " " : m.MCode;
                    //pick.QTY = 0; // decimal.Parse(txtNumEdit.Text);

                    pick.QTY = 0;

                    pick.MaintainDate   = FormatHelper.TODateInt(DateTime.Now);
                    pick.MaintainTime   = FormatHelper.TOTimeInt(DateTime.Now);
                    pick.MaintainUser   = this.GetUserCode();
                    pick.Status         = "Release";
                    pick.VEnderItemCode = wwpo.HWMCode;
                    pick.CDate          = FormatHelper.TODateInt(DateTime.Now);
                    pick.CTime          = FormatHelper.TOTimeInt(DateTime.Now);
                    pick.CUser          = this.GetUserCode();
                    pick.InvLine        = invline;
                    _WarehouseFacade.AddPickdetail(pick);
                }



                //if (decqty + pickqty > wwpoqty)
                //{
                //    WebInfoPublish.Publish(this, "领料数量大于库存数量", this.languageComponent1);
                //}
                //else
                //{
                //}
                this.DataProvider.CommitTransaction();
                txtWWPoSerialEdit.Text = string.Empty;
                WebInfoPublish.Publish(this, "添加成功!", this.languageComponent1);
            }
            catch (Exception ex)
            {
                this.DataProvider.RollbackTransaction();
                WebInfoPublish.PublishInfo(this, ex.Message, this.languageComponent1);
            }


            this.gridHelper.RequestData();
            this.buttonHelper.PageActionStatusHandle(PageActionType.Add);
        }
        protected void cmdLotSave_ServerClick(object sender, EventArgs e)
        {
            try
            {
                _WarehouseFacade = new BenQGuru.eMES.Material.WarehouseFacade(this.DataProvider);
                BenQGuru.eMES.Domain.Warehouse.Pick p = (BenQGuru.eMES.Domain.Warehouse.Pick)_WarehouseFacade.GetPick(txtPickNoQuery.Text);
                if (p.Status != Pick_STATUS.Status_Release)
                {
                    WebInfoPublish.Publish(this, p.PickNo + "拣货任务令的状态必须是初始化才能修改!", this.languageComponent1);
                    return;
                }
                StringBuilder sb = new StringBuilder(300);
                this.DataProvider.BeginTransaction();
                List <string> pickLineGtQty = new List <string>();
                for (int i = 0; i < this.gridWebGrid.Rows.Count; i++)
                {
                    string pickLine = this.gridWebGrid.Rows[i].Items.FindItemByKey("PICKLINE").Value.ToString();
                    BenQGuru.eMES.Domain.Warehouse.PickDetail d = (BenQGuru.eMES.Domain.Warehouse.PickDetail)_WarehouseFacade.GetPickdetail(txtPickNoQuery.Text, pickLine);
                    decimal qty = d.QTY;
                    BenQGuru.eMES.Domain.MOModel.Material m = (BenQGuru.eMES.Domain.MOModel.Material)_WarehouseFacade.GetMaterialFromDQMCode(d.DQMCode);

                    if (m == null)
                    {
                        WebInfoPublish.Publish(this, d.DQMCode + "物料号不存在!", this.languageComponent1);
                        this.DataProvider.RollbackTransaction();
                        return;
                    }



                    string qtyStr = this.gridWebGrid.Rows[i].Items.FindItemByKey("QTY").Value.ToString();

                    decimal decqty = 0;
                    if (!decimal.TryParse(qtyStr, out decqty))
                    {
                        WebInfoPublish.Publish(this, txtPickNoQuery.Text + ":" + pickLine + "数量必须是数字!", this.languageComponent1);
                        this.DataProvider.RollbackTransaction();
                        return;
                    }

                    string  invno   = FormatHelper.CleanString(txtInvNoEidt.Text);
                    decimal pickqty = _WarehouseFacade.GetPickDetailQty(invno, d.InvLine, m.MCode);
                    decimal wwpoqty = _WarehouseFacade.GetWWPOQty(invno, d.InvLine, m.MCode);

                    bool isFalse = (decqty + pickqty - qty > wwpoqty);
                    d.QTY = decqty;
                    if (isFalse)
                    {
                        sb.Append(string.Format(@"拣货任务令号:{0},SAP单据号:{1},状态:{2},下发人:{3},鼎桥物料编码:{4},描述:{5},领取数量:{6},超领数量:{7} \r\n",
                                                p.PickNo,
                                                txtInvNoEidt.Text,
                                                p.Status,
                                                GetUserCode(),
                                                m.DqmCode,
                                                m.MenshortDesc,
                                                decqty, decqty + pickqty - qty - wwpoqty));
                        pickLineGtQty.Add(pickLine);
                    }
                    _WarehouseFacade.UpdatePickdetail(d);
                }

                this.DataProvider.CommitTransaction();

                if (pickLineGtQty.Count == 0)
                {
                    WebInfoPublish.Publish(this, "保存成功", this.languageComponent1);
                }
                else
                {
                    GenWWPOMail(sb.ToString(), GetUserCode());
                    WebInfoPublish.Publish(this, "保存成功 - " + txtPickNoQuery.Text + "行项目" + string.Join(",", pickLineGtQty.ToArray()) + " 的领料数大于SAP物料数量", this.languageComponent1);
                }
            }
            catch (Exception ex)
            {
                this.DataProvider.RollbackTransaction();
                throw ex;
            }
            this.gridHelper.RequestData();
            this.buttonHelper.PageActionStatusHandle(PageActionType.Save);
        }