public Acc_ChartOfAccount GetAcc_ChartOfAccountBalance(long chartOfAccountID)
        {
            List <Acc_TransactionDetail> transactionDetailList = GetLedgerBalanceByChartOfAccountID(chartOfAccountID);
            Acc_ChartOfAccount           chartOfAccount        = GetAcc_ChartOfAccountByID(chartOfAccountID);
            Decimal balance = 0;

            foreach (Acc_TransactionDetail td in transactionDetailList)
            {
                if (chartOfAccount.Acc_Class.AccountNature == Convert.ToInt32(EnumCollection.TransactionNature.Debit))
                {
                    if (chartOfAccount.Acc_Class.AccountNature == td.TransactionNature)
                    {
                        balance -= td.Amount;
                    }
                    else
                    {
                        balance += td.Amount;
                    }
                }
                else if (chartOfAccount.Acc_Class.AccountNature == Convert.ToInt32(EnumCollection.TransactionNature.Credit))
                {
                    if (chartOfAccount.Acc_Class.AccountNature == td.TransactionNature)
                    {
                        balance -= td.Amount;
                    }
                    else
                    {
                        balance += td.Amount;
                    }
                }
            }
            chartOfAccount.Balance = balance;
            return(chartOfAccount);
        }
        public Acc_ChartOfAccount GetAcc_ChartOfAccountByParentID(long parentid)
        {
            Acc_ChartOfAccount cacc = new Acc_ChartOfAccount();

            cacc = Database.Acc_ChartOfAccounts.Where(c => c.ParentID == parentid && c.IsRemoved == 0).FirstOrDefault();
            if (cacc != null)
            {
                cacc.Acc_Class = cacc.Acc_Class;
            }
            return(cacc);
        }
        public Acc_ChartOfAccount GetAcc_ChartOfAccountByID(long id)
        {
            Acc_ChartOfAccount cacc = new Acc_ChartOfAccount();

            try
            {
                cacc = Database.Acc_ChartOfAccounts.Single(c => c.IID == id && c.IsRemoved == 0);
            }
            catch (Exception ex)
            {
            }
            return(cacc);
        }
        public Acc_ChartOfAccount GetChartOfAccountByName(string name)
        {
            Acc_ChartOfAccount cacc = new Acc_ChartOfAccount();

            try
            {
                cacc           = Database.Acc_ChartOfAccounts.Where(c => c.Name == name && c.IsRemoved == 0).FirstOrDefault();
                cacc.Acc_Class = cacc.Acc_Class;
            }
            catch (Exception ex)
            {
            }
            return(cacc);
        }
        public Acc_ChartOfAccount GetAcc_ChartOfAccountByAccountNo(string accountNo)
        {
            Acc_ChartOfAccount cacc = new Acc_ChartOfAccount();

            try
            {
                cacc           = Database.Acc_ChartOfAccounts.Single(c => c.AccountNo == accountNo && c.IsRemoved == 0);
                cacc.Acc_Class = cacc.Acc_Class;
                Acc_ChartOfAccount parentCOA = GetAcc_ChartOfAccountByID(cacc.ParentID);
                cacc.ParentChartOfAccount = parentCOA;
            }
            catch (Exception ex)
            {
            }
            return(cacc);
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //if (Session["BranchID"] != null)
            //{

            try
            {
                if (CurrentMemberID > 0)
                {
                    using (TheFacade facade = new TheFacade())
                    {
                        Member member = facade.MemberFacade.GetMemberById(CurrentMemberID);
                        if (member != null && member.MemberVerificationStatus == (int)EnumCollection.VerificationStatus.Approved_for_Committee_Meeting)
                        {
                            member.MemberVerificationStatus = (int)EnumCollection.VerificationStatus.Completed;
                            member.MembershipStatus         = (int)EnumCollection.MembershipStatus.Approved;
                            DateTime expireDate = new DateTime(DateTime.Now.Year, 6, 30);
                            if (DateTime.Now.Date > expireDate)
                            {
                                expireDate = expireDate.AddYears(1);
                            }
                            try
                            {
                                expireDate = Convert.ToDateTime(txtExpireDate.Text);
                            }
                            catch (Exception ex)
                            {
                            }
                            member.MembershipCode = txtMembershipCode.Text;

                            facade.Update <Member>(member);
                            Ins_MembershipExpireInfo info = new Ins_MembershipExpireInfo();
                            info.MemberID   = member.ID;
                            info.ExpireDate = expireDate.Date;
                            info.CreateBy   = 1;
                            info.CreateDate = DateTime.Now;
                            info.UpdateBy   = 1;
                            info.UpdateDate = DateTime.Now;
                            info.IsRemoved  = 0;
                            facade.Insert <Ins_MembershipExpireInfo>(info);
                            Ins_MemberVerification memberVerification = facade.MemberFacade.GetMemberVerificationByMemberID(member.ID);
                            if (memberVerification != null)
                            {
                                memberVerification.Status = (int)EnumCollection.VerificationStatus.Completed;
                                facade.Update <Ins_MemberVerification>(memberVerification);
                            }

                            Acc_ChartOfAccount       chartofAcc      = facade.AccountsFacade.GetAcc_ChartOfAccountByName("Account Receivable");
                            Acc_ChartOfAccountMember customerAccount = new Acc_ChartOfAccountMember();

                            #region acc
                            Acc_ChartOfAccount newAccount = new Acc_ChartOfAccount();
                            newAccount.AccountNo = GenerateAccountNo(chartofAcc.Gparent.ToString());
                            newAccount.Name      = member.Name;
                            newAccount.IsActive  = 1;

                            newAccount.AccountTypeID  = Convert.ToInt32(EnumCollection.AccountType.Transactable);
                            newAccount.ParentID       = chartofAcc.IID;
                            newAccount.Gparent        = chartofAcc.Gparent;
                            newAccount.OpeningBalance = Convert.ToDecimal(txtOpeningBalance.Text);
                            newAccount.CreateBy       = 1;

                            newAccount.UpdateBy = 1;


                            newAccount.CreateDate = DateTime.Now;

                            newAccount.UpdateDate = DateTime.Now;
                            newAccount.IsRemoved  = 0;
                            facade.Insert <Acc_ChartOfAccount>(newAccount);

                            #endregion

                            customerAccount.ChartofAccountID = newAccount.IID;
                            customerAccount.MemberID         = member.ID;
                            customerAccount.UpdateDate       = DateTime.Now;
                            customerAccount.UpdateBy         = 1;


                            customerAccount.CreateDate = DateTime.Now;
                            customerAccount.CreateBy   = 1;

                            customerAccount.IsRemoved = 0;
                            facade.Insert <Acc_ChartOfAccountMember>(customerAccount);
                        }

                        else
                        {
                            Session["duplicate"] = true;
                        }
                    }
                }
                else
                {
                    using (TheFacade facade = new TheFacade())
                    {
                    }
                }
                Session["IsSaved"] = true;
            }
            catch
            {
                Session["IsSaved"] = false;
            }
            finally
            {
                Response.Redirect(Request.Url.ToString());
            }
            //}
            //else
            //{
            //    FormsAuthentication.SignOut();
            //    Roles.DeleteCookie();
            //    Session.Abandon();
            //    Response.Redirect("~/login.aspx");
            //}
        }
        //Account Number Generate
        public long GetMemberForAccount(long CurrentMemberID)
        {
            try
            {
                if (CurrentMemberID > 0)
                {
                    using (TheFacade facade = new TheFacade())
                    {
                        Member member = facade.MemberFacade.GetMemberById(CurrentMemberID);
                        if (member != null)
                        {
                            member.MemberVerificationStatus = (int)EnumCollection.VerificationStatus.Completed;
                            member.MembershipStatus         = (int)EnumCollection.MembershipStatus.Approved;
                            DateTime expireDate = new DateTime(DateTime.Now.Year, 6, 30);
                            if (DateTime.Now.Date > expireDate)
                            {
                                expireDate = expireDate.AddYears(1);
                            }
                            try
                            {
                                expireDate = Convert.ToDateTime(txtExpireDate.Text);
                            }
                            catch (Exception ex)
                            {
                            }
                            member.MembershipCode = txtMembershipCode.Text;

                            facade.Update <Member>(member);
                            Ins_MembershipExpireInfo info = new Ins_MembershipExpireInfo();
                            info.MemberID   = member.ID;
                            info.ExpireDate = expireDate.Date;
                            info.CreateBy   = 1;
                            info.CreateDate = DateTime.Now;
                            info.UpdateBy   = 1;
                            info.UpdateDate = DateTime.Now;
                            info.IsRemoved  = 0;
                            facade.Insert <Ins_MembershipExpireInfo>(info);
                            Ins_MemberVerification memberVerification = facade.MemberFacade.GetMemberVerificationByMemberID(member.ID);
                            if (memberVerification != null)
                            {
                                memberVerification.Status = (int)EnumCollection.VerificationStatus.Completed;
                                facade.Update <Ins_MemberVerification>(memberVerification);
                            }

                            Acc_ChartOfAccount       chartofAcc      = facade.AccountsFacade.GetAcc_ChartOfAccountByName("Account Receivable");
                            Acc_ChartOfAccountMember customerAccount = new Acc_ChartOfAccountMember();

                            #region acc
                            Acc_ChartOfAccount newAccount = new Acc_ChartOfAccount();
                            newAccount.AccountNo = GenerateAccountNo(chartofAcc.Gparent.ToString());
                            newAccount.Name      = member.Name;
                            newAccount.IsActive  = 1;

                            newAccount.AccountTypeID  = Convert.ToInt32(EnumCollection.AccountType.Transactable);
                            newAccount.ParentID       = chartofAcc.IID;
                            newAccount.Gparent        = chartofAcc.Gparent;
                            newAccount.OpeningBalance = Convert.ToDecimal(txtOpeningBalance.Text);
                            newAccount.CreateBy       = 1;

                            newAccount.UpdateBy = 1;


                            newAccount.CreateDate = DateTime.Now;

                            newAccount.UpdateDate = DateTime.Now;
                            newAccount.IsRemoved  = 0;
                            facade.Insert <Acc_ChartOfAccount>(newAccount);

                            #endregion

                            customerAccount.ChartofAccountID = newAccount.IID;
                            customerAccount.MemberID         = member.ID;
                            customerAccount.UpdateDate       = DateTime.Now;
                            customerAccount.UpdateBy         = 1;


                            customerAccount.CreateDate = DateTime.Now;
                            customerAccount.CreateBy   = 1;

                            customerAccount.IsRemoved = 0;
                            facade.Insert <Acc_ChartOfAccountMember>(customerAccount);
                        }

                        else
                        {
                            Session["duplicate"] = true;
                        }
                    }
                }
                else
                {
                    using (TheFacade facade = new TheFacade())
                    {
                    }
                }
                Session["IsSaved"] = true;
            }
            catch
            {
                Session["IsSaved"] = false;
            }
            finally
            {
                Response.Redirect(Request.Url.ToString());
            }

            lablmessage.Text = " Registration & Account  Create Succesfully";

            return(CurrentMemberID);
        }