예제 #1
0
        protected void cmdMerge_ServerClick(object sender, EventArgs e)
        {
            ArrayList array = this.GetCheckedRows();
            //A:检查Grid中至少选择2笔以上记录
            //marked by seven  2010-12-22
            //if (array.Count < 2)
            //{
            //    WebInfoPublish.PublishInfo(this, "$Error_Row_Selected_More_Two", this.languageComponent1);
            //    return;
            //}
            //B:检查选择的入库单类型,源库别,收货库别,组织必须一致。
            Hashtable htRecType       = new Hashtable();
            Hashtable htFromStorageNo = new Hashtable();
            Hashtable htToStorageNo   = new Hashtable();
            Hashtable htOrgID         = new Hashtable();

            foreach (Infragistics.WebUI.UltraWebGrid.UltraGridRow row in array)
            {
                string RecType       = row.Cells.FromKey("RECType").ToString();
                string FromStorageNo = row.Cells.FromKey("FromStorageID").ToString();
                string ToStorageNo   = row.Cells.FromKey("ToStorageID").ToString();
                string OrgID         = row.Cells.FromKey("Check").ToString();

                if (!htRecType.ContainsKey(RecType))
                {
                    htRecType.Add(RecType, "");
                }

                if (!htFromStorageNo.ContainsKey(FromStorageNo))
                {
                    htFromStorageNo.Add(FromStorageNo, "");
                }

                if (!htToStorageNo.ContainsKey(ToStorageNo))
                {
                    htToStorageNo.Add(ToStorageNo, "");
                }

                if (!htOrgID.ContainsKey(OrgID))
                {
                    htOrgID.Add(OrgID, "");
                }
            }

            if (htRecType.Count != 1)
            {
                WebInfoPublish.PublishInfo(this, "$Error_RecType_Different", this.languageComponent1);
                return;
            }

            if (htFromStorageNo.Count != 1)
            {
                WebInfoPublish.PublishInfo(this, "$Error_FromStorageNo_Different", this.languageComponent1);
                return;
            }

            if (htToStorageNo.Count != 1)
            {
                WebInfoPublish.PublishInfo(this, "$Error_ToStorageNo_Different", this.languageComponent1);
                return;
            }
            if (htOrgID.Count != 1)
            {
                WebInfoPublish.PublishInfo(this, "$Error_OrgID_Different", this.languageComponent1);
                return;
            }
            if (_TransferFacade == null)
            {
                _TransferFacade = new WarehouseFacade(this.DataProvider);
            }

            try
            {
                this.DataProvider.BeginTransaction();
                //将选择的几个移转单的Detail信息按料号Sum(PLANQTY)重新计算数量后放在该新生成的移转单下。

                Hashtable detailHT = new Hashtable();
                decimal   totalQty = 0;
                foreach (Infragistics.WebUI.UltraWebGrid.UltraGridRow row in array)
                {
                    string  TransferNO = row.Cells.FromKey("TransferNO").ToString();
                    decimal qty        = _TransferFacade.QueryTransferQty(TransferNO);
                    totalQty += qty;

                    object[] objs = _TransferFacade.GetInvTransferDetailByTransferNO(TransferNO);

                    if (objs != null)
                    {
                        foreach (InvTransferDetail tranferDetail in objs)
                        {
                            if (!detailHT.ContainsKey(tranferDetail.ItemCode))
                            {
                                detailHT.Add(tranferDetail.ItemCode, tranferDetail.Planqty);
                            }
                            else
                            {
                                detailHT[tranferDetail.ItemCode] = decimal.Parse(detailHT[tranferDetail.ItemCode].ToString()) + tranferDetail.Planqty;
                            }
                        }
                    }
                }

                //C:按规则 MESXXXXXXX(MES + 7位数字)生成新的移转单号(可以利用TblSerialBook表)
                string newTransNo = this.CreateNewTransNo();

                DBDateTime  dbDateTime  = FormatHelper.GetNowDBDateTime(this.DataProvider);
                InvTransfer invTransfer = new InvTransfer();
                invTransfer.TransferNO     = newTransNo;
                invTransfer.TransferStatus = RecordStatus.RecordStatus_NEW;
                invTransfer.CreateDate     = dbDateTime.DBDate;
                invTransfer.CreateTime     = dbDateTime.DBTime;
                invTransfer.CreateUser     = this.GetUserCode();
                invTransfer.FromStorageID  = (array[0] as Infragistics.WebUI.UltraWebGrid.UltraGridRow).Cells.FromKey("FromStorageID").Value.ToString();
                invTransfer.ToStorageID    = (array[0] as Infragistics.WebUI.UltraWebGrid.UltraGridRow).Cells.FromKey("ToStorageID").Value.ToString();
                invTransfer.Rectype        = (array[0] as Infragistics.WebUI.UltraWebGrid.UltraGridRow).Cells.FromKey("RECType").Value.ToString();
                invTransfer.Memo           = "";
                invTransfer.Mdate          = dbDateTime.DBDate;
                invTransfer.Mtime          = dbDateTime.DBTime;
                invTransfer.Muser          = this.GetUserCode();
                invTransfer.OrgID          = int.Parse((array[0] as Infragistics.WebUI.UltraWebGrid.UltraGridRow).Cells.FromKey("OrganizationID").Value.ToString());
                _TransferFacade.AddInvTransfer(invTransfer);

                int i = 1;
                foreach (DictionaryEntry de in detailHT)
                {
                    //ORDERNO,ORDERLINE,MEMO,MOCODE,CustomerCode,CUSTOMERNAME都为空,ACTQTY=0
                    InvTransferDetail detail = new InvTransferDetail();
                    detail.TransferNO     = newTransNo;
                    detail.TransferLine   = i++;
                    detail.OrderNO        = "";
                    detail.OrderLine      = 0;
                    detail.Memo           = "";
                    detail.MOCode         = "";
                    detail.CustomerCode   = "";
                    detail.CustomerName   = "";
                    detail.Actqty         = 0;
                    detail.Muser          = this.GetUserCode();
                    detail.Mdate          = dbDateTime.DBDate;
                    detail.Mtime          = dbDateTime.DBTime;
                    detail.TransferDate   = dbDateTime.DBDate;
                    detail.TransferTime   = dbDateTime.DBTime;
                    detail.TransferUser   = this.GetUserCode();
                    detail.TransferStatus = RecordStatus.RecordStatus_NEW;
                    detail.ItemCode       = de.Key.ToString();
                    detail.Planqty        = decimal.Parse(de.Value.ToString());

                    _TransferFacade.AddInvTransferDetail(detail);
                }

                //D:将关联关系插入table:TBLInvTransferMerge
                foreach (Infragistics.WebUI.UltraWebGrid.UltraGridRow row in array)
                {
                    InvTransferMerge merge = new InvTransferMerge();
                    merge.Transferno = newTransNo;
                    //merge.Frmtransferno = (array[0] as Infragistics.WebUI.UltraWebGrid.UltraGridRow).Cells.FromKey("FromStorageID").ToString();
                    //modify by li 2011.1.19
                    merge.Frmtransferno = row.Cells.FromKey("TransferNO").ToString();
                    merge.Muser         = this.GetUserCode();
                    merge.Mdate         = dbDateTime.DBDate;
                    merge.Mtime         = dbDateTime.DBTime;

                    _TransferFacade.AddInvTransferMerge(merge);
                }

                this.DataProvider.CommitTransaction();

                cmdQuery_ServerClick(null, null);

                WebInfoPublish.PublishInfo(this, string.Format("$Success_Merge_Transfer {0}", newTransNo), this.languageComponent1);
            }
            catch (Exception ex)
            {
                this.DataProvider.RollbackTransaction();
            }
        }