Beispiel #1
0
 private void btnEditOldDue_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (dMember_Code != 0)
         {
             ArrearPostMaster mst = (from mas in db.ArrearPostMasters where mas.MemberCode == dMember_Code select mas).FirstOrDefault();
             if (mst != null)
             {
                 frmArrearDueList frm = new frmArrearDueList(dMember_Code, "PostArrear", txtMemberType.Text, txtMemberName.Text, txtMemberNo.Text);
                 this.Close();
                 frm.ShowDialog();
             }
             else
             {
                 MessageBox.Show("No Data Found!");
                 txtMemberNo.Focus();
             }
         }
         else
         {
             MessageBox.Show("Please Enter the Membership No!");
             txtMemberNo.Focus();
         }
     }
     catch (Exception ex)
     {
         ExceptionLogging.SendErrorToText(ex);
     }
 }
Beispiel #2
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                bValidation = false;
                BeforeUpdate();
                if (bValidation == false)
                {
                    MASTERMEMBER mmMst = (from mas in db.MASTERMEMBERs where mas.MEMBER_CODE == dMember_Code select mas).FirstOrDefault();

                    if (bUpdate == false)
                    {
                        DataView dv = new DataView(dtArrearPost);
                        dv.RowFilter = "AMOUNT>0";
                        int iTotalDuePay = dv.Count;

                        ArrearPostMaster arrearMaster = new ArrearPostMaster
                        {
                            MemberCode              = dMember_Code,
                            EntryDate               = DateTime.Now,
                            BeforeLastPaymentDate   = mmMst.LASTPAYMENT_DATE,
                            BeforeTotalBF           = mmMst.ACCBF,
                            BeforeTotalSubscription = mmMst.ACCSUBSCRIPTION,
                            BeforeTotalMonthsPaid   = Convert.ToInt32(mmMst.TOTALMONTHSPAID),
                            TotalDuePay             = iTotalDuePay,
                            UpdatedStatus           = "Not Updated"
                        };
                        db.ArrearPostMasters.Add(arrearMaster);
                        db.SaveChanges();

                        var NewData = new JSonHelper().ConvertObjectToJSon(arrearMaster);
                        AppLib.EventHistory(this.Tag.ToString(), 0, "", NewData, "ArrearPostMaster");

                        DataTable dtTemp = new DataTable();
                        dtTemp = ((DataView)dgArrearPost.ItemsSource).ToTable();
                        var iMasterId = Convert.ToInt32(db.ArrearPostMasters.Max(x => x.ID));

                        List <ArrearPostDetail> lstArrearDtl = new List <ArrearPostDetail>();

                        foreach (DataRow row in dtTemp.Rows)
                        {
                            if (Convert.ToDecimal(row["AMOUNT"]) != 0)
                            {
                                ArrearPostDetail arrearDtl = new ArrearPostDetail
                                {
                                    MasterId           = iMasterId,
                                    Year               = Convert.ToInt32(row["YEAR"]),
                                    Month              = Convert.ToDateTime("1/" + row["MONTH"] + row["YEAR"]).Month,
                                    TotalAmount        = Convert.ToDecimal(row["AMOUNT"]),
                                    AmounBF            = Convert.ToDecimal(row["BF"]),
                                    AmountInsurance    = Convert.ToDecimal(row["INSURANCE"]),
                                    AmountSubscription = Convert.ToDecimal(row["SUBSCRIPTION"]),
                                    UpdatedStatus      = "Not Updated",
                                    MemberCode         = Convert.ToInt32(dMember_Code)
                                };
                                lstArrearDtl.Add(arrearDtl);
                            }
                        }

                        if (lstArrearDtl.Count > 0)
                        {
                            db.ArrearPostDetails.AddRange(lstArrearDtl);
                            db.SaveChanges();

                            var NewData1 = new JSonHelper().ConvertObjectToJSon(lstArrearDtl);
                            AppLib.EventHistory(this.Tag.ToString(), 0, "", NewData1, "ArrearPostDetail");
                        }

                        MessageBox.Show("Details are Saved Sucessfully");
                        fClear();
                    }
                    else
                    {
                        ArrearPostMaster mst = (from mas in db.ArrearPostMasters where mas.ID == iArrearMst_ID select mas).FirstOrDefault();

                        var      OldData = new JSonHelper().ConvertObjectToJSon(mst);
                        DataView dv      = new DataView(dtArrearPost);
                        dv.RowFilter = "AMOUNT>0";
                        int iTotalDuePay = dv.Count;

                        if (mst != null)
                        {
                            mst.UpdatedEntryDate = DateTime.Now;
                            mst.IsEdited         = true;
                            mst.TotalDuePay      = iTotalDuePay;
                        }
                        db.SaveChanges();

                        var NewData = new JSonHelper().ConvertObjectToJSon(mst);
                        AppLib.EventHistory(this.Tag.ToString(), 1, OldData, NewData, "ArrearPostMaster");

                        ArrearPostDetail dtl = (from mas in db.ArrearPostDetails where mas.MasterId == iArrearMst_ID select mas).FirstOrDefault();
                        var OldData1         = new JSonHelper().ConvertObjectToJSon(dtl);
                        if (dtl != null)
                        {
                            db.ArrearPostDetails.RemoveRange(db.ArrearPostDetails.Where(x => x.MasterId == iArrearMst_ID));
                            db.SaveChanges();
                        }

                        DataTable dtTemp = new DataTable();
                        dtTemp = ((DataView)dgArrearPost.ItemsSource).ToTable();

                        List <ArrearPostDetail> lstArrearDtl = new List <ArrearPostDetail>();

                        foreach (DataRow row in dtTemp.Rows)
                        {
                            if (Convert.ToDecimal(row["AMOUNT"]) != 0)
                            {
                                ArrearPostDetail arrearDtl = new ArrearPostDetail
                                {
                                    MasterId           = iArrearMst_ID,
                                    Year               = Convert.ToInt32(row["YEAR"]),
                                    Month              = Convert.ToDateTime("1/" + row["MONTH"] + row["YEAR"]).Month,
                                    TotalAmount        = Convert.ToDecimal(row["AMOUNT"]),
                                    AmounBF            = Convert.ToDecimal(row["BF"]),
                                    AmountInsurance    = Convert.ToDecimal(row["INSURANCE"]),
                                    AmountSubscription = Convert.ToDecimal(row["SUBSCRIPTION"]),
                                    UpdatedStatus      = "Not Updated",
                                    MemberCode         = Convert.ToInt32(dMember_Code)
                                };
                                lstArrearDtl.Add(arrearDtl);
                            }
                        }

                        if (lstArrearDtl.Count > 0)
                        {
                            db.ArrearPostDetails.AddRange(lstArrearDtl);
                            db.SaveChanges();

                            var NewData1 = new JSonHelper().ConvertObjectToJSon(lstArrearDtl);
                            AppLib.EventHistory(this.Tag.ToString(), 1, OldData1, NewData1, "ArrearPostDetail");
                        }

                        MessageBox.Show("Details are Updated Sucessfully");
                        fClear();
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionLogging.SendErrorToText(ex);
            }
        }