示例#1
0
 public bool IsBadContract(int contractId)
 {
     using (var db = new RentBikeEntities())
     {
         return(CommonList.IsBadContract(db, contractId));
     }
 }
        private void LoadData(string strSearch, int page)
        {
            // LOAD PAGER
            using (var db = new RentBikeEntities())
            {
                var dataList = (from c in db.RentTypes
                                select c);

                int totalRecord = dataList.Count();
                int totalPage = totalRecord % pageSize == 0 ? totalRecord / pageSize : totalRecord / pageSize + 1;

                IEnumerable<int> pageList = Enumerable.Range(1, totalPage);
                ddlPager.DataSource = pageList;
                ddlPager.DataBind();

                if (pageList.Count() > 0)
                    ddlPager.SelectedIndex = page;

                // LOAD DATA WITH PAGING
                int skip = page * pageSize;
                dataList = dataList.Skip(skip).Take(pageSize);
                rptRentType.DataSource = dataList.ToList();
                rptRentType.DataBind();
            }
        }
示例#3
0
        private void LoadInOutType()
        {
            List <InOutType> lst = new List <InOutType>();

            using (var db = new RentBikeEntities())
            {
                var item = from itm in db.InOutTypes
                           where itm.IS_CONTRACT == false && itm.ACTIVE == true
                           select itm;

                lst = item.ToList();

                if (lst.Count > 0)
                {
                    ddlInOutFee.Items.Add(new ListItem {
                        Text = "Hãy chọn loại chi phí", Value = "-1"
                    });
                    foreach (var data in lst)
                    {
                        ddlInOutFee.Items.Add(new ListItem {
                            Text = data.NAME, Value = data.ID.ToString()
                        });
                    }
                    if (inOutId != 0)
                    {
                        var io = db.InOuts.FirstOrDefault(c => c.ID == inOutId);
                        ddlInOutFee.SelectedValue = io.INOUT_TYPE_ID.ToString();
                    }
                }
            }
        }
示例#4
0
        private void LoadUser(string user)
        {
            using (var db = new RentBikeEntities())
            {
                var acc = (from s in db.Accounts
                           where s.ACC == user && s.ACTIVE == true
                           select s).FirstOrDefault();

                if (acc.STORE_ID != 0)
                {
                    var item = db.Stores.FirstOrDefault(s => s.ID == acc.STORE_ID);
                    if (item != null)
                    {
                        Session["store_name"] = item.NAME;
                    }
                }
                else
                {
                    Session["store_name"] = string.Empty;
                }

                Session["username"]   = acc.ACC;
                Session["name"]       = acc.NAME;
                Session["permission"] = acc.PERMISSION_ID;
                Session["city_id"]    = acc.CITY_ID;
                Session["store_id"]   = acc.STORE_ID;
            }
        }
        private List<CONTRACT_FULL_VW> GetMiddleContract(int STORE_ID, string startDate, string endDate)
        {
            using (var db = new RentBikeEntities())
            {
                var listContract = db.CONTRACT_FULL_VW.Where(c => c.CONTRACT_STATUS == true && c.ACTIVE == true).ToList();
                if (STORE_ID != 0)
                {
                    listContract = listContract.Where(c => c.STORE_ID == STORE_ID).ToList();
                }
                if (!string.IsNullOrEmpty(startDate) && !string.IsNullOrEmpty(endDate))
                {
                    listContract = listContract.Where(c => c.CREATED_DATE >= Convert.ToDateTime(startDate) && c.CREATED_DATE <= Convert.ToDateTime(endDate)).ToList();
                }
                else if (!string.IsNullOrEmpty(startDate) && string.IsNullOrEmpty(endDate))
                {
                    listContract = listContract.Where(c => c.CREATED_DATE >= Convert.ToDateTime(startDate)).ToList();
                }
                else if (string.IsNullOrEmpty(startDate) && !string.IsNullOrEmpty(endDate))
                {
                    listContract = listContract.Where(c => c.CREATED_DATE <= Convert.ToDateTime(endDate)).ToList();
                }

                return listContract;
            }
        }
