Beispiel #1
0
 private static string GetFormatedText(EF6.InvtBatchCAP_Header target, string[] textField, string textFormatString)
 {
     for (int i = 0; i < textField.Length; i++)
     {
         PropertyInfo pi = target.GetType().GetProperty(textField[i]);
         textFormatString = textFormatString.Replace("{" + i.ToString() + "}", pi != null ? pi.GetValue(target, null).ToString() : string.Empty);
     }
     return(textFormatString);
 }
Beispiel #2
0
        /// <summary>
        /// Get a EF6.InvtBatchCAP_Header object from the database using the given HeaderId
        /// </summary>
        /// <param name="headerId">The primary key value</param>
        /// <returns>A EF6.InvtBatchCAP_Header object</returns>
        public static EF6.InvtBatchCAP_Header Get(Guid headerId)
        {
            EF6.InvtBatchCAP_Header result = null;

            using (var ctx = new EF6.RT2020Entities())
            {
                result = ctx.InvtBatchCAP_Header.Where(x => x.HeaderId == headerId).AsNoTracking().FirstOrDefault();
            }

            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Get a EF6.InvtBatchCAP_Header object from the database using the given QueryString
        /// </summary>
        /// <param name="headerId">The primary key value</param>
        /// <returns>A EF6.InvtBatchCAP_Header object</returns>
        public static EF6.InvtBatchCAP_Header Get(string whereClause)
        {
            EF6.InvtBatchCAP_Header result = null;

            using (var ctx = new EF6.RT2020Entities())
            {
                result = ctx.InvtBatchCAP_Header
                         .SqlQuery(string.Format("Select * from InvtBatchCAP_Header Where {0}", whereClause))
                         .AsNoTracking()
                         .FirstOrDefault();
            }

            return(result);
        }
Beispiel #4
0
        private void SaveREJ()
        {
            using (var ctx = new EF6.RT2020Entities())
            {
                using (var scope = ctx.Database.BeginTransaction())
                {
                    try
                    {
                        var oHeader = ctx.InvtBatchCAP_Header.Find(this.REJId);
                        if (oHeader == null)
                        {
                            #region add new InvtBatchCAP_Header
                            oHeader          = new EF6.InvtBatchCAP_Header();
                            oHeader.HeaderId = Guid.NewGuid();
                            txtTxNumber.Text = SystemInfoHelper.Settings.QueuingTxNumber(EnumHelper.TxType.REJ);
                            oHeader.TxNumber = txtTxNumber.Text;
                            oHeader.TxType   = EnumHelper.TxType.REJ.ToString();

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

                            ctx.InvtBatchCAP_Header.Add(oHeader);
                            #endregion
                        }
                        #region InvtBatchCAP_Header core data
                        oHeader.TxDate = dtpRecvDate.Value;
                        oHeader.Status = Convert.ToInt32(cboStatus.Text == "HOLD" ? EnumHelper.Status.Draft.ToString("d") : EnumHelper.Status.Active.ToString("d"));

                        oHeader.WorkplaceId      = new Guid(cboWorkplace.SelectedValue.ToString());
                        oHeader.StaffId          = new Guid(cboOperatorCode.SelectedValue.ToString());
                        oHeader.SupplierId       = new Guid(cboSupplierList.SelectedValue.ToString());
                        oHeader.SupplierRefernce = txtSupplierInvoice.Text;
                        oHeader.Remarks          = txtRemarks.Text;
                        oHeader.Reference        = txtRefNumber.Text;
                        oHeader.LinkToAP         = chkAPLink.Checked;

                        oHeader.ModifiedBy = ConfigHelper.CurrentUserId;
                        oHeader.ModifiedOn = DateTime.Now;
                        #endregion

                        decimal totlaAmount = 0;
                        decimal.TryParse(txtTotalAmount.Text, out totlaAmount);
                        oHeader.TotalAmount = totlaAmount;

                        ctx.SaveChanges();

                        #region log activity
                        RT2020.Controls.Log4net.LogInfo(
                            ctx.Entry(oHeader).State == System.Data.Entity.EntityState.Added ?
                            RT2020.Controls.Log4net.LogAction.Create :
                            RT2020.Controls.Log4net.LogAction.Update, oHeader.ToString());
                        #endregion

                        this.REJId = oHeader.HeaderId;

                        #region SaveREJDetail();
                        foreach (ListViewItem listItem in lvDetailsList.Items)
                        {
                            Guid detailId = Guid.Empty, productId = Guid.Empty;

                            if (Guid.TryParse(listItem.Text.Trim(), out detailId) && Guid.TryParse(listItem.SubItems[11].Text.Trim(), out productId))
                            {
                                //System.Guid detailId = new Guid(listItem.Text.Trim());
                                var oDetail = ctx.InvtBatchCAP_Details.Find(detailId);
                                if (oDetail == null)
                                {
                                    oDetail            = new EF6.InvtBatchCAP_Details();
                                    oDetail.DetailsId  = Guid.NewGuid();
                                    oDetail.HeaderId   = this.REJId;
                                    oDetail.TxNumber   = txtTxNumber.Text;
                                    oDetail.TxType     = txtTxType.Text;
                                    oDetail.LineNumber = Convert.ToInt32(listItem.SubItems[1].Text.Length == 0 ? "1" : listItem.SubItems[1].Text);

                                    ctx.InvtBatchCAP_Details.Add(oDetail);
                                }
                                oDetail.ProductId  = productId; // new Guid(listItem.SubItems[11].Text.Trim());
                                oDetail.Qty        = Convert.ToDecimal(listItem.SubItems[8].Text.Length == 0 ? "0" : listItem.SubItems[8].Text);
                                oDetail.UnitAmount = Convert.ToDecimal(listItem.SubItems[9].Text.Length == 0 ? "0" : listItem.SubItems[9].Text);
                                oDetail.UnitAmountInForeignCurrency = Convert.ToDecimal(listItem.SubItems[9].Text.Length == 0 ? "0" : listItem.SubItems[9].Text);

                                if (listItem.SubItems[2].Text.Trim().ToUpper() == "REMOVED" && detailId != System.Guid.Empty)
                                {
                                    ctx.InvtBatchCAP_Details.Remove(oDetail);
                                }
                                ctx.SaveChanges();
                            }
                        }
                        #endregion

                        #region UpdateHeaderInfo(); HACK: 點解喺呢度先 update Total Amount? 我將佢搬咗上去
                        //oHeader.TotalAmount = Convert.ToDecimal(Common.Utility.IsNumeric(txtTotalAmount.Text) ? txtTotalAmount.Text : "0");
                        //ctx.SaveChanges();

                        // log activity (Update)
                        //RT2020.Controls.Log4net.LogInfo(RT2020.Controls.Log4net.LogAction.Update, oHeader.ToString());
                        #endregion

                        scope.Commit();
                    }
                    catch (Exception ex)
                    {
                        scope.Rollback();
                    }
                }
            }
        }
Beispiel #5
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);
        }