Beispiel #1
0
        private int Import()
        {
            int result = 0;

            using (var ctx = new EF6.RT2020Entities())
            {
                using (var scope = ctx.Database.BeginTransaction())
                {
                    try
                    {
                        for (int i = 0; i < md.Length; i++)
                        {
                            string txNumber = SystemInfoHelper.Settings.QueuingTxNumber(EnumHelper.TxType.TXF);

                            #region Guid headerId = ImportTxferHeader(md[i].Master as TxferTxtIEMaster, txNumber);
                            var master = md[i].Master as TxferTxtIEMaster;

                            var oHeader = new EF6.InvtBatchTXF_Header();
                            oHeader.HeaderId      = Guid.NewGuid();
                            oHeader.TxType        = EnumHelper.TxType.TXF.ToString();
                            oHeader.TxNumber      = txNumber;
                            oHeader.TxDate        = master.TxDate;
                            oHeader.TransferredOn = master.TxferDate;
                            oHeader.CompletedOn   = master.CompletionDate;
                            oHeader.FromLocation  = WorkplaceEx.GetWorkplaceIdByCode(master.FromLocation);
                            oHeader.ToLocation    = WorkplaceEx.GetWorkplaceIdByCode(master.ToLocation);
                            oHeader.StaffId       = StaffEx.GetStaffIdByStaffNumber(master.Operator);
                            oHeader.Status        = Convert.ToInt32(EnumHelper.Status.Draft.ToString("d"));
                            oHeader.Reference     = master.RefNumber;
                            oHeader.Remarks       = master.Remarks;

                            oHeader.CreatedBy  = ConfigHelper.CurrentUserId;
                            oHeader.CreatedOn  = DateTime.Now;
                            oHeader.ModifiedBy = ConfigHelper.CurrentUserId;
                            oHeader.ModifiedOn = DateTime.Now;

                            ctx.InvtBatchTXF_Header.Add(oHeader);
                            ctx.SaveChanges();

                            Guid headerId = oHeader.HeaderId;
                            #endregion

                            if (headerId != Guid.Empty)
                            {
                                lvImportedList.Items[i].Text = txNumber;

                                #region ImportTxferDetails(md[i].Details, headerId, txNumber);
                                object[] details = md[i].Details;

                                if (details != null)
                                {
                                    for (int j = 0; j < details.Length; j++)
                                    {
                                        TxferTxtIEDetails detail = details[j] as TxferTxtIEDetails;
                                        Guid prodId = GetProductId(detail);
                                        if (prodId != Guid.Empty)
                                        {
                                            var oDetail = new EF6.InvtBatchTXF_Details();
                                            oDetail.DetailsId      = Guid.NewGuid();
                                            oDetail.ProductId      = prodId;
                                            oDetail.HeaderId       = headerId;
                                            oDetail.LineNumber     = j + 1;
                                            oDetail.TxNumber       = txNumber;
                                            oDetail.TxType         = EnumHelper.TxType.TXF.ToString();
                                            oDetail.QtyConfirmed   = 0;
                                            oDetail.QtyHHT         = 0;
                                            oDetail.QtyManualInput = 0;
                                            oDetail.QtyReceived    = detail.TxferQty;
                                            oDetail.QtyRequested   = detail.RequiredQty;
                                            oDetail.Remarks        = detail.Remarks;

                                            ctx.InvtBatchTXF_Details.Add(oDetail);
                                            ctx.SaveChanges();
                                            result++;
                                        }
                                    }
                                }
                                #endregion

                                result++;
                            }
                        }

                        scope.Commit();
                    }
                    catch (Exception ex)
                    {
                        scope.Rollback();
                    }
                }
            }

            return(result);
        }
Beispiel #2
0
        private int Import()
        {
            int result = 0;

            using (var ctx = new EF6.RT2020Entities())
            {
                using (var scope = ctx.Database.BeginTransaction())
                {
                    try
                    {
                        for (int i = 0; i < md.Length; i++)
                        {
                            string txNumber = SystemInfoHelper.Settings.QueuingTxNumber(EnumHelper.TxType.CAP);

                            #region Guid headerId = ImportCAPHeader(md[i].Master as CAPTxtIEMaster, txNumber);
                            CAPTxtIEMaster master = md[i].Master as CAPTxtIEMaster;

                            var oHeader = new EF6.InvtBatchCAP_Header();
                            oHeader.HeaderId     = Guid.NewGuid();
                            oHeader.TxType       = EnumHelper.TxType.CAP.ToString();
                            oHeader.TxNumber     = txNumber;
                            oHeader.TxDate       = master.RecvDate;
                            oHeader.WorkplaceId  = WorkplaceEx.GetWorkplaceIdByCode(master.Location);
                            oHeader.StaffId      = StaffEx.GetStaffIdByStaffNumber(master.Operator);
                            oHeader.SupplierId   = SupplierEx.GetSupplierIdBySupplierCode(master.Supplier);
                            oHeader.Status       = Convert.ToInt32(EnumHelper.Status.Draft.ToString("d"));
                            oHeader.Reference    = master.RefNumber;
                            oHeader.Remarks      = master.Remarks;
                            oHeader.CurrencyCode = "HKD";
                            oHeader.ExchangeRate = (decimal)1;

                            oHeader.CreatedBy  = ConfigHelper.CurrentUserId;
                            oHeader.CreatedOn  = DateTime.Now;
                            oHeader.ModifiedBy = ConfigHelper.CurrentUserId;
                            oHeader.ModifiedOn = DateTime.Now;

                            ctx.InvtBatchCAP_Header.Add(oHeader);
                            ctx.SaveChanges();

                            Guid headerId = oHeader.HeaderId;
                            #endregion

                            decimal ttlAmt = 0;
                            #region decimal ttlAmt = ImportCAPDetails(md[i].Details, headerId, txNumber);
                            object[] details = md[i].Details;
                            if (details != null)
                            {
                                for (int j = 0; j < details.Length; j++)
                                {
                                    CAPTxtIEDetails detail = details[j] as CAPTxtIEDetails;
                                    Guid            prodId = GetProductId(detail);

                                    if (prodId != Guid.Empty)
                                    {
                                        var oDetail = new EF6.InvtBatchCAP_Details();
                                        oDetail.DetailsId  = Guid.NewGuid();
                                        oDetail.ProductId  = prodId;
                                        oDetail.HeaderId   = headerId;
                                        oDetail.LineNumber = j + 1;
                                        oDetail.TxNumber   = txNumber;
                                        oDetail.TxType     = EnumHelper.TxType.CAP.ToString();
                                        oDetail.Qty        = detail.ReceivedQty;
                                        oDetail.UnitAmount = detail.ReceivedUnitAmount;
                                        oDetail.UnitAmountInForeignCurrency = detail.ReceivedUnitAmount;

                                        ctx.InvtBatchCAP_Details.Add(oDetail);
                                        ctx.SaveChanges();

                                        ttlAmt += oDetail.Qty.Value * oDetail.UnitAmount.Value;
                                    }
                                    else
                                    {
                                        string skippedProduct = String.Format("?{0} {1} {2} {3}",
                                                                              detail.StockCode, detail.Appendix1, detail.Appendix2, detail.Appendix3);
                                        skippedList.Add(skippedProduct);
                                    }
                                }
                            }
                            #endregion

                            oHeader = ctx.InvtBatchCAP_Header.Find(headerId);
                            if (oHeader != null)
                            {
                                oHeader.TotalAmount = ttlAmt;
                                ctx.SaveChanges();

                                UpdateListView(i, txNumber);

                                skippedList.Clear();
                            }

                            result++;
                        }
                        scope.Commit();
                    }
                    catch (Exception ex)
                    {
                        scope.Rollback();
                    }
                }
            }

            return(result);
        }