示例#6
0
        private void LoadData(string strSearch, int page)
        {
            using (var db = new RentBikeEntities())
            {
                IQueryable <CONTRACT_HISTORY_FULL_VW> dataList = db.CONTRACT_HISTORY_FULL_VW.OrderByDescending(c => c.CREATED_DATE);

                if (STORE_ID != 0)
                {
                    dataList = dataList.Where(c => c.STORE_ID == STORE_ID);
                }

                if (!string.IsNullOrEmpty(strSearch))
                {
                    dataList = dataList.Where(c => c.SEARCH_TEXT.ToLower().Contains(strSearch.ToLower()) ||
                                              c.CUSTOMER_NAME.ToLower().Contains(strSearch.ToLower()));
                }

                int totalRecord            = dataList.Count();
                int totalPage              = totalRecord % pageSize == 0 ? totalRecord / pageSize : totalRecord / pageSize + 1;
                IEnumerable <int> pageList = Enumerable.Range(1, totalPage);

                ddlPager.DataSource = pageList;
                ddlPager.DataBind();
                if (pageList.Count() > 0)
                {
                    ddlPager.SelectedIndex = page;
                }

                int skip = page * pageSize;
                dataList = dataList.Skip(skip).Take(pageSize);
                rptContractHistory.DataSource = dataList.ToList();
                rptContractHistory.DataBind();
            }
        }
        private void LoadStoreById(string id)
        {
            int storeid = Convert.ToInt32(id);
            List<Store> lst;
            using (var db = new RentBikeEntities())
            {
                var st = from s in db.Stores
                         where s.ID == storeid
                         select s;

                lst = st.ToList<Store>();
            }

            Store store = lst[0];
            txtName.Text = store.NAME;
            txtAddress.Text = store.ADDRESS;
            ddlCity.SelectedValue = store.CITY_ID.ToString();
            txtPhone.Text = store.PHONE;
            txtStartCapital.Text = store.START_CAPITAL.ToString(); // Common.CommonList.FormatedAsCurrency(Convert.ToInt32(store.START_CAPITAL));
            txtCurrentCapital.Text = store.CURRENT_CAPITAL.ToString();
            txtApplyDate.Text = store.APPLY_DATE.ToShortDateString();
            txtTotalRevenueBefore.Text = store.REVENUE_BEFORE_APPLY.ToString();
            txtTotalCostBefore.Text = store.TOTAL_COST_BEFORE.ToString();
            txtTotalInvesmentBefore.Text = store.TOTAL_INVESMENT_BEFORE.ToString();
            txtRegisterDate.Text = store.REGISTER_DATE.ToShortDateString();
            rdbActive.Checked = store.ACTIVE;
            rdbDeActive.Checked = !rdbActive.Checked;
            txtNote.Text = store.NOTE;
        }
        private void UpdateStore(string id)
        {
            using (var db = new RentBikeEntities())
            {
                int storeid = Convert.ToInt32(id);
                var st = (from s in db.Stores
                          where s.ID == storeid
                          select s).FirstOrDefault();

                st.NAME = txtName.Text.Trim();
                st.ADDRESS = txtAddress.Text.Trim();
                st.CITY_ID = Convert.ToInt32(ddlCity.SelectedValue);
                st.PHONE = txtPhone.Text.Trim();
                st.FAX = string.Empty;
                st.START_CAPITAL = Convert.ToDecimal(txtStartCapital.Text);
                st.CURRENT_CAPITAL = Convert.ToDecimal(txtCurrentCapital.Text);
                //st.APPLY_DATE = Convert.ToDateTime(txtApplyDate.Text.Trim());
                //st.REVENUE_BEFORE_APPLY = Convert.ToDecimal(txtTotalRevenueBefore.Text);
                //st.TOTAL_COST_BEFORE = Convert.ToDecimal(txtTotalCostBefore.Text);
                //st.TOTAL_INVESMENT_BEFORE = Convert.ToDecimal(txtTotalInvesmentBefore.Text);
                st.REGISTER_DATE = Convert.ToDateTime(txtRegisterDate.Text.Trim());
                st.ACTIVE = rdbActive.Checked;
                st.NOTE = txtNote.Text.Trim();
                st.SEARCH_TEXT = string.Format("{0} {1} {2}", st.NAME, st.ADDRESS, st.PHONE);

                db.SaveChanges();


                var storefee = db.StoreFees.FirstOrDefault(s =>s.STORE_ID == storeid);
                storefee.FEE_PERCENT = 0;
                db.SaveChanges();
            }

            WriteLog(Constants.ACTION_UPDATE_STORE, false);
        }
        private List <INOUT_FULL_VW> GetMiddleInOut(int STORE_ID, string startDate, string endDate)
        {
            using (var db = new RentBikeEntities())
            {
                var listInOut = db.INOUT_FULL_VW.Where(c => c.ACTIVE == true);
                if (STORE_ID != 0)
                {
                    listInOut = listInOut.Where(c => c.STORE_ID == STORE_ID);
                }

                if (!string.IsNullOrEmpty(startDate) && !string.IsNullOrEmpty(endDate))
                {
                    listInOut = listInOut.Where(c => c.INOUT_DATE >= Convert.ToDateTime(startDate) && c.INOUT_DATE <= Convert.ToDateTime(endDate));
                }
                else if (!string.IsNullOrEmpty(startDate) && string.IsNullOrEmpty(endDate))
                {
                    listInOut = listInOut.Where(c => c.INOUT_DATE >= Convert.ToDateTime(startDate));
                }
                else if (string.IsNullOrEmpty(startDate) && !string.IsNullOrEmpty(endDate))
                {
                    listInOut = listInOut.Where(c => c.INOUT_DATE <= Convert.ToDateTime(endDate));
                }

                return(listInOut.ToList());
            }
        }
        private void LoadGeneralInfo()
        {
            int     rentbikeNo                  = GetNoRentBikeContract();
            int     rentequipNo                 = GetNoRentOfficeEquipContract();
            int     rentotherNo                 = GetNoRentOtherContract();
            int     notFinishContract           = GetNoOfNotFinishedContract();
            decimal totalmoneynotfinishContract = GetAmountOfNotFinishedContract();

            lblRentBikeNo.Text      = rentbikeNo == 0 ? "0" : string.Format("{0:0,0}", rentbikeNo);
            lblRentOfficeEquip.Text = rentequipNo == 0 ? "0" : string.Format("{0:0,0}", rentequipNo);
            lblRentOther.Text       = rentotherNo == 0 ? "0" : string.Format("{0:0,0}", rentotherNo);

            lblTotalBikeContractAmount.Text  = TotalAmountBikeContract == 0 ? "0" : string.Format("{0:0,0}", TotalAmountBikeContract);
            lblTotalEquipContractAmount.Text = TotalAmountEquipContract == 0 ? "0" : string.Format("{0:0,0}", TotalAmountEquipContract);
            lblTotalOtherContractAmount.Text = TotalAmountOtherContract == 0 ? "0" : string.Format("{0:0,0}", TotalAmountOtherContract);

            lblNotFinishedContract.Text           = notFinishContract == 0 ? "0" : string.Format("{0:0,0}", notFinishContract);
            lblTotalMoneyOfNotFinishContract.Text = totalmoneynotfinishContract == 0 ? "0" : string.Format("{0:0,0}", totalmoneynotfinishContract);
            lblTotalFeeContract.Text = TotalFeeBike + TotalFeeEquip + TotalFeeOther == 0 ? "0" : string.Format("{0:0,0}", TotalFeeBike + TotalFeeEquip + TotalFeeOther);

            drpRentType.Items.Clear();
            drpRentType.Items.Add(new ListItem("Tất cả", ""));
            using (var db = new RentBikeEntities())
            {
                foreach (RentType rentType in db.RentTypes.ToList())
                {
                    drpRentType.Items.Add(new ListItem(rentType.NAME, rentType.ID.ToString()));
                }
            }
        }
        private void LoadData(int storeId, string strSearch, int page)
        {
            // LOAD PAGER
            using (var db = new RentBikeEntities())
            {
                listStore = db.Stores.ToList();
                listPermission = db.AccountPermissions.ToList();

                IQueryable<Account> accList = db.Accounts;

                if (storeId != 0)
                    accList = accList.Where(c => c.STORE_ID == storeId);

                if(!string.IsNullOrEmpty(strSearch))
                    accList = accList.Where(c =>c.SEARCH_TEXT.ToLower().Contains(strSearch.ToLower()));

                var result = accList.ToList();
                int totalRecord = result.Count;
                int totalPage = totalRecord % pageSize == 0 ? totalRecord / pageSize : totalRecord / pageSize + 1;

                IEnumerable<int> pageList = Enumerable.Range(1, totalPage);
                ddlPager.DataSource = pageList;
                ddlPager.DataBind();

                if (pageList.Count() > 0)
                    ddlPager.SelectedIndex = page;

                // LOAD DATA WITH PAGING
                int skip = page * pageSize;
                result = result.Skip(skip).Take(pageSize).ToList();

                rptAccount.DataSource = result;
                rptAccount.DataBind();
            }
        }
        private void LoadData(string strSearch, int page)
        {
            using (var db = new RentBikeEntities())
            {
                IQueryable<CONTRACT_HISTORY_FULL_VW> dataList = db.CONTRACT_HISTORY_FULL_VW.OrderByDescending(c => c.CREATED_DATE);

                if (STORE_ID != 0)
                    dataList = dataList.Where(c => c.STORE_ID == STORE_ID);

                if (!string.IsNullOrEmpty(strSearch))
                    dataList = dataList.Where(c => c.SEARCH_TEXT.ToLower().Contains(strSearch.ToLower())
                        || c.CUSTOMER_NAME.ToLower().Contains(strSearch.ToLower()));

                int totalRecord = dataList.Count();
                int totalPage = totalRecord % pageSize == 0 ? totalRecord / pageSize : totalRecord / pageSize + 1;
                IEnumerable<int> pageList = Enumerable.Range(1, totalPage);

                ddlPager.DataSource = pageList;
                ddlPager.DataBind();
                if (pageList.Count() > 0)
                    ddlPager.SelectedIndex = page;

                int skip = page * pageSize;
                dataList = dataList.Skip(skip).Take(pageSize);
                rptContractHistory.DataSource = dataList.ToList();
                rptContractHistory.DataBind();
            }
        }
        private void LoadData(string strSearch, int rentType)
        {
            using (var db = new RentBikeEntities())
            {
                var dataList = (from s in db.CONTRACT_FULL_VW
                                where s.CONTRACT_STATUS == true && s.ACTIVE == true
                                select s).OrderByDescending(c => c.RENT_DATE).ToList();

                if (STORE_ID != 0)
                {
                    dataList = dataList.Where(c => c.STORE_ID == STORE_ID).ToList();
                }

                if (!string.IsNullOrEmpty(strSearch))
                {
                    dataList = dataList.Where(c => c.SEARCH_TEXT.ToLower().Contains(strSearch.ToLower()) ||
                                              c.CUSTOMER_NAME.ToLower().Contains(strSearch.ToLower())).ToList();
                }


                if (rentType != 0)
                {
                    dataList = dataList.Where(c => c.RENT_TYPE_ID == rentType).ToList();
                }
                rptContract.DataSource = dataList;
                rptContract.DataBind();
            }
        }
示例#14
0
 protected void rptAccount_ItemCommand(object sender, RepeaterCommandEventArgs e)
 {
     try
     {
         if (e.CommandName == "Delete" && !string.IsNullOrEmpty(e.CommandArgument.ToString()))
         {
             var id = Convert.ToInt32(e.CommandArgument.ToString());
             using (var db = new RentBikeEntities())
             {
                 var account = db.Accounts.FirstOrDefault(c => c.ID == id);
                 if (account != null)
                 {
                     db.Accounts.Remove(account);
                     db.SaveChanges();
                 }
                 LoadData();
                 ViewState["DeleteSuccess"] = "Xóa tài khoản thành công";
             }
         }
     }
     catch (Exception ex)
     {
         ViewState["DeleteFail"] = ex.Message;
     }
 }
        private int GetNoRentOtherContract()
        {
            int no = 0;

            using (var db = new RentBikeEntities())
            {
                var item = (from itm in db.Contracts
                            where itm.RENT_TYPE_ID == 3 && // Other
                            itm.CONTRACT_STATUS == true
                            select itm);

                if (STORE_ID != 0)
                {
                    item = item.Where(c => c.STORE_ID == STORE_ID);
                }

                if (item != null && item.Any())
                {
                    no                       = item.Count();
                    TotalFeeOther            = item.Select(c => c.FEE_PER_DAY).DefaultIfEmpty(0).Sum();
                    TotalAmountOtherContract = item.Select(c => c.CONTRACT_AMOUNT).DefaultIfEmpty(0).Sum();
                }
            }

            return(no);
        }
示例#16
0
        private void CreateNewStore()
        {
            using (TransactionScope scope = new TransactionScope())
            {

                Store st = new Store();
                st.NAME = txtName.Text.Trim();
                st.ADDRESS = txtAddress.Text.Trim();
                st.CITY_ID = Convert.ToInt32(ddlCity.SelectedValue);
                st.PHONE = txtPhone.Text.Trim();
                st.FAX = string.Empty;
                st.START_CAPITAL = Convert.ToDecimal(txtStartCapital.Text);
                //st.CURRENT_CAPITAL = Convert.ToDecimal(txtCurrentCapital.Text);
                //st.APPLY_DATE = Convert.ToDateTime(txtApplyDate.Text);
                //st.REVENUE_BEFORE_APPLY = Convert.ToDecimal(txtTotalRevenueBefore.Text);
                //st.TOTAL_COST_BEFORE = Convert.ToDecimal(txtTotalCostBefore.Text);
                //st.TOTAL_INVESMENT_BEFORE = Convert.ToDecimal(txtTotalInvesmentBefore.Text);
                st.REGISTER_DATE = Convert.ToDateTime(txtRegisterDate.Text);
                st.ACTIVE = rdbActive.Checked;
                st.NOTE = txtNote.Text.Trim();
                st.SEARCH_TEXT = string.Format("{0} {1} {2}", st.NAME, st.ADDRESS, st.PHONE);

                using (var rb = new RentBikeEntities())
                {
                    rb.Stores.Add(st);
                    rb.SaveChanges();
                }

                using (var rb1 = new RentBikeEntities())
                {
                    var item = rb1.InOutTypes.FirstOrDefault(s =>s.NAME == "Nhập vốn");

                    InOut io = new InOut();
                    io.IN_AMOUNT = Convert.ToDecimal(txtStartCapital.Text.Replace(",", string.Empty));
                    io.OUT_AMOUNT = 0;
                    io.CONTRACT_ID = -1;
                    io.PERIOD_ID = -1;
                    io.RENT_TYPE_ID = -1;
                    io.PERIOD_DATE = DateTime.Now;
                    io.MORE_INFO = "Vốn đầu tư ban đầu khi đăng ký cửa hàng";
                    io.STORE_ID = st.ID;
                    io.INOUT_TYPE_ID = item.ID;
                    io.INOUT_DATE = DateTime.Now;
                    io.SEARCH_TEXT = string.Format("{0} {1} ngày {2}", io.MORE_INFO, io.IN_AMOUNT, io.INOUT_DATE);

                    rb1.InOuts.Add(io);
                    rb1.SaveChanges();

                    StoreFee sf = new StoreFee();
                    sf.STORE_ID = st.ID;
                    sf.FEE_PERCENT = 0;
                    rb1.StoreFees.Add(sf);
                    rb1.SaveChanges();
                }

                WriteLog(Constants.ACTION_CREATE_STORE, false);

                scope.Complete();
            }
        }
