Exemple #1
0
        private object GetUpdateObject()
        {
            if (_iqcfacade == null)
            {
                _iqcfacade = new BenQGuru.eMES.IQC.IQCFacade(base.DataProvider);
            }
            string ReceiptNo   = FormatHelper.CleanString(this.txtReceiveNoQuery.Text);
            int    ReceiptLine = 0;

            if (FormatHelper.CleanString(this.txtReceiveLineEdit.Text).Length > 0)
            {
                ReceiptLine = int.Parse(FormatHelper.CleanString(this.txtReceiveLineEdit.Text));
            }
            object           obj = this._iqcfacade.GetInvReceiptDetailForUpdate(ReceiptNo, ReceiptLine);
            InvReceiptDetail invreceiptdetail = (InvReceiptDetail)obj;

            if (invreceiptdetail == null)
            {
                invreceiptdetail = this._iqcfacade.CreateNewINVReceiptDetail();

                invreceiptdetail.Receiptno   = FormatHelper.CleanString(this.txtReceiveNoQuery.Text.ToUpper(), 40);
                invreceiptdetail.Receiptline = int.Parse(this.txtReceiveLineEdit.Text);
                invreceiptdetail.Itemcode    = FormatHelper.CleanString(this.txtMaterialCodeEdit.Text, 40);
                invreceiptdetail.Orderline   = int.Parse(this.txtOrderLineEdit.Text);
                invreceiptdetail.Orderno     = FormatHelper.CleanString(this.txtOrderNoEdit.Text, 40);
                invreceiptdetail.Planqty     = decimal.Parse(this.txtPlanQtyEdit.Text);
                invreceiptdetail.Memo        = FormatHelper.CleanString(this.txtMemoEdit.Text, 2000);
                invreceiptdetail.InvUser     = FormatHelper.CleanString(this.txtManagerCode.Text, 100);//added by Jarvis
                invreceiptdetail.Muser       = this.GetUserCode();
                invreceiptdetail.Recstatus   = FormatHelper.CleanString(this.txtTicketStatus.Text, 2000);
                return(invreceiptdetail);
            }
            else
            {
                invreceiptdetail.Receiptno   = FormatHelper.CleanString(this.txtReceiveNoQuery.Text.ToUpper(), 40);
                invreceiptdetail.Receiptline = int.Parse(this.txtReceiveLineEdit.Text);
                invreceiptdetail.Itemcode    = FormatHelper.CleanString(this.txtMaterialCodeEdit.Text, 40);
                invreceiptdetail.Orderline   = int.Parse(this.txtOrderLineEdit.Text);
                invreceiptdetail.Orderno     = FormatHelper.CleanString(this.txtOrderNoEdit.Text, 40);
                invreceiptdetail.Planqty     = decimal.Parse(this.txtPlanQtyEdit.Text);
                invreceiptdetail.Memo        = FormatHelper.CleanString(this.txtMemoEdit.Text, 2000);
                invreceiptdetail.InvUser     = FormatHelper.CleanString(this.txtManagerCode.Text, 100);//added by Jarvis
                invreceiptdetail.Muser       = this.GetUserCode();
                invreceiptdetail.Recstatus   = FormatHelper.CleanString(this.txtTicketStatus.Text, 2000);
                return(invreceiptdetail);
            }
        }
        public async Task <List <InvReceiptDetailDto> > SaveDetailAsync(InvReceiptDto vm)
        {
            try
            {
                foreach (var item in vm.listDetail)
                {
                    var objsave = new InvReceiptDetail()
                    {
                        Id = item.DetailId,
                        InventoryItemId = item.InventoryItemId,
                        InvReceiptId    = vm.Id,
                        Quantity        = item.Quantity
                    };
                    if (objsave.Id > 0 && item.ObjectState != (int)ObjectState.Deleted)
                    {
                        item.ObjectState = (int)ObjectState.Modified;
                    }
                    if (objsave.Id <= 0 && item.ObjectState != (int)ObjectState.Deleted)
                    {
                        item.ObjectState = (int)ObjectState.Added;
                    }
                    switch (item.ObjectState)
                    {
                    case (int)ObjectState.Added:
                        db.InvReceiptDetails.Add(objsave);
                        await db.SaveChangesAsync();

                        break;

                    case (int)ObjectState.Modified:
                        db.Entry(objsave).State = EntityState.Modified;
                        await db.SaveChangesAsync();

                        break;
                    }
                    item.DetailId = objsave.Id;
                }
                vm.listDetail = GetDetails(vm.Id);
                return(vm.listDetail);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }