示例#1
0
    private void InsertNewData(ref ISession sess)
    {
        string PriceTax = ValidCurrency(txtPriceTax.Text.Trim());
        ITransaction tx = sess.BeginTransaction();
        try
        {
            Batchinvoiceheader bih = new Batchinvoiceheader();
            bih.Dealercode = UserHelper.DealerCode;
            bih.Branchcode = ddlStoreCode.SelectedValue;
            bih.Createdby = UserHelper.Username;
            bih.Createddate = DateTime.Now;
            IList lstbih = sess.CreateCriteria(typeof(Batchinvoiceheader)).Add(Expression.Eq("Batchinvoicenumber", txtBillNo.Text.Trim())).List();
            if (lstbih.Count > 0)
            {
                ShowMessage(Message.Invoice_BillDuplicated, true);
                return;
            }
            else
                bih.Batchinvoicenumber = txtBillNo.Text.Trim();

            //Create sellitem
            Sellitem sellIns = new Sellitem();

            if (!PriceTax.Equals("")) sellIns.Pricebeforetax = decimal.Parse(PriceTax);
            DateTime dtRecDate;
            DateTime.TryParse(txtRecCDate.Text, new CultureInfo(UserHelper.Language), DateTimeStyles.AllowWhiteSpaces, out dtRecDate);
            sellIns.Paymentdate = dtRecDate;
            sellIns.Selltype = txtSellingType.Text;

            sellIns.Paymenttype = int.Parse(ddlPaymentMethod.SelectedValue);
            sess.Save(sellIns);
            bih.Sellitem = sellIns;

            #region Save hire-purchase
            if (ddlPaymentMethod.SelectedValue.Equals(((int)CusPaymentType.UnFixedHire_purchase).ToString()))
            {
                TextBox txtIntentDatePay, UHPtxtMoney;
                Payment pmIns;
                for (int i = 1; i < 6; i++)
                {
                    try
                    {
                        txtIntentDatePay = (TextBox)UnfixedHP.FindControl("txtIntentDatePay" + i);
                        UHPtxtMoney = (TextBox)UnfixedHP.FindControl("UHPtxtMoney" + i);
                        pmIns = new Payment();
                        if (txtIntentDatePay.Text.Trim() != "" && UHPtxtMoney.Text.Trim() != "")
                        {
                            pmIns.Sellitem = sellIns;
                            pmIns.Paymentdate = DateTime.Parse(txtIntentDatePay.Text.Trim());
                            pmIns.Amount = decimal.Parse(ValidCurrency(UHPtxtMoney.Text.Trim()));
                            pmIns.Status = 0;
                            sess.Save(pmIns);
                        }
                    }
                    catch (Exception) { }
                }
            }
            if (ddlPaymentMethod.SelectedValue.Equals(((int)CusPaymentType.FixedHire_purchase).ToString()))
            {
                BindAndSaveFHPPayment(ref sess, sellIns);
            }
            #endregion

            //Create subshop
            if (ddlAgency.SelectedValue.Trim().Equals(""))
            {
                ShowMessage(Resources.Message.Selling_SubStoreNotFound, true);
                return;
            }
            else
            {
                Subshop ss = sess.CreateCriteria(typeof(Subshop)).Add(Expression.Eq("Id", long.Parse(ddlAgency.SelectedValue))).List()[0] as Subshop;
                bih.Subshop = ss;
                sess.SaveOrUpdate(bih);
            }

            string strItemSelected = liSelectItemIns.Text;
            string[] lstItemSelected = strItemSelected.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < lstItemSelected.Length; i++)
            {   // selling date (nmChi added: 29/07/2008)
                DateTime dtSellDate;
                if (!DateTime.TryParse(txtSellingDate.Text, new CultureInfo(UserHelper.Language), DateTimeStyles.AllowWhiteSpaces, out dtSellDate))
                {
                    dtSellDate = DateTime.Now;
                }

                Iteminstance itemIns = sess.CreateCriteria(typeof(Iteminstance)).Add(Expression.Eq("Id", long.Parse(lstItemSelected[i]))).List()[0] as Iteminstance;
                itemIns.Status = (int)ItemStatus.Sold;   // Now drop inventory - change request 21/7/2010
                //itemIns.Status = (int)ItemStatus.Imported;
                itemIns.Releaseddate = dtSellDate;
                sess.SaveOrUpdate(itemIns);

                // save to Inventory of Day
                //InventoryHelper
                //    .SaveInventoryDay(itemIns.Item.Id, DateTime.Now, -1, (int)ItemStatus.Sold, UserHelper.DealerCode, UserHelper.BranchCode);

                //sess.Save((new ItemHepler()).SaveTranHis(itemIns, DateTime.Now, ItemStatus.Sold, int.Parse(ddlPaymentMethod.SelectedValue), long.Parse(PriceTax), UserHelper.CurrentUsername, null));

                sess.SaveOrUpdate(new Batchinvoicedetail(itemIns.Enginenumber, DateTime.Now, UserHelper.Username, itemIns, bih));
            }
            tx.Commit();
            PageRefresh();
            gvItems.Visible = false; btnSave.Enabled = false;
            ShowMessage(Resources.Message.ActionSucessful, false);
        }
        catch (HibernateException)
        {
            tx.Rollback();
            throw;
        }
    }