示例#17
0
        private void LoadData(string strSearch, int page)
        {
            // LOAD PAGER
            using (var db = new RentBikeEntities())
            {
                var dataList = (from c in db.RentTypes
                                select c);

                int totalRecord = dataList.Count();
                int totalPage   = totalRecord % pageSize == 0 ? totalRecord / pageSize : totalRecord / pageSize + 1;

                IEnumerable <int> pageList = Enumerable.Range(1, totalPage);
                ddlPager.DataSource = pageList;
                ddlPager.DataBind();

                if (pageList.Count() > 0)
                {
                    ddlPager.SelectedIndex = page;
                }

                // LOAD DATA WITH PAGING
                int skip = page * pageSize;
                dataList = dataList.Skip(skip).Take(pageSize);
                rptRentType.DataSource = dataList.ToList();
                rptRentType.DataBind();
            }
        }
 private List<Contract> GetContractFeeByDay(DateTime date, RentBikeEntities db)
 {
     var data = from d in db.Contracts
                where d.RENT_DATE == date
                select d;
     return data.ToList();
 }
        private void LoadData(string strSearch, int storeId, int page)
        {
            // LOAD PAGER
            using (var db = new RentBikeEntities())
            {
                IQueryable<STORE_FULL_VW> dataList = db.STORE_FULL_VW;

                if (storeId != 0)
                    dataList = dataList.Where(c => c.ID == storeId);

                if (!string.IsNullOrEmpty(strSearch))
                    dataList = dataList.Where(c => c.ID == storeId);

                var result = dataList.ToList();
                int totalRecord = result.Count;
                int totalPage = totalRecord % pageSize == 0 ? totalRecord / pageSize : totalRecord / pageSize + 1;
                IEnumerable<int> pageList = Enumerable.Range(1, totalPage);

                ddlPager.DataSource = pageList;
                ddlPager.DataBind();

                if (pageList.Count() > 0)
                    ddlPager.SelectedIndex = page;

                // LOAD DATA WITH PAGING
                int skip = page * pageSize;
                result = result.Skip(skip).Take(pageSize).ToList();

                rptStore.DataSource = result;
                rptStore.DataBind();
            }
        }
示例#20
0
        private void LoadInfor()
        {
            using (var db = new RentBikeEntities())
            {
                if (inOutId == 0)
                {
                    return;
                }

                var io = db.InOuts.FirstOrDefault(c => c.ID == inOutId);
                if (io != null)
                {
                    var ioType = db.InOutTypes.FirstOrDefault(c => c.ID == io.INOUT_TYPE_ID);
                    if (ioType != null)
                    {
                        if (ioType.IS_INCOME)
                        {
                            txtFeeAmount.Text = io.IN_AMOUNT.ToString();
                        }
                        else
                        {
                            txtFeeAmount.Text = io.OUT_AMOUNT.ToString();
                        }
                    }
                    txtMoreInfo.Text = io.MORE_INFO;
                    txtFeeDate.Text  = io.INOUT_DATE.Value.ToString("MM/dd/yyyy");
                }
            }
        }
示例#21
0
 public bool IsBadContract(int contractId)
 {
     using (var db = new RentBikeEntities())
     {
         return CommonList.IsBadContract(db, contractId);
     }
 }
示例#22
0
        protected string ValidateFields()
        {
            if (string.IsNullOrEmpty(ddlInOutFee.SelectedValue.Trim()) || "-1".Equals(ddlInOutFee.SelectedValue))
            {
                return("Bạn cần phải chọn loại chi phí.");
            }

            if (PERMISSION == ROLE.STAFF)
            {
                if (DateTime.Today.Subtract(Convert.ToDateTime(txtFeeDate.Text)).Days > 0)
                {
                    if (string.IsNullOrEmpty(txtUsername.Text.Trim()) || string.IsNullOrEmpty(txtPassword.Text.Trim()))
                    {
                        return("Bạn cần phải nhập tài khoản cửa hàng trưởng để xác nhận.");
                    }

                    using (var db = new RentBikeEntities())
                    {
                        var acc = db.Accounts.ToList().Where(c => c.ACC == txtUsername.Text.Trim() &&
                                                             c.PASSWORD == Helper.EncryptPassword(txtPassword.Text.Trim()) &&
                                                             c.STORE_ID == STORE_ID).FirstOrDefault();

                        if (acc == null)
                        {
                            return("Thông tin cửa hàng trưởng bạn nhập không tồn tại.");
                        }
                    }
                }
            }

            return(string.Empty);
        }
        private List <CONTRACT_FULL_VW> GetMiddleContract(int STORE_ID, string startDate, string endDate)
        {
            using (var db = new RentBikeEntities())
            {
                var listContract = db.CONTRACT_FULL_VW.Where(c => c.CONTRACT_STATUS == true && c.ACTIVE == true).ToList();
                if (STORE_ID != 0)
                {
                    listContract = listContract.Where(c => c.STORE_ID == STORE_ID).ToList();
                }
                if (!string.IsNullOrEmpty(startDate) && !string.IsNullOrEmpty(endDate))
                {
                    listContract = listContract.Where(c => c.CREATED_DATE >= Convert.ToDateTime(startDate) && c.CREATED_DATE <= Convert.ToDateTime(endDate)).ToList();
                }
                else if (!string.IsNullOrEmpty(startDate) && string.IsNullOrEmpty(endDate))
                {
                    listContract = listContract.Where(c => c.CREATED_DATE >= Convert.ToDateTime(startDate)).ToList();
                }
                else if (string.IsNullOrEmpty(startDate) && !string.IsNullOrEmpty(endDate))
                {
                    listContract = listContract.Where(c => c.CREATED_DATE <= Convert.ToDateTime(endDate)).ToList();
                }

                return(listContract);
            }
        }
示例#24
0
        protected void CalcFeeStore(int storeId)
        {
            using (var db = new RentBikeEntities())
            {
                IQueryable <INOUT_FULL_VW> inOut = db.INOUT_FULL_VW.Where(c => c.ACTIVE == true);
                if (storeId != 0)
                {
                    inOut = inOut.Where(c => c.STORE_ID == storeId);
                }
                var data = from d in inOut.ToList()
                           group d by d.INOUT_DATE into g
                           select new
                {
                    Period = g.Key,
                    Record = from o in g
                             select new
                    {
                        TotalIn  = g.Sum(x => x.IN_AMOUNT),
                        TotalOut = g.Sum(x => x.OUT_AMOUNT),
                    }
                };

                if (data.Any())
                {
                    decimal sumIn  = 0;
                    decimal sumOut = 0;
                    decimal sumEnd = 0;

                    sumIn              = data.Select(c => c.Record.ToList()[0].TotalIn).DefaultIfEmpty(0).Sum();
                    sumOut             = data.Select(c => c.Record.ToList()[0].TotalOut).DefaultIfEmpty(0).Sum();
                    sumEnd             = sumIn - sumOut;
                    lblTotalValue.Text = sumEnd == 0 ? "0" : string.Format("{0:0,0}", sumEnd);
                }
            }
        }
示例#25
0
        private List <Contract> GetContractFeeByDay(DateTime date, RentBikeEntities db)
        {
            var data = from d in db.Contracts
                       where d.RENT_DATE == date
                       select d;

            return(data.ToList());
        }
        private List <CONTRACT_FULL_VW> GetResultList(string strSearch, string customerType)
        {
            using (var db = new RentBikeEntities())
            {
                IQueryable <CONTRACT_FULL_VW> dataList = db.CONTRACT_FULL_VW.Where(c => c.CONTRACT_STATUS == true && c.ACTIVE == true).OrderByDescending(c => c.ID);

                if (STORE_ID != 0)
                {
                    dataList = dataList.Where(c => c.STORE_ID == STORE_ID);
                }

                if (!string.IsNullOrEmpty(customerType))
                {
                    switch (customerType)
                    {
                    case "1":
                        dataList = dataList.Where(c => c.IS_LOW_RECOVERABILITY == false);
                        break;

                    case "2":
                        dataList = dataList.Where(c => c.IS_LOW_RECOVERABILITY == true);
                        break;

                    default:
                        break;
                    }
                }
                if (!string.IsNullOrEmpty(strSearch))
                {
                    dataList = dataList.Where(s => s.SEARCH_TEXT.ToLower().Contains(txtSearch.Text.ToLower()) ||
                                              s.CUSTOMER_NAME.ToLower().Contains(txtSearch.Text.ToLower()));
                }


                var result    = new List <CONTRACT_FULL_VW>();
                var lstPeriod = db.PayPeriods.Where(s => s.STATUS == true).ToList();
                foreach (CONTRACT_FULL_VW c in dataList)
                {
                    var     lstTempPeriod = lstPeriod.Where(s => s.CONTRACT_ID == c.ID).ToList();
                    decimal totalPayed    = lstTempPeriod.Select(s => s.ACTUAL_PAY).DefaultIfEmpty(0).Sum();
                    foreach (PayPeriod pp in lstTempPeriod)
                    {
                        if (pp.AMOUNT_PER_PERIOD > totalPayed)
                        {
                            c.PAY_DATE  = pp.PAY_DATE;
                            c.OVER_DATE = DateTime.Now.Subtract(c.PAY_DATE).Days;
                            if (c.OVER_DATE > 50)
                            {
                                result.Add(c);
                            }
                            break;
                        }
                        totalPayed -= pp.AMOUNT_PER_PERIOD;
                    }
                }
                return(result.OrderBy(c => c.OVER_DATE).ToList());
            }
        }
示例#27
0
        public bool CheckAdminPermission()
        {
            string acc = Convert.ToString(Session["username"]);
            using (var db = new RentBikeEntities())
            {
                var item = db.Accounts.FirstOrDefault(s => s.ACC == acc);

                if (item.PERMISSION_ID == 1)
                    return true;
                return false;
            }
        }
        protected override void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!IsPostBack)
            {
                int id = Convert.ToInt32(Request.QueryString["ID"]);
                using (var db = new RentBikeEntities())
                {
                    Contract con = db.Contracts.FirstOrDefault(c => c.ID == id);

                    var customer = db.Customers.FirstOrDefault(c => c.ID == con.CUSTOMER_ID);
                    if (customer != null)
                    {
                        CustomerName = customer.NAME;
                    }

                    txtEndDate.Text  = string.Format("{0:dd/MM/yyyy}", con.END_DATE);
                    txtAmount.Text   = string.Format("{0:0,0}", con.CONTRACT_AMOUNT);
                    txtOverDate.Text = DateTime.Now.Date.Subtract(con.END_DATE).TotalDays <= 0 ? "0" : DateTime.Now.Date.Subtract(con.END_DATE).TotalDays.ToString();

                    List <PayPeriod> lstPayperiod = db.PayPeriods.Where(c => c.CONTRACT_ID == id).ToList();
                    decimal          paidAmount   = lstPayperiod.Where(c => c.ACTUAL_PAY > 0).Select(c => c.ACTUAL_PAY).DefaultIfEmpty(0).Sum();
                    decimal          total        = 0;

                    for (DateTime date = con.RENT_DATE; date <= DateTime.Now; date = date.AddDays(1))
                    {
                        foreach (PayPeriod pay in lstPayperiod)
                        {
                            if (date <= pay.PAY_DATE.AddDays(10))
                            {
                                total += pay.AMOUNT_PER_PERIOD / 10;
                                break;
                            }
                        }
                    }
                    if (total - paidAmount < 0)
                    {
                        txtRealIncome.Text   = "0";
                        txtReduceAmount.Text = string.Format("{0:0,0}", paidAmount - total);
                    }
                    else
                    {
                        txtRealIncome.Text   = string.Format("{0:0,0}", total - paidAmount);
                        txtReduceAmount.Text = "0";
                    }
                }
            }
            //Disable UI for Admin account
            if (IS_ADMIN)
            {
                pnlTable.Enabled = false;
            }
        }
示例#29
0
        private void LoadGrid(PayPeriod pp)
        {
            List <InOut> payList = new List <InOut>();

            using (var db = new RentBikeEntities())
            {
                var itemLst = db.InOuts.Where(s => s.PERIOD_ID == pp.ID && s.IN_AMOUNT != 0).ToList();

                rptContractInOut.DataSource = itemLst;
                rptContractInOut.DataBind();
            }
        }
示例#30
0
        protected void btnCancel_Click(object sender, EventArgs e)
        {
            int periodId = Convert.ToInt32(Request.QueryString["ID"]);
            PayPeriod pp = new PayPeriod();
            using (var db = new RentBikeEntities())
            {
                var item = db.PayPeriods.FirstOrDefault(s => s.ID == periodId);
                pp = item;
            }

            Response.Redirect(string.Format("FormContractUpdate.aspx?ID={0}", pp.CONTRACT_ID));
        }
        private List<CONTRACT_FULL_VW> GetResultList(string strSearch, string customerType)
        {
            using (var db = new RentBikeEntities())
            {
                IQueryable<CONTRACT_FULL_VW> dataList = db.CONTRACT_FULL_VW.Where(c => c.CONTRACT_STATUS == true && c.ACTIVE == true).OrderByDescending(c => c.ID);

                if (STORE_ID != 0)
                    dataList = dataList.Where(c => c.STORE_ID == STORE_ID);

                if (!string.IsNullOrEmpty(customerType))
                {
                    switch(customerType)
                    {
                        case "1":
                            dataList = dataList.Where(c =>c.IS_LOW_RECOVERABILITY == false);
                            break;
                        case "2":
                            dataList = dataList.Where(c => c.IS_LOW_RECOVERABILITY == true);
                            break;
                        default:
                            break;
                    }

                }
                if (!string.IsNullOrEmpty(strSearch))
                    dataList = dataList.Where(s => s.SEARCH_TEXT.ToLower().Contains(txtSearch.Text.ToLower())
                        || s.CUSTOMER_NAME.ToLower().Contains(txtSearch.Text.ToLower()));

                var result = new List<CONTRACT_FULL_VW>();
                var lstPeriod = db.PayPeriods.Where(s => s.STATUS == true).ToList();
                foreach (CONTRACT_FULL_VW c in dataList)
                {
                    var lstTempPeriod = lstPeriod.Where(s => s.CONTRACT_ID == c.ID).ToList();
                    decimal totalPayed = lstTempPeriod.Select(s => s.ACTUAL_PAY).DefaultIfEmpty(0).Sum();
                    foreach (PayPeriod pp in lstTempPeriod)
                    {
                        if (pp.AMOUNT_PER_PERIOD > totalPayed)
                        {
                            c.PAY_DATE = pp.PAY_DATE;
                            c.OVER_DATE = DateTime.Now.Subtract(c.PAY_DATE).Days;
                            if (c.OVER_DATE > 50)
                            {
                                result.Add(c);
                            }
                            break;
                        }
                        totalPayed -= pp.AMOUNT_PER_PERIOD;
                    }
                }
                return result.OrderBy(c => c.OVER_DATE).ToList();
            }
        }
示例#32
0
        private decimal GetRentFeeByDay(int rentType, DateTime date, RentBikeEntities db)
        {
            var data = from d in db.Contracts
                       where d.RENT_TYPE_ID == rentType &&
                       d.RENT_DATE == date
                       select d;

            if (data.Any())
            {
                return(data.Sum(x => x.FEE_PER_DAY));
            }
            return(0);
        }
 private List <Store> GetMiddleStore(int STORE_ID)
 {
     using (var db = new RentBikeEntities())
     {
         var listStore = (from c in db.Stores
                          select c).ToList();
         if (STORE_ID != 0)
         {
             listStore = listStore.Where(c => c.ID == STORE_ID).ToList();
         }
         return(listStore.ToList());
     }
 }
示例#34
0
        protected void btnCancel_Click(object sender, EventArgs e)
        {
            int       periodId = Convert.ToInt32(Request.QueryString["ID"]);
            PayPeriod pp       = new PayPeriod();

            using (var db = new RentBikeEntities())
            {
                var item = db.PayPeriods.FirstOrDefault(s => s.ID == periodId);
                pp = item;
            }

            Response.Redirect(string.Format("FormContractUpdate.aspx?ID={0}", pp.CONTRACT_ID));
        }
