void UserRights()
        {
            try
            {
                userPrevilage = new UserPrevilage(this.btnBank.Tag.ToString());
                if (userPrevilage.Show == true)
                {
                    btnBank.IsEnabled = true;
                }
                else
                {
                    btnBank.IsEnabled = false;
                }

                userPrevilage = new UserPrevilage(this.btnBranch.Tag.ToString());
                if (userPrevilage.Show == true)
                {
                    btnBranch.IsEnabled = true;
                }
                else
                {
                    btnBranch.IsEnabled = false;
                }

                userPrevilage = new UserPrevilage(this.btnNUBEBranch.Tag.ToString());
                if (userPrevilage.Show == true)
                {
                    btnNUBEBranch.IsEnabled = true;
                }
                else
                {
                    btnNUBEBranch.IsEnabled = false;
                }

                userPrevilage = new UserPrevilage(this.btnPersonTitle.Tag.ToString());
                if (userPrevilage.Show == true)
                {
                    btnPersonTitle.IsEnabled = true;
                }
                else
                {
                    btnPersonTitle.IsEnabled = false;
                }

                userPrevilage = new UserPrevilage(this.btnSalutation.Tag.ToString());
                if (userPrevilage.Show == true)
                {
                    btnSalutation.IsEnabled = true;
                }
                else
                {
                    btnSalutation.IsEnabled = false;
                }

                userPrevilage = new UserPrevilage(this.btnRelationSetup.Tag.ToString());
                if (userPrevilage.Show == true)
                {
                    btnRelationSetup.IsEnabled = true;
                }
                else
                {
                    btnRelationSetup.IsEnabled = false;
                }

                userPrevilage = new UserPrevilage(this.btnReasonSetup.Tag.ToString());
                if (userPrevilage.Show == true)
                {
                    btnReasonSetup.IsEnabled = true;
                }
                else
                {
                    btnReasonSetup.IsEnabled = false;
                }

                userPrevilage = new UserPrevilage(this.btnNameSetup.Tag.ToString());
                if (userPrevilage.Show == true)
                {
                    btnNameSetup.IsEnabled = true;
                }
                else
                {
                    btnNameSetup.IsEnabled = false;
                }

                userPrevilage = new UserPrevilage(this.btnCity.Tag.ToString());
                if (userPrevilage.Show == true)
                {
                    btnCity.IsEnabled = true;
                }
                else
                {
                    btnCity.IsEnabled = false;
                }

                userPrevilage = new UserPrevilage(this.btnStateSetup.Tag.ToString());
                if (userPrevilage.Show == true)
                {
                    btnStateSetup.IsEnabled = true;
                }
                else
                {
                    btnStateSetup.IsEnabled = false;
                }

                userPrevilage = new UserPrevilage(this.btnMonthEndClosing.Tag.ToString());
                if (userPrevilage.Show == true)
                {
                    btnMonthEndClosing.IsEnabled = true;
                }
                else
                {
                    btnMonthEndClosing.IsEnabled = false;
                }

                userPrevilage = new UserPrevilage(this.btnYearEndClosing.Tag.ToString());
                if (userPrevilage.Show == true)
                {
                    btnYearEndClosing.IsEnabled = true;
                }
                else
                {
                    btnYearEndClosing.IsEnabled = false;
                }
            }
            catch (Exception ex)
            {
                ExceptionLogging.SendErrorToText(ex);
            }
        }
        private void BgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                string DBPath = "";
                string str    = "";
                var    dt     = (from x in db.Tran_Start where x.EntryDate == DateTime.Today.Date select x).FirstOrDefault();
                if (dt == null)
                {
                    var qry = (from x in db.MASTERNAMESETUPs select x).FirstOrDefault();

                    // ######### VERSION 1 BACKUP ##############

                    if (qry.NEWEXEPATH != null)
                    {
                        str = qry.NEWEXEPATH.ToString();
                        if (str.Contains(".") == true)
                        {
                            string[] path = qry.NEWEXEPATH.Split('.');
                            DBPath = path[0];
                        }
                        else
                        {
                            DBPath = qry.NEWEXEPATH.ToString();
                        }

                        try
                        {
                            using (SqlConnection con = new SqlConnection(AppLib.connStr))
                            {
                                string sBack = " BACKUP DATABASE " + qry.NEWREPORTSPATH + " \r" +
                                               " TO DISK='" + DBPath.ToString() + string.Format("{0:ddMMMyyyy}", DateTime.Today) + ".bak'";
                                SqlCommand cmd = new SqlCommand(sBack, con);
                                cmd.Connection.Open();
                                cmd.CommandTimeout = 0;
                                cmd.ExecuteNonQuery();

                                sBack = " xp_cmdshell 'del " + DBPath.ToString() + string.Format("{0:ddMMMyyyy}", DateTime.Now.AddDays(-3)) + ".bak'";
                                cmd   = new SqlCommand(sBack, con);
                                cmd.CommandTimeout = 0;
                                cmd.ExecuteNonQuery();
                                cmd.Connection.Close();
                            }
                        }
                        catch (Exception ex)
                        {
                            ExceptionLogging.SendErrorToText(ex);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please Enter the Daily Backup Path Correctly!", "VERSION 1 Daily BackUp Error");
                    }

                    // ######### VERSION 2 BACKUP ##############

                    if (qry.BackUpPath != null)
                    {
                        str = qry.BackUpPath.ToString();
                        if (str.Contains(".") == true)
                        {
                            string[] path = qry.BackUpPath.Split('.');
                            DBPath = path[0];
                        }
                        else
                        {
                            DBPath = qry.BackUpPath.ToString();
                        }
                        try
                        {
                            using (SqlConnection con = new SqlConnection(AppLib.connStr))
                            {
                                string sBack = " BACKUP DATABASE " + con.Database + " \r" +
                                               " TO DISK='" + DBPath.ToString() + string.Format("{0:ddMMMyyyy}", DateTime.Today) + ".bak'";
                                SqlCommand cmd = new SqlCommand(sBack, con);
                                cmd.Connection.Open();
                                cmd.CommandTimeout = 0;
                                cmd.ExecuteNonQuery();

                                sBack = " xp_cmdshell 'del " + DBPath.ToString() + string.Format("{0:ddMMMyyyy}", DateTime.Now.AddDays(-3)) + ".bak'";
                                cmd   = new SqlCommand(sBack, con);
                                cmd.CommandTimeout = 0;
                                cmd.ExecuteNonQuery();
                                cmd.Connection.Close();
                            }
                        }
                        catch (Exception ex)
                        {
                            ExceptionLogging.SendErrorToText(ex);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please Enter the Daily Backup Path Correctly!", "VERSION 2 Daily BackUp Error");
                    }

                    var TS = (from x in db.Tran_Start where x.Id == 1 select x).FirstOrDefault();
                    if (TS != null)
                    {
                        TS.EntryDate   = DateTime.Now.Date;
                        TS.UserId      = AppLib.iUserCode;
                        TS.UpdatedTime = DateTime.Now;
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionLogging.SendErrorToText(ex);
            }
        }
        private void LoadReport()
        {
            try
            {
                MemberReport.Reset();
                DataTable dt = new DataTable();
                dt = getData();
                if (dt.Rows.Count > 0)
                {
                    string           Total      = dt.Rows.Count.ToString();
                    ReportDataSource masterData = new ReportDataSource("ActiveMember", dt);

                    MemberReport.LocalReport.DataSources.Add(masterData);
                    ReportDataSource Data = new ReportDataSource("DataSet1", dt);

                    MemberReport.LocalReport.DataSources.Add(Data);
                    MemberReport.LocalReport.ReportEmbeddedResource = "Nube.Reports.frmActiveMemberReport.rdlc";
                    ReportParameter[] NB = new ReportParameter[5];
                    if (!string.IsNullOrEmpty(cmbNubeBranch.Text))
                    {
                        NB[0] = new ReportParameter("NubeBranchName", "NUBE BRANCH - " + cmbNubeBranch.Text.ToString());
                    }
                    else
                    {
                        NB[0] = new ReportParameter("NubeBranchName", "");
                    }

                    if (!string.IsNullOrEmpty(cmbBank.Text))
                    {
                        NB[1] = new ReportParameter("BankName", "BANK - " + cmbBank.Text.ToString());
                    }
                    else
                    {
                        NB[1] = new ReportParameter("BankName", "");
                    }


                    if (!string.IsNullOrEmpty(cmbBranch.Text))
                    {
                        NB[2] = new ReportParameter("BranchName", "BANK BRANCH - " + cmbBranch.Text.ToString());
                    }
                    else
                    {
                        NB[2] = new ReportParameter("BranchName", "");
                    }
                    NB[3] = new ReportParameter("TotalMember", Total);

                    if (sForm_Name == "NewMemberReport")
                    {
                        NB[4] = new ReportParameter("Title", "NEW MEMBER REPORT");
                    }
                    else
                    {
                        NB[4] = new ReportParameter("Title", "ACTIVE MEMBER REPORT");
                    }

                    MemberReport.LocalReport.SetParameters(NB);
                    MemberReport.RefreshReport();
                    LoadBankReport(dt);
                }
                else
                {
                    MessageBox.Show("No Records Found!");
                }
            }
            catch (Exception ex)
            {
                ExceptionLogging.SendErrorToText(ex);
            }
        }
        private void txtMemberID_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.Key == Key.Enter && !string.IsNullOrEmpty(txtMemberID.Text))
                {
                    decimal dMemberId = Convert.ToDecimal(txtMemberID.Text);
                    var     mm        = (from x in dbBFS.TVMASTERMEMBERs where x.MEMBER_ID == dMemberId select x).FirstOrDefault();

                    if (mm != null)
                    {
                        dgvDetails.ItemsSource  = null;
                        txtBankName.Text        = mm.BANK_USERCODE;
                        txtBranchkName.Text     = mm.BRANCHNAME;
                        dtpDOJ.SelectedDate     = mm.DATEOFJOINING;
                        txtType.Text            = mm.MEMBERTYPE_NAME;
                        txtMonthlyBF.Text       = mm.MONTHLYBF.ToString();
                        txtMonthlySub.Text      = mm.MONTHLYSUBSCRIPTION.ToString();
                        txtMemberName.Text      = mm.MEMBER_NAME.ToString();
                        txtStatus.Text          = mm.MEMBERSTATUS.ToString();
                        txtLastPaymentDate.Text = string.Format("{0:MMM-yyyy}", mm.LASTPAYMENT_DATE);


                        using (SqlConnection con = new SqlConnection(AppLib.connStr))
                        {
                            progressBar1.Minimum    = 1;
                            progressBar1.Maximum    = 10;
                            progressBar1.Visibility = Visibility.Visible;
                            con.Open();
                            progressBar1.Value = 2;
                            System.Windows.Forms.Application.DoEvents();
                            SqlCommand cmd = new SqlCommand("SPMEMBERHISTORY", con);
                            cmd.CommandType = CommandType.StoredProcedure;
                            cmd.Parameters.Add(new SqlParameter("@MEMBER_CODE", mm.MEMBER_CODE));
                            progressBar1.Value = 5;
                            System.Windows.Forms.Application.DoEvents();
                            SqlDataAdapter adp = new SqlDataAdapter(cmd);
                            adp.SelectCommand.CommandTimeout = 0;
                            DataTable dt = new DataTable();
                            adp.Fill(dt);
                            progressBar1.Value = 7;
                            System.Windows.Forms.Application.DoEvents();
                            if (dt.Rows.Count > 0)
                            {
                                progressBar1.Value = 9;
                                System.Windows.Forms.Application.DoEvents();
                                dgvDetails.ItemsSource = dt.DefaultView;
                            }
                            else
                            {
                                MessageBox.Show("No Data Found");
                            }
                            progressBar1.Value = 10;
                            System.Windows.Forms.Application.DoEvents();
                            progressBar1.Visibility = Visibility.Hidden;
                        }
                    }
                    else
                    {
                        txtBankName.Text        = "";
                        txtBranchkName.Text     = "";
                        dtpDOJ.Text             = "";
                        txtType.Text            = "";
                        txtMonthlyBF.Text       = "";
                        txtMonthlySub.Text      = "";
                        txtMemberName.Text      = "";
                        txtStatus.Text          = "";
                        txtLastPaymentDate.Text = "";
                        MessageBox.Show("No Data Found", "Invalid Membership");
                        progressBar1.Visibility = Visibility.Hidden;
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionLogging.SendErrorToText(ex);
                progressBar1.Visibility = Visibility.Hidden;
            }
        }