示例#2
0
 private void BindUFHP(ref ISession sess, Sellitem SellItemIns)
 {
     if (SellItemIns.Paymenttype.Equals((int)CusPaymentType.UnFixedHire_purchase))
     {
         TextBox txtIntentDatePay, UHPtxtMoney;
         CalendarExtender CEUHPCandelar;
         //GetSellItem
         Payment pm;
         IList lstPayment = sess.CreateCriteria(typeof(Payment))
             .Add(Expression.Eq("Sellitem", SellItemIns))
             //.Add(Expression.Eq("Status", (int)CusPaymentType.UnFixedHire_purchase))
             .List();
         for (int i = 1; i <= lstPayment.Count; i++)
         {
             try
             {
                 pm = (Payment)lstPayment[i - 1];
                 txtIntentDatePay = (TextBox)UnfixedHP.FindControl("txtIntentDatePay" + i);
                 UHPtxtMoney = (TextBox)UnfixedHP.FindControl("UHPtxtMoney" + i);
                 CEUHPCandelar = (CalendarExtender)UnfixedHP.FindControl("CEUHP" + i);
                 txtIntentDatePay.Text = pm.Paymentdate.ToShortDateString();
                 UHPtxtMoney.Text = (_PageStatus.Value.Equals(_DEFAULTPAGE))
                                        ? Convert2Currency(pm.Amount.ToString())
                                        : pm.Amount.ToString();
             }
             catch (Exception)
             {
                 throw new Exception("Error");
             }
         }
     }
 }
示例#3
0
    private void BindAndSaveFHPPayment(ref ISession sess, Sellitem sellitemIns)
    {
        decimal AllMoney = decimal.Parse(ValidCurrency(txtPriceTax.Text));
        decimal RestOfMoneyFHP = AllMoney - decimal.Parse(ValidCurrency(txtFHPFirstMoney.Text));
        decimal MoneyOfInstalment = RestOfMoneyFHP / (decimal.Parse(txtFHPTimes.Text) - 1);
        int DateCount = int.Parse(txtFHPPaidMoneyDate.Text.Trim());
        DateTime firstDate; DateTime lastDate = new DateTime();
        DateTime.TryParse(txtRecCDate.Text, new CultureInfo(UserHelper.Language), DateTimeStyles.AllowWhiteSpaces, out firstDate);

        Payment paymentIns;
        for (int i = 0; i <= (decimal.Parse(txtFHPTimes.Text) - 1); i++)
        {
            paymentIns = new Payment();
            //Save the first instalment
            if (i == 0)
            {
                paymentIns.Amount = decimal.Parse(ValidCurrency(txtFHPFirstMoney.Text));
                paymentIns.Paymentdate = firstDate;
                paymentIns.Sellitem = sellitemIns;
            }
            else
            {
                lastDate = firstDate.AddDays(DateCount * i);
                paymentIns.Amount = MoneyOfInstalment;
                paymentIns.Paymentdate = lastDate;
                paymentIns.Sellitem = sellitemIns;
            }
            paymentIns.Status = 0;
            sess.SaveOrUpdate(paymentIns);
        }
    }
示例#4
0
    private void InsertNewData(ref ISession sess)
    {
        //if (checkDateRange(txtSellingDate.Text.Trim(), txtRecCDate.Text.Trim())) { ShowMessage(Resources.Customers.RecDateSmallerThanSelDate, true); return; }
        //Datetime
        DateTime dtRecDate = DataFormat.DateFromString(txtRecCDate.Text), dtSellDate = DataFormat.DateFromString(txtSellingDate.Text);

        string PriceTax;
        PriceTax = txtPriceTax.Text.Trim().Replace(",", "");
        PriceTax = txtPriceTax.Text.Trim().Replace(".", "");

        ITransaction tx = sess.BeginTransaction();
        try
        {
            string Billno = txtBillNo.Text.Trim();
            //string idnum = _CustomerID.Value.Trim();
            if (_CustomerID.Value.Trim() == "-1")
            {
                ShowMessage(Message.Cus_NoCustomer, true);
                return;
            }
            Invoice InvoiceIns = new Invoice();
            // so hoa don giua 2 dai ly co the trung
            IList lstNonDulpInvoiceIns = sess.CreateCriteria(typeof(Invoice))
                .Add(Expression.Eq("Invoicenumber", Billno))
                .Add(Expression.Eq("Dealercode", UserHelper.DealerCode))
                .List();
            if (lstNonDulpInvoiceIns.Count > 0)
            {
                ShowMessage(Customers.Invoice_BillDuplicated, true);
                return;
            }
            else
            {
                lstNonDulpInvoiceIns = sess.CreateCriteria(typeof(Invoice))
                    .Add(Expression.InsensitiveLike("Enginenumber", txtEngineNo.Text.Trim().ToUpper()))
                    //.Add(Expression.Eq("Dealercode", UserHelper.DealerCode))
                    .List();
                if (lstNonDulpInvoiceIns.Count > 0)
                {
                    ShowMessage(Customers.Invoice_BillDuplicated, true);
                    return;
                }
                else InvoiceIns.Invoicenumber = Billno;
            }

            //Begin: Update SellItem
            Sellitem SellItemIns = new Sellitem();
            SellItemIns.Numberplate = txtPlateNo.Text.Trim();
            SellItemIns.Selltype = txtSellingType.Text.Trim();
            SellItemIns.Pricebeforetax = (!PriceTax.Equals("")) ? decimal.Parse(PriceTax) : 0;
            SellItemIns.Paymenttype = int.Parse(ddlPaymentMethod.SelectedValue);

            if (txtTakPlateNoDate.Text.Trim() != "")
            {
                SellItemIns.Numplaterecdate = DataFormat.DateFromString(txtTakPlateNoDate.Text);
            }
            else SellItemIns.Numplaterecdate = DateTime.MinValue;

            SellItemIns.Paymentdate = dtRecDate;
            SellItemIns.Commentsellitem = txtComment.Text.Trim();
            sess.SaveOrUpdate(SellItemIns);
            InvoiceIns.Sellitem = SellItemIns;
            //End: Update SellItem
            //Begin: Save Payment Method
            if (ddlPaymentMethod.SelectedValue.Equals(((int)CusPaymentType.UnFixedHire_purchase).ToString()))
            {
                TextBox txtIntentDatePay, UHPtxtMoney;
                Payment pmIns;
                for (int i = 1; i < 6; i++)
                {
                    try
                    {
                        txtIntentDatePay = (TextBox)UnfixedHP.FindControl("txtIntentDatePay" + i);
                        UHPtxtMoney = (TextBox)UnfixedHP.FindControl("UHPtxtMoney" + i);
                        pmIns = new Payment();
                        if (txtIntentDatePay.Text.Trim() != "" && UHPtxtMoney.Text.Trim() != "")
                        {
                            pmIns.Sellitem = SellItemIns;
                            pmIns.Paymentdate = DateTime.Parse(txtIntentDatePay.Text.Trim());
                            pmIns.Amount = decimal.Parse(UHPtxtMoney.Text.Trim());
                            pmIns.Status = 0;
                            sess.Save(pmIns);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            if (ddlPaymentMethod.SelectedValue.Equals(((int)CusPaymentType.FixedHire_purchase).ToString()))
            {
                BindAndSaveFHPPayment(ref sess, SellItemIns);
            }
            //End: Save Payment Method
            //Begin: Update ItemInstance
            Iteminstance ItmIns = sess.CreateCriteria(typeof(Iteminstance))
                                      .Add(Expression.Eq("Id", Int64.Parse(_ItemInstanceID.Value))).List()[0] as
                                  Iteminstance;
            ItmIns.Status = (int)ItemStatus.Sold;
            ItmIns.Releaseddate = dtSellDate;
            sess.SaveOrUpdate(ItmIns);
            if (PriceTax.Equals("")) PriceTax = "0";
            TransHis th =
                (new ItemHepler()).SaveTranHis(ItmIns, dtSellDate, ItemStatus.Sold,
                                               int.Parse(ddlPaymentMethod.SelectedValue), decimal.Parse(PriceTax),
                                               UserHelper.Username, null, UserHelper.FullBranchCode, null);
            sess.Save(th);

            // save to Inventory of Day
            InventoryHelper.SaveInventoryDay(ItmIns.Item.Id, dtSellDate, -1, (int)ItemStatus.Sold,
                                             UserHelper.DealerCode, UserHelper.BranchCode);

            InvoiceIns.Iteminstance = ItmIns;
            //End: Update ItemInstance
            //Begin: Customer Type
            Customer cusIns =
                sess.CreateCriteria(typeof(Customer)).Add(Expression.Eq("Id", Int64.Parse(_CustomerID.Value)))
                .List()[0] as Customer;
            InvoiceIns.Customer = cusIns;

            InvoiceIns.Enginenumber = ItmIns.Enginenumber;
            InvoiceIns.Dealercode = ItmIns.Dealercode;
            InvoiceIns.Branchcode = ItmIns.Branchcode;
            InvoiceIns.Createddate = DateTime.Now;
            InvoiceIns.Selldate = dtSellDate;
            InvoiceIns.Createdby = UserHelper.Username;
            sess.SaveOrUpdate(InvoiceIns);

            #region warrantyInfo
            //********** Save warranty info ***************
            WarrantyInfo warr = ServiceTools.GetWarrantyInfo(ItmIns.Enginenumber);
            if (warr == null)   // co roi thi thoi: yeu cau ngay 16/7/2008
            {
                //Clone new customer
                Customer csnew = new Customer(cusIns.Identifynumber, cusIns.Fullname, cusIns.Gender, cusIns.Birthdate, cusIns.Address, cusIns.Provinceid, cusIns.Districtid, cusIns.Jobtypeid, cusIns.Email, cusIns.Tel, cusIns.Mobile, (int)CusType.WarrantyInfo, cusIns.Customerdescription, cusIns.Precinct, cusIns.Priority, cusIns.Dealercode, false);
                sess.Save(csnew);

                if (ServiceTools.SaveWarrantyInfo(ItmIns.Enginenumber, 0, dtSellDate,
                ItmIns.Databasecode, ItmIns.Item.Id, ItmIns.Color, UserHelper.DealerCode, csnew.Id) == false)
                {
                    throw new Exception(Message.WarrantyContent_UpdateDataFailed);
                }
            }
            #endregion

            tx.Commit();
            ShowMessage(Message.ActionSucessful, false);

            RefreshAll();
            _PageStatus.Value = _DEFAULTPAGE;
        }
        catch (Exception ex)
        {
            if (!tx.WasRolledBack)
                tx.Rollback();
            ShowMessage(ex.Message, true);
        }
    }