示例#35
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            // SAVE INOUT
            int periodId = Convert.ToInt32(Request.QueryString["ID"]);

            using (var db = new RentBikeEntities())
            {
                if (!string.IsNullOrEmpty(txtIncome.Text))
                {
                    var pp = db.PayPeriods.FirstOrDefault(s => s.ID == periodId);
                    pp.ACTUAL_PAY = Convert.ToDecimal(txtIncome.Text) + pp.ACTUAL_PAY;
                    db.SaveChanges();

                    var contract                    = db.Contracts.FirstOrDefault(c => c.ID == pp.CONTRACT_ID && c.CONTRACT_STATUS == true);
                    List <PayPeriod> payList        = db.PayPeriods.Where(c => c.CONTRACT_ID == pp.CONTRACT_ID).ToList();
                    decimal          totalActualPay = payList.Select(c => c.ACTUAL_PAY).DefaultIfEmpty(0).Sum();
                    decimal          totalPlanPay   = payList.Select(c => c.AMOUNT_PER_PERIOD).DefaultIfEmpty(0).Sum();

                    if (totalActualPay > totalPlanPay)
                    {
                        CommonList.CreatePayPeriod(db, contract.ID, payList.LastOrDefault(), false);
                    }

                    InOut io = new InOut();
                    io.IN_AMOUNT     = Convert.ToDecimal(txtIncome.Text);
                    io.OUT_AMOUNT    = 0;
                    io.CONTRACT_ID   = pp.CONTRACT_ID;
                    io.PERIOD_ID     = pp.ID;
                    io.RENT_TYPE_ID  = contract.RENT_TYPE_ID;
                    io.INOUT_TYPE_ID = Convert.ToInt32(ddInOutType.SelectedValue);
                    io.PERIOD_DATE   = pp.PAY_DATE;
                    io.MORE_INFO     = txtMoreInfo.Text.Trim();
                    io.STORE_ID      = Convert.ToInt32(Session["store_id"]);
                    io.SEARCH_TEXT   = string.Format("{0} ", io.MORE_INFO);
                    io.INOUT_DATE    = DateTime.Now;
                    io.CREATED_BY    = Session["username"].ToString();
                    io.CREATED_DATE  = DateTime.Now;
                    io.UPDATED_BY    = Session["username"].ToString();
                    io.UPDATED_DATE  = DateTime.Now;

                    db.InOuts.Add(io);
                    db.SaveChanges();

                    var    customer = db.Customers.FirstOrDefault(c => c.ID == contract.CUSTOMER_ID);
                    string message  = string.Format("Tài khoản {0} cửa hàng {1} thực hiện thu phí kỳ hạn ngày {2} của hợp đồng {3} số tiền {4} vào lúc {5}", Convert.ToString(Session["username"]), STORE_NAME, pp.PAY_DATE.ToString("dd/MM/yyyy"), customer.NAME, Helper.FormatedAsCurrency(io.IN_AMOUNT), DateTime.Now);
                    Helper.WriteLog(Convert.ToString(Session["username"]), STORE_NAME, Constants.ACTION_CREATE_INOUT, message, false);

                    Response.Redirect("FormContractUpdate.aspx?ID=" + pp.CONTRACT_ID, false);
                }
            }
        }
示例#36
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            // SAVE INOUT
            int periodId = Convert.ToInt32(Request.QueryString["ID"]);
            using (var db = new RentBikeEntities())
            {
                if (!string.IsNullOrEmpty(txtIncome.Text))
                {
                    var pp = db.PayPeriods.FirstOrDefault(s => s.ID == periodId);
                    pp.ACTUAL_PAY = Convert.ToDecimal(txtIncome.Text) + pp.ACTUAL_PAY;
                    db.SaveChanges();

                    var contract = db.Contracts.FirstOrDefault(c => c.ID == pp.CONTRACT_ID && c.CONTRACT_STATUS == true);
                    List<PayPeriod> payList = db.PayPeriods.Where(c => c.CONTRACT_ID == pp.CONTRACT_ID).ToList();
                    decimal totalActualPay = payList.Select(c => c.ACTUAL_PAY).DefaultIfEmpty(0).Sum();
                    decimal totalPlanPay = payList.Select(c => c.AMOUNT_PER_PERIOD).DefaultIfEmpty(0).Sum();

                    if (totalActualPay > totalPlanPay)
                    {
                        CommonList.CreatePayPeriod(db, contract.ID, payList.LastOrDefault(), false);
                    }

                    InOut io = new InOut();
                    io.IN_AMOUNT = Convert.ToDecimal(txtIncome.Text);
                    io.OUT_AMOUNT = 0;
                    io.CONTRACT_ID = pp.CONTRACT_ID;
                    io.PERIOD_ID = pp.ID;
                    io.RENT_TYPE_ID = contract.RENT_TYPE_ID;
                    io.INOUT_TYPE_ID = Convert.ToInt32(ddInOutType.SelectedValue);
                    io.PERIOD_DATE = pp.PAY_DATE;
                    io.MORE_INFO = txtMoreInfo.Text.Trim();
                    io.STORE_ID = Convert.ToInt32(Session["store_id"]);
                    io.SEARCH_TEXT = string.Format("{0} ", io.MORE_INFO);
                    io.INOUT_DATE = DateTime.Now;
                    io.CREATED_BY = Session["username"].ToString();
                    io.CREATED_DATE = DateTime.Now;
                    io.UPDATED_BY = Session["username"].ToString();
                    io.UPDATED_DATE = DateTime.Now;

                    db.InOuts.Add(io);
                    db.SaveChanges();

                    var customer = db.Customers.FirstOrDefault(c => c.ID == contract.CUSTOMER_ID);
                    string message = string.Format("Tài khoản {0} cửa hàng {1} thực hiện thu phí kỳ hạn ngày {2} của hợp đồng {3} số tiền {4} vào lúc {5}", Convert.ToString(Session["username"]), STORE_NAME, pp.PAY_DATE.ToString("dd/MM/yyyy"), customer.NAME, Helper.FormatedAsCurrency(io.IN_AMOUNT), DateTime.Now);
                    Helper.WriteLog(Convert.ToString(Session["username"]), STORE_NAME, Constants.ACTION_CREATE_INOUT, message, false);

                    Response.Redirect("FormContractUpdate.aspx?ID=" + pp.CONTRACT_ID, false);
                }
            }
        }
示例#37
0
        private void LoadData(string strSearch, string date, int page, int storeId)
        {
            int totalRecord = 0;
            // LOAD DATA WITH PAGING
            List <INOUT_FULL_VW> dataList;
            int skip = page * pageSize;

            using (var db = new RentBikeEntities())
            {
                if (storeId != 0)
                {
                    dataList = db.INOUT_FULL_VW.Where(s => s.SEARCH_TEXT.Contains(strSearch) && s.STORE_ID == storeId).OrderByDescending(s => s.ID).ToList();
                    if (!string.IsNullOrEmpty(date))
                    {
                        date     = Convert.ToDateTime(date).ToString("yyyyMMdd");
                        dataList = dataList.Where(s => s.INOUT_DATE.HasValue ? s.INOUT_DATE.Value.ToString("yyyyMMdd").Equals(date) : false).ToList();
                    }
                    totalRecord = Convert.ToInt32(dataList.Count());
                    dataList    = dataList.Skip(skip).Take(pageSize).ToList();
                }
                else
                {
                    dataList = db.INOUT_FULL_VW.Where(s => s.SEARCH_TEXT.Contains(strSearch)).OrderByDescending(s => s.ID).ToList();
                    if (!string.IsNullOrEmpty(date))
                    {
                        date     = Convert.ToDateTime(date).ToString("yyyyMMdd");
                        dataList = dataList.Where(s => s.INOUT_DATE.HasValue ? s.INOUT_DATE.Value.ToString("yyyyMMdd").Equals(date) : false).ToList();
                    }
                    totalRecord = Convert.ToInt32(dataList.Count());
                    dataList    = dataList.Skip(skip).Take(pageSize).ToList();
                }
                int        totalPage = totalRecord % pageSize == 0 ? totalRecord / pageSize : totalRecord / pageSize + 1;
                List <int> pageList  = new List <int>();
                for (int i = 1; i <= totalPage; i++)
                {
                    pageList.Add(i);
                }

                ddlPager.DataSource = pageList;
                ddlPager.DataBind();
                if (pageList.Count > 0)
                {
                    ddlPager.SelectedIndex = page;
                }
            }

            ReBuildData(dataList);
            rptInOut.DataSource = dataList;
            rptInOut.DataBind();
        }
示例#38
0
        private static List <Store> GetStoreByCity(int city_id)
        {
            List <Store> lst;

            using (var db = new RentBikeEntities())
            {
                var st = from s in db.Stores
                         where s.CITY_ID == city_id && s.ACTIVE == true
                         select s;

                lst = st.ToList <Store>();
            }
            return(lst);
        }
示例#39
0
        private static List <Store> GetAllStore()
        {
            List <Store> lst;

            using (var db = new RentBikeEntities())
            {
                var st = from s in db.Stores
                         where s.ACTIVE == true
                         select s;

                lst = st.ToList <Store>();
            }
            return(lst);
        }
示例#40
0
        public bool CheckAdminPermission()
        {
            string acc = Convert.ToString(Session["username"]);

            using (var db = new RentBikeEntities())
            {
                var item = db.Accounts.FirstOrDefault(s => s.ACC == acc);

                if (item.PERMISSION_ID == 1)
                {
                    return(true);
                }
                return(false);
            }
        }
示例#41
0
        private bool LoadUser(string user, string password)
        {
            if (string.IsNullOrEmpty(user) || string.IsNullOrEmpty(password))
            {
                return(false);
            }

            using (var db = new RentBikeEntities())
            {
                var acc = (from s in db.Accounts
                           where s.ACC == user && s.PASSWORD == password && s.ACTIVE == true
                           select s).FirstOrDefault();

                if (acc == null)
                {
                    return(false);
                }

                if (acc.STORE_ID != 0)
                {
                    var item = db.Stores.FirstOrDefault(s => s.ID == acc.STORE_ID);
                    if (item != null)
                    {
                        if (!item.ACTIVE)
                        {
                            return(false);
                        }
                        Session["store_name"] = item.NAME;
                    }
                }
                else
                {
                    Session["store_name"] = string.Empty;
                }

                Session["username"]   = acc.ACC;
                Session["password"]   = acc.PASSWORD;
                Session["name"]       = acc.NAME;
                Session["permission"] = acc.PERMISSION_ID;
                Session["city_id"]    = acc.CITY_ID;
                Session["store_id"]   = acc.STORE_ID;

                Helper.WriteLog(acc.ACC, Convert.ToString(Session["store_name"]), Constants.ACTION_LOGIN, false);
            }
            return(true);
        }
        private decimal GetAmountOfNotFinishedContract()
        {
            decimal amount = 0;
            using (var db = new RentBikeEntities())
            {
                var item = from itm in db.Contracts
                           where itm.CONTRACT_STATUS == true
                           select itm;

                if (STORE_ID != 0)
                    item = item.Where(c => c.STORE_ID == STORE_ID);

                if (item != null && item.Any())
                    amount = item.Select(c => c.CONTRACT_AMOUNT).DefaultIfEmpty(0).Sum();
            }
            return amount;
        }
        private int GetNoOfNotFinishedContract()
        {
            int no = 0;
            using (var db = new RentBikeEntities())
            {
                var item = (from itm in db.Contracts
                            where itm.CONTRACT_STATUS == true
                            select itm);

                if (STORE_ID != 0)
                    item = item.Where(c => c.STORE_ID == STORE_ID);

                if (item != null && item.Any())
                    no = item.Count();
            }

            return no;
        }
 protected void btnLowRecoverability_Click(object sender, EventArgs e)
 {
     try
     {
         string id = Request.QueryString["ID"];
         using (var db = new RentBikeEntities())
         {
             int contractId = Helper.parseInt(id);
             var contract = db.Contracts.FirstOrDefault(c => c.CONTRACT_STATUS == true && c.ID == contractId);
             if (contract != null)
             {
                 Customer customer = db.Customers.FirstOrDefault(c => c.ID == contract.CUSTOMER_ID);
                 if (customer != null)
                 {
                     string message = string.Empty;
                     if (btnLowRecoverability.CommandArgument == "LowRecoverability")
                     {
                         customer.IS_LOW_RECOVERABILITY = true;
                         lblMessage.Text = string.Format(Constants.LOW_RECOVERABILITY, customer.NAME);
                         btnLowRecoverability.Text = "Bỏ khả năng thu hồi thấp";
                         btnLowRecoverability.CommandArgument = "RevertLowRecoverability";
                         message = string.Format("Tài khoản {0} cửa hàng {1} đã đánh dấu khả năng thu hồi thấp cho khách hàng {2} vào lúc {3}", Convert.ToString(Session["username"]), STORE_NAME, customer.NAME, DateTime.Now);
                     }
                     else
                     {
                         customer.IS_LOW_RECOVERABILITY = false;
                         lblMessage.Text = string.Format(Constants.REVERT_LOW_RECOVERABILITY, customer.NAME);
                         btnLowRecoverability.Text = "Khả năng thu hồi thấp";
                         btnLowRecoverability.CommandArgument = "LowRecoverability";
                         message = string.Format("Tài khoản {0} cửa hàng {1} đã bỏ khả năng thu hồi thấp cho khách hàng {2} vào lúc {3}", Convert.ToString(Session["username"]), STORE_NAME, customer.NAME, DateTime.Now);
                     }
                     db.SaveChanges();
                     Helper.WriteLog(Convert.ToString(Session["username"]), STORE_NAME, Constants.ACTION_UPDATE_CONTRACT, message, false);
                 }
             }
         }
     }
     catch(Exception ex)
     {
         lblMessage.Text = ex.Message;
         lblMessage.CssClass = "text-center text-danger";
         Logger.Log(ex.Message);
     }
 }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string result = ValidateFields();
            if (!string.IsNullOrEmpty(result))
            {
                lblMessage.Text = result;
                return;
            }

            using (var db = new RentBikeEntities())
            {
                int inOutId = Helper.parseInt(Request.QueryString["id"]);
                if (inOutId != 0)
                {
                    var io = db.InOuts.FirstOrDefault(c =>c.ID == inOutId);
                    // SAVE INOUT
                    io.IN_AMOUNT = Convert.ToDecimal(txtIncome.Text);
                    io.MORE_INFO = txtMoreInfo.Text.Trim();
                    io.UPDATED_BY = Session["username"].ToString();
                    io.UPDATED_DATE = DateTime.Now;
                    db.SaveChanges();
                }

                int periodId = Helper.parseInt(Request.QueryString["pid"]);
                if (periodId != 0)
                {
                    // SAVE PERIOD
                    decimal totalInAmountOfPeriod = db.InOuts.Where(c =>c.PERIOD_ID == periodId).Select(c =>c.IN_AMOUNT).DefaultIfEmpty(0).Sum();
                    var pp = db.PayPeriods.FirstOrDefault(c =>c.ID == periodId);
                    pp.ACTUAL_PAY = totalInAmountOfPeriod;
                    db.SaveChanges();

                    var contract = db.Contracts.FirstOrDefault(c => c.ID == pp.CONTRACT_ID);
                    var customer = db.Customers.FirstOrDefault(c =>c.ID == contract.CUSTOMER_ID);
                    string message = string.Format("Tài khoản {0} cửa hàng {1} thực hiện chỉnh sửa thu phí kỳ hạn ngày {2} của hợp đồng {3} số tiền {4} vào lúc {5}", Convert.ToString(Session["username"]), STORE_NAME, pp.PAY_DATE.ToString("dd/MM/yyyy"), customer.NAME, Helper.FormatedAsCurrency(Convert.ToDecimal(txtIncome.Text.Trim())), DateTime.Now);
                    Helper.WriteLog(Convert.ToString(Session["username"]), STORE_NAME, Constants.ACTION_UPDATE_INOUT, message, false);

                    Response.Redirect(string.Format("FormInOutUpdate.aspx?ID={0}", periodId), false);
                }
                Response.Redirect("FormDailyIncomeOutcome.aspx", false);
            }
        }
示例#46
0
        private void LoadData(string strSearch, int page)
        {
            // LOAD PAGER
            using (var db = new RentBikeEntities())
            {
                List<CONTRACT_FULL_VW> dataList = db.CONTRACT_FULL_VW.Where(c =>c.ACTIVE == true && ( c.SEARCH_TEXT.ToLower().Contains(strSearch.ToLower())
                    || c.CUSTOMER_NAME.ToLower().Contains(strSearch.ToLower())))
                    .OrderByDescending(c => c.ID)
                    .OrderByDescending(c => c.CONTRACT_STATUS)
                    .ToList();

                if (IS_ADMIN && STORE_ID != 0)
                {
                    dataList = dataList.Where(c =>c.STORE_ID == STORE_ID).ToList();
                }

                var totalRecord = dataList.Count;
                litSearchResult.Text = string.Format("Có {0} kết quả được tìm thấy.", totalRecord);

                int totalPage = totalRecord % pageSize == 0 ? totalRecord / pageSize : totalRecord / pageSize + 1;
                List<int> pageList = new List<int>();
                for (int i = 1; i <= totalPage; i++)
                {
                    pageList.Add(i);
                }

                ddlPager.DataSource = pageList;
                ddlPager.DataBind();
                if (pageList.Count > 0)
                {
                    ddlPager.SelectedIndex = page;
                }

                int skip = page * pageSize;
                dataList = dataList.Skip(skip).Take(pageSize).ToList();

                rptSearch.DataSource = dataList;
                rptSearch.DataBind();
            }
        }
        protected override void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!IsPostBack)
            {
                // LOAD PAYPERIOD
                int inOutId = Helper.parseInt(Request.QueryString["id"]);
                if (inOutId != 0)
                {
                    using (var db = new RentBikeEntities())
                    {
                        var io = db.InOuts.FirstOrDefault(c =>c.ID == inOutId);
                        InOutDate = io.INOUT_DATE.Value;
                        // DISPLAY SREEN
                        txtIncome.Text = Convert.ToString(io.IN_AMOUNT.ToString());
                        txtMoreInfo.Text = io.MORE_INFO;
                        hplContract.NavigateUrl = string.Format("FormContractUpdate.aspx?ID={0}", io.CONTRACT_ID);
                        hplContract.Text = "Xem chi tiết hợp đồng";

                        var store = db.Stores.FirstOrDefault(s =>s.ID == io.STORE_ID && s.ACTIVE == true);
                        if (store != null)
                        {
                            txtStore.Text = store.NAME;
                            txtStore.Enabled = false;
                        }

                        var lst = db.InOutTypes.Where(s => s.IS_CONTRACT == true && s.ACTIVE == true).ToList();
                        foreach (var data in lst)
                        {
                            ddInOutType.Items.Add(new ListItem { Text = data.NAME, Value = data.ID.ToString() });
                        }
                        ddInOutType.SelectedValue = io.INOUT_TYPE_ID.ToString();
                    }
                }
            }
            //Disable UI for Admin account
            if (IS_ADMIN) pnlTable.Enabled = false;
        }
示例#48
0
        protected void CalcFeeStore(int storeId)
        {
            using (var db = new RentBikeEntities())
            {
                IQueryable<INOUT_FULL_VW> inOut = db.INOUT_FULL_VW.Where(c =>c.ACTIVE == true);
                if (storeId != 0)
                {
                    inOut = inOut.Where(c => c.STORE_ID == storeId);
                }
                var data = from d in inOut.ToList()
                           group d by d.INOUT_DATE into g
                           select new
                           {
                               Period = g.Key,
                               Record = from o in g
                                        select new
                                        {
                                            TotalIn = g.Sum(x => x.IN_AMOUNT),
                                            TotalOut = g.Sum(x => x.OUT_AMOUNT),

                                        }
                           };

                if (data.Any())
                {
                    decimal sumIn = 0;
                    decimal sumOut = 0;
                    decimal sumEnd = 0;

                    sumIn = data.Select(c => c.Record.ToList()[0].TotalIn).DefaultIfEmpty(0).Sum();
                    sumOut = data.Select(c => c.Record.ToList()[0].TotalOut).DefaultIfEmpty(0).Sum();
                    sumEnd = sumIn - sumOut;
                    lblTotalValue.Text = sumEnd == 0 ? "0" : string.Format("{0:0,0}", sumEnd);
                }
            }
        }
示例#49
0
        private void LoadStoreById(string id)
        {
            int storeid = Convert.ToInt32(id);
            List<Store> lst;
            using (var db = new RentBikeEntities())
            {
                var st = from s in db.Stores
                         where s.ID == storeid
                         select s;

                lst = st.ToList<Store>();
            }

            Store store = lst[0];
            txtName.Text = store.NAME;
            txtAddress.Text = store.ADDRESS;
            ddlCity.SelectedValue = store.CITY_ID.ToString();
            txtPhone.Text = store.PHONE;
            txtStartCapital.Text = store.START_CAPITAL.ToString(); // Common.CommonList.FormatedAsCurrency(Convert.ToInt32(store.START_CAPITAL));
            txtCurrentCapital.Text = store.CURRENT_CAPITAL.ToString();
            txtApplyDate.Text = store.APPLY_DATE.ToShortDateString();
            txtTotalRevenueBefore.Text = store.REVENUE_BEFORE_APPLY.ToString();
            txtTotalCostBefore.Text = store.TOTAL_COST_BEFORE.ToString();
            txtTotalInvesmentBefore.Text = store.TOTAL_INVESMENT_BEFORE.ToString();
            txtRegisterDate.Text = store.REGISTER_DATE.ToShortDateString();
            rdbActive.Checked = store.ACTIVE;
            rdbDeActive.Checked = !rdbActive.Checked;
            txtNote.Text = store.NOTE;
        }
示例#50
0
        private static List<Store> GetStoreByCity(int city_id)
        {
            List<Store> lst;
            using (var db = new RentBikeEntities())
            {
                var st = from s in db.Stores
                         where s.CITY_ID == city_id && s.ACTIVE == true
                         select s;

                lst = st.ToList<Store>();
            }
            return lst;
        }
示例#51
0
        private static List<Store> GetAllStore()
        {
            List<Store> lst;
            using (var db = new RentBikeEntities())
            {
                var st = from s in db.Stores
                         where s.ACTIVE == true
                         select s;

                lst = st.ToList<Store>();
            }
            return lst;
        }
示例#52
0
        private void WriteLog(string action, bool isCrashed)
        {
            Log lg = new Log();
            lg.ACCOUNT = Session["username"].ToString();
            lg.STORE = STORE_NAME;
            lg.LOG_ACTION = action;
            lg.LOG_DATE = DateTime.Now;
            lg.IS_CRASH = isCrashed;
            lg.LOG_MSG = string.Format("Tài khoản {0} cửa hàng {1} thực hiện {2} vào lúc {3}", lg.ACCOUNT, STORE_NAME, lg.LOG_ACTION, lg.LOG_DATE);
            lg.SEARCH_TEXT = lg.LOG_MSG;

            using (var db = new RentBikeEntities())
            {
                db.Logs.Add(lg);
                db.SaveChanges();
            }
        }
示例#53
0
        private bool LoadUser(string user, string password)
        {
            if (string.IsNullOrEmpty(user) || string.IsNullOrEmpty(password))
                return false;

            using (var db = new RentBikeEntities())
            {
                var acc = (from s in db.Accounts
                           where s.ACC == user && s.PASSWORD == password && s.ACTIVE == true
                           select s).FirstOrDefault();

                if (acc == null) return false;

                if (acc.STORE_ID != 0)
                {
                    var item = db.Stores.FirstOrDefault(s => s.ID == acc.STORE_ID);
                    if (item != null)
                    {
                        if (!item.ACTIVE)
                            return false;
                        Session["store_name"] = item.NAME;
                    }
                }
                else
                    Session["store_name"] = string.Empty;

                Session["username"] = acc.ACC;
                Session["password"] = acc.PASSWORD;
                Session["name"] = acc.NAME;
                Session["permission"] = acc.PERMISSION_ID;
                Session["city_id"] = acc.CITY_ID;
                Session["store_id"] = acc.STORE_ID;

                Helper.WriteLog(acc.ACC, Convert.ToString(Session["store_name"]), Constants.ACTION_LOGIN, false);
            }
            return true;
        }
示例#54
0
        private void UpdateStore(string id)
        {
            using (var db = new RentBikeEntities())
            {
                int storeid = Convert.ToInt32(id);
                var st = (from s in db.Stores
                          where s.ID == storeid
                          select s).FirstOrDefault();

                st.NAME = txtName.Text.Trim();
                st.ADDRESS = txtAddress.Text.Trim();
                st.CITY_ID = Convert.ToInt32(ddlCity.SelectedValue);
                st.PHONE = txtPhone.Text.Trim();
                st.FAX = string.Empty;
                st.START_CAPITAL = Convert.ToDecimal(txtStartCapital.Text);
                st.CURRENT_CAPITAL = Convert.ToDecimal(txtCurrentCapital.Text);
                //st.APPLY_DATE = Convert.ToDateTime(txtApplyDate.Text.Trim());
                //st.REVENUE_BEFORE_APPLY = Convert.ToDecimal(txtTotalRevenueBefore.Text);
                //st.TOTAL_COST_BEFORE = Convert.ToDecimal(txtTotalCostBefore.Text);
                //st.TOTAL_INVESMENT_BEFORE = Convert.ToDecimal(txtTotalInvesmentBefore.Text);
                st.REGISTER_DATE = Convert.ToDateTime(txtRegisterDate.Text.Trim());
                st.ACTIVE = rdbActive.Checked;
                st.NOTE = txtNote.Text.Trim();
                st.SEARCH_TEXT = string.Format("{0} {1} {2}", st.NAME, st.ADDRESS, st.PHONE);

                db.SaveChanges();

                var storefee = db.StoreFees.FirstOrDefault(s =>s.STORE_ID == storeid);
                storefee.FEE_PERCENT = 0;
                db.SaveChanges();
            }

            WriteLog(Constants.ACTION_UPDATE_STORE, false);
        }
        private void LoadStore()
        {
            List<Store> lst = new List<Store>();
            using (var db = new RentBikeEntities())
            {
                var data = from itm in db.Stores
                           select itm;

                if (data.Any())
                {
                    foreach (Store store in data)
                    {
                        ddlStore.Items.Add(new ListItem(store.NAME, store.ID.ToString()));
                    }
                    ddlStore.SelectedValue = storeId.ToString();
                    if (!IS_ADMIN)
                        ddlStore.Enabled = false;
                }
            }
        }
示例#56
0
        private void CreateNewStore()
        {
            using (TransactionScope scope = new TransactionScope())
            {

                Store st = new Store();
                st.NAME = txtName.Text.Trim();
                st.ADDRESS = txtAddress.Text.Trim();
                st.CITY_ID = Convert.ToInt32(ddlCity.SelectedValue);
                st.PHONE = txtPhone.Text.Trim();
                st.FAX = string.Empty;
                st.START_CAPITAL = Convert.ToDecimal(txtStartCapital.Text);
                //st.CURRENT_CAPITAL = Convert.ToDecimal(txtCurrentCapital.Text);
                //st.APPLY_DATE = Convert.ToDateTime(txtApplyDate.Text);
                //st.REVENUE_BEFORE_APPLY = Convert.ToDecimal(txtTotalRevenueBefore.Text);
                //st.TOTAL_COST_BEFORE = Convert.ToDecimal(txtTotalCostBefore.Text);
                //st.TOTAL_INVESMENT_BEFORE = Convert.ToDecimal(txtTotalInvesmentBefore.Text);
                st.REGISTER_DATE = Convert.ToDateTime(txtRegisterDate.Text);
                st.ACTIVE = rdbActive.Checked;
                st.NOTE = txtNote.Text.Trim();
                st.SEARCH_TEXT = string.Format("{0} {1} {2}", st.NAME, st.ADDRESS, st.PHONE);

                using (var rb = new RentBikeEntities())
                {
                    rb.Stores.Add(st);
                    rb.SaveChanges();
                }

                using (var rb1 = new RentBikeEntities())
                {
                    var item = rb1.InOutTypes.FirstOrDefault(s =>s.NAME == "Nhập vốn");

                    InOut io = new InOut();
                    io.IN_AMOUNT = Convert.ToDecimal(txtStartCapital.Text.Replace(",", string.Empty));
                    io.OUT_AMOUNT = 0;
                    io.CONTRACT_ID = -1;
                    io.PERIOD_ID = -1;
                    io.RENT_TYPE_ID = -1;
                    io.PERIOD_DATE = DateTime.Now;
                    io.MORE_INFO = "Vốn đầu tư ban đầu khi đăng ký cửa hàng";
                    io.STORE_ID = st.ID;
                    io.INOUT_TYPE_ID = item.ID;
                    io.INOUT_DATE = DateTime.Now;
                    io.SEARCH_TEXT = string.Format("{0} {1} ngày {2}", io.MORE_INFO, io.IN_AMOUNT, io.INOUT_DATE);

                    rb1.InOuts.Add(io);
                    rb1.SaveChanges();

                    StoreFee sf = new StoreFee();
                    sf.STORE_ID = st.ID;
                    sf.FEE_PERCENT = 0;
                    rb1.StoreFees.Add(sf);
                    rb1.SaveChanges();
                }

                WriteLog(Constants.ACTION_CREATE_STORE, false);

                scope.Complete();
            }
        }
        private void LoadInfor()
        {
            using (var db = new RentBikeEntities())
            {
                if (inOutId == 0) return;

                var io = db.InOuts.FirstOrDefault(c =>c.ID == inOutId);
                if (io != null)
                {
                    var ioType = db.InOutTypes.FirstOrDefault(c =>c.ID == io.INOUT_TYPE_ID);
                    if (ioType != null)
                    {
                        if (ioType.IS_INCOME)
                            txtFeeAmount.Text = io.IN_AMOUNT.ToString();
                        else
                            txtFeeAmount.Text = io.OUT_AMOUNT.ToString();
                    }
                    txtMoreInfo.Text = io.MORE_INFO;
                    txtFeeDate.Text = io.INOUT_DATE.Value.ToString("MM/dd/yyyy");
                }
            }
        }
        private void LoadInOutType()
        {
            List<InOutType> lst = new List<InOutType>();
            using (var db = new RentBikeEntities())
            {
                var item = from itm in db.InOutTypes
                           where itm.IS_CONTRACT == false && itm.ACTIVE == true
                           select itm;

                lst = item.ToList();

                if (lst.Count > 0)
                {
                    ddlInOutFee.Items.Add(new ListItem { Text = "Hãy chọn loại chi phí", Value = "-1"});
                    foreach(var data in lst)
                    {
                        ddlInOutFee.Items.Add(new ListItem { Text = data.NAME, Value = data.ID.ToString() });
                    }
                    if (inOutId != 0)
                    {
                        var io = db.InOuts.FirstOrDefault(c =>c.ID == inOutId);
                        ddlInOutFee.SelectedValue = io.INOUT_TYPE_ID.ToString();
                    }
                }
            }
        }
        protected string ValidateFields()
        {
            if (string.IsNullOrEmpty(ddlInOutFee.SelectedValue.Trim()) || "-1".Equals(ddlInOutFee.SelectedValue))
            {
                return "Bạn cần phải chọn loại chi phí.";
            }

            if (PERMISSION == ROLE.STAFF)
            {
                if(DateTime.Today.Subtract(Convert.ToDateTime(txtFeeDate.Text)).Days > 0)
                {
                    if (string.IsNullOrEmpty(txtUsername.Text.Trim()) || string.IsNullOrEmpty(txtPassword.Text.Trim()))
                    {
                        return "Bạn cần phải nhập tài khoản cửa hàng trưởng để xác nhận.";
                    }

                    using (var db = new RentBikeEntities())
                    {

                        var acc = db.Accounts.ToList().Where(c => c.ACC == txtUsername.Text.Trim()
                        && c.PASSWORD == Helper.EncryptPassword(txtPassword.Text.Trim())
                        && c.STORE_ID == STORE_ID).FirstOrDefault();

                        if (acc == null)
                        {
                            return "Thông tin cửa hàng trưởng bạn nhập không tồn tại.";
                        }
                    }
                }
            }

            return string.Empty;
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string result = ValidateFields();
            if (!string.IsNullOrEmpty(result))
            {
                lblMessage.Text = result;
                return;
            }

            using (TransactionScope ts = new TransactionScope())
            {

                using (var db = new RentBikeEntities())
                {
                    string message = string.Empty;
                    InOut io = db.InOuts.FirstOrDefault(c =>c.ID == inOutId);
                    if (io == null)
                    {
                        io = new InOut();
                        io.INOUT_TYPE_ID = Convert.ToInt32(ddlInOutFee.SelectedValue);
                        io.MORE_INFO = txtMoreInfo.Text.Trim();
                        io.CONTRACT_ID = -1;
                        io.PERIOD_ID = -1;
                        io.RENT_TYPE_ID = -1;
                        io.PERIOD_DATE = new DateTime(1, 1, 1);
                        if (ddlStore.Enabled == false)
                        {
                            io.STORE_ID = STORE_ID;
                        }
                        else
                        {
                            io.STORE_ID = Convert.ToInt32(ddlStore.SelectedValue);
                        }

                        var item = db.InOutTypes.FirstOrDefault(s =>s.ID == io.INOUT_TYPE_ID);

                        if (item.IS_INCOME)
                        {
                            io.IN_AMOUNT = Convert.ToDecimal(txtFeeAmount.Text.Trim());
                            io.OUT_AMOUNT = 0;
                            message = string.Format("Tài khoản {0} cửa hàng {1} thực hiện {2} ({3}) vào lúc {4}", Convert.ToString(Session["username"]), STORE_NAME, ddlInOutFee.SelectedItem.Text, Helper.FormatedAsCurrency(io.IN_AMOUNT), DateTime.Now);
                        }
                        else
                        {
                            io.IN_AMOUNT = 0;
                            io.OUT_AMOUNT = Convert.ToDecimal(txtFeeAmount.Text.Trim());
                            message = string.Format("Tài khoản {0} cửa hàng {1} thực hiện {2} ({3}) vào lúc {4}", Convert.ToString(Session["username"]), STORE_NAME, ddlInOutFee.SelectedItem.Text, Helper.FormatedAsCurrency(io.IN_AMOUNT), DateTime.Now);
                        }

                        io.INOUT_DATE = Convert.ToDateTime(txtFeeDate.Text);
                        io.SEARCH_TEXT = string.Format("{0} {1} {2}", io.INOUT_DATE, io.MORE_INFO, item.NAME);
                        io.CREATED_BY = Session["username"].ToString();
                        io.CREATED_DATE = DateTime.Now;
                        io.UPDATED_BY = Session["username"].ToString();
                        io.UPDATED_DATE = DateTime.Now;

                        db.InOuts.Add(io);
                        Helper.WriteLog(Convert.ToString(Session["username"]), STORE_NAME, Constants.ACTION_CREATE_INOUT, message, false);
                    }
                    else
                    {
                        io.INOUT_TYPE_ID = Convert.ToInt32(ddlInOutFee.SelectedValue);
                        io.INOUT_DATE = Convert.ToDateTime(txtFeeDate.Text);
                        io.MORE_INFO = txtMoreInfo.Text.Trim();
                        if (ddlStore.Enabled == false)
                        {
                            io.STORE_ID = Convert.ToInt32(Session["store_id"]);
                        }
                        else
                        {
                            io.STORE_ID = Convert.ToInt32(ddlStore.SelectedValue);
                        }

                        var item = db.InOutTypes.FirstOrDefault(s =>s.ID == io.INOUT_TYPE_ID);
                        if (item.IS_INCOME)
                        {
                            io.IN_AMOUNT = Convert.ToDecimal(txtFeeAmount.Text.Trim());
                            io.OUT_AMOUNT = 0;
                            message = string.Format("Tài khoản {0} cửa hàng {1} thực hiện chỉnh sửa {2} ({3}) vào lúc {4}", Convert.ToString(Session["username"]), STORE_NAME, ddlInOutFee.SelectedItem.Text, Helper.FormatedAsCurrency(io.IN_AMOUNT), DateTime.Now);
                        }
                        else
                        {
                            io.IN_AMOUNT = 0;
                            io.OUT_AMOUNT = Convert.ToDecimal(txtFeeAmount.Text.Trim());
                            message = string.Format("Tài khoản {0} cửa hàng {1} thực hiện chỉnh sửa {2} ({3}) vào lúc {4}", Convert.ToString(Session["username"]), STORE_NAME, ddlInOutFee.SelectedItem.Text, Helper.FormatedAsCurrency(io.IN_AMOUNT), DateTime.Now);
                        }
                        io.SEARCH_TEXT = string.Format("{0} {1} {2}", io.INOUT_DATE, io.MORE_INFO, item.NAME);
                        io.UPDATED_BY = Session["username"].ToString();
                        io.UPDATED_DATE = DateTime.Now;

                        Helper.WriteLog(Convert.ToString(Session["username"]), STORE_NAME, Constants.ACTION_CREATE_INOUT, message, false);
                    }
                    db.SaveChanges();
                }

                ts.Complete();
            }
            Response.Redirect("FormDailyIncomeOutcome.aspx", false);
        }