Ejemplo n.º 1
0
        public ActionResult Register(Register model)
        {
            OKhachHang khachHang = new OKhachHang
            {
                TenKhach  = model.FullName,
                DienThoai = model.Phone,
                Email     = model.Email,
            };

            khService.Add(khachHang);
            int      idKhach = khService.GetLastId();
            OAccount account = new OAccount {
                Email   = khachHang.Email,
                MaKhach = idKhach,
                MatKhau = model.Password,
                TenDN   = model.UserName,
                MaQuyen = 3,
            };

            if (accountService.Register(account))
            {
                Session["Account"] = account;
                //Random rd = new Random();
                //string strRandom;
                //strRandom = rd.Next(1, 1000).ToString();
                //Session["RandomText"] = strRandom;
                //SendMailActive(account.Email, strRandom);
                return(RedirectToAction("Index", "Home"));
            }
            return(View("Login"));
        }
Ejemplo n.º 2
0
        public ActionResult Create()
        {
            OAccount data = new OAccount();

            data.TrangThai    = false;
            ViewBag.Customers = new SelectList(khService.GetAll(), "MaKhach", "TenKhach");

            ViewBag.ListRoles = new SelectList(accountService.GetAllRole(), "MaQuyen", "TenQuyen");
            return(View(data));
        }
Ejemplo n.º 3
0
        public OAccount GetById(string matk)
        {
            conn.connect();
            var comm = new SqlCommand("Account_GetByMaTK", conn.db);

            comm.CommandType = System.Data.CommandType.StoredProcedure;
            comm.Parameters.Add("@MaTK", SqlDbType.UniqueIdentifier).Value = Guid.Parse(matk);
            DataTable dt = new DataTable();

            dt.Load(comm.ExecuteReader());
            OAccount oAccount = new OAccount();

            oAccount = Help.DAL.ConvertDataTable <OAccount>(dt).FirstOrDefault();
            conn.Close();
            return(oAccount);
        }
Ejemplo n.º 4
0
        public OAccount Get(string username, string password)
        {
            conn.connect();
            var comm = new SqlCommand("Account_Get", conn.db);

            comm.CommandType = System.Data.CommandType.StoredProcedure;
            comm.Parameters.Add("@UserName", SqlDbType.NVarChar).Value = username;
            comm.Parameters.Add("@Password", SqlDbType.NVarChar).Value = password;
            DataTable dt = new DataTable();

            dt.Load(comm.ExecuteReader());
            OAccount oAccount = new OAccount();

            oAccount = Help.DAL.ConvertDataTable <OAccount>(dt).FirstOrDefault();
            conn.Close();
            return(oAccount);
        }
Ejemplo n.º 5
0
        public bool UnLock(OAccount item)
        {
            conn.connect();
            var comm = new SqlCommand("Account_UnLock", conn.db);

            comm.CommandType = CommandType.StoredProcedure;
            if (comm == null)
            {
                return(false);
            }
            comm.Parameters.Add("@MaTK", SqlDbType.UniqueIdentifier).Value = item.MaTK;

            if (comm.ExecuteNonQuery() != 0)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 6
0
        public bool Register(OAccount account)
        {
            conn.connect();
            var comm = new SqlCommand("Account_Register", conn.db);

            comm.CommandType = System.Data.CommandType.StoredProcedure;
            comm.Parameters.Add("@UserName", SqlDbType.NVarChar).Value = account.TenDN;
            comm.Parameters.Add("@Password", SqlDbType.NVarChar).Value = Help.Helper.EncodeSHA1(account.MatKhau);
            comm.Parameters.Add("@Email", SqlDbType.NVarChar).Value    = account.Email;

            comm.Parameters.Add(new SqlParameter("@MaKhach", account.MaKhach ?? (object)DBNull.Value));

            SqlDataReader reader   = comm.ExecuteReader();
            OAccount      oAccount = new OAccount();

            conn.Close();
            return(true);
        }
Ejemplo n.º 7
0
        public ActionResult Update(string matk, string username, string email)
        {
            var account = new OAccount {
                TenDN = username,
                Email = email,
                MaTK  = Guid.Parse(matk)
            };

            if (accountService.Update(account))
            {
                if (Session["Admin"] != null)
                {
                    Session["Admin"] = account;
                }
                return(Json(new { Success = true, Message = "Sửa thông tin thành công!", Model = account }));
            }
            return(Json(new { Success = false, Message = "Sửa thông tin thất bại!" }));
        }
Ejemplo n.º 8
0
        public bool Active(OAccount item)
        {
            conn.connect();
            var comm = new SqlCommand("Account_Active", conn.db);

            comm.CommandType = CommandType.StoredProcedure;
            if (comm == null)
            {
                return(false);
            }
            comm.Parameters.Add("@UserName", SqlDbType.NVarChar).Value = item.TenDN;
            comm.Parameters.Add("@Password", SqlDbType.NVarChar).Value = Help.Helper.EncodeSHA1(item.MatKhau);

            if (comm.ExecuteNonQuery() != 0)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 9
0
        public bool ChangePass(OAccount item, string newpass)
        {
            conn.connect();
            var comm = new SqlCommand("Account_ChangePass_Admin", conn.db);

            comm.CommandType = CommandType.StoredProcedure;
            if (comm == null)
            {
                return(false);
            }
            comm.Parameters.Add("@UserName", SqlDbType.NVarChar).Value = item.TenDN;
            comm.Parameters.Add("@OldPass", SqlDbType.NVarChar).Value  = Help.Helper.EncodeSHA1(item.MatKhau);
            comm.Parameters.Add("@NewPass", SqlDbType.NVarChar).Value  = Help.Helper.EncodeSHA1(newpass);

            if (comm.ExecuteNonQuery() != 0)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 10
0
        public void Add(OAccount account)
        {
            conn.connect();
            var comm = new SqlCommand("Account_Add", conn.db);

            comm.CommandType = System.Data.CommandType.StoredProcedure;
            comm.Parameters.Add("@TenDN", SqlDbType.NVarChar).Value   = account.TenDN;
            comm.Parameters.Add("@MatKhau", SqlDbType.NVarChar).Value = Help.Helper.EncodeSHA1(account.MatKhau);
            comm.Parameters.Add("@Email", SqlDbType.NVarChar).Value   = account.Email;
            comm.Parameters.Add("@MaQuyen", SqlDbType.Int).Value      = account.MaQuyen;

            comm.Parameters.Add("@TrangThai", SqlDbType.Bit).Value = account.TrangThai;

            comm.Parameters.Add(new SqlParameter("@MaKhach", account.MaKhach ?? (object)DBNull.Value));

            SqlDataReader reader   = comm.ExecuteReader();
            OAccount      oAccount = new OAccount();

            conn.Close();
        }
Ejemplo n.º 11
0
        public bool Update(OAccount item)
        {
            conn.connect();
            var comm = new SqlCommand("Account_Update", conn.db);

            comm.CommandType = CommandType.StoredProcedure;
            if (comm == null)
            {
                return(false);
            }
            comm.Parameters.Add("@MaTK", SqlDbType.UniqueIdentifier).Value = item.MaTK;
            comm.Parameters.Add("@UserName", SqlDbType.NVarChar).Value     = item.TenDN;
            comm.Parameters.Add(new SqlParameter("@Email", item.Email ?? (object)DBNull.Value));

            if (comm.ExecuteNonQuery() != 0)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 12
0
        public ActionResult Create(OAccount model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    accountService.Add(model);
                    return(RedirectToAction("Search", "QuanLyNguoiDung"));
                }
                catch (Exception e)
                {
                }
            }

            ViewBag.IsEdit = true;

            ViewBag.Customers = new SelectList(khService.GetAll(), "MaKhach", "TenKhach");

            ViewBag.ListRoles = new SelectList(accountService.GetAllRole(), "MaQuyen", "TenQuyen");
            return(View(model));
        }
Ejemplo n.º 13
0
        private async void Save_Click(object sender, RoutedEventArgs e)
        {
            if (numberBox.Text.Length < numberBox.MaxLength || !numberRx.IsMatch(numberBox.Text))
            {
                numberBox.Focus(FocusState.Programmatic); return;
            }
            if (passwordBox.Password.Length == 0 || carrierBox.SelectedIndex == 1 && passwordBox.Password.Length != BitePasswordLength)
            {
                passwordBox.Focus(FocusState.Programmatic); return;
            }

            if (Network.Disconnected)
            {
                await new MessageDialog(DisplayResources.Strings.GetString("NetworkOffline")).ShowAsync();
                return;
            }

            SetEnabled(false);
            var statusBar = StatusBar.GetForCurrentView();

            statusBar.ProgressIndicator.Text = DisplayResources.Strings.GetString("LoggingIn");
            await statusBar.ProgressIndicator.ShowAsync();

            string  number = numberBox.Text;
            Account account = null;
            string  errorMessage = null, errorMessageId = null;

            try {
                switch (carrierBox.SelectedIndex)
                {
                case 0:
                    errorMessageId = "ZZLoginFailure";
                    account        = await ZZAccount.Login(client, numberBox.Text, passwordBox.Password);

                    break;

                case 1:
                    errorMessageId = "BiteLoginFailure";
                    account        = await BiteAccount.Login(client, numberBox.Text, passwordBox.Password.ToUpper());

                    break;

                case 2:
                    errorMessageId = "OLoginFailure";
                    account        = await OAccount.Login(client, numberBox.Text, passwordBox.Password);

                    break;
                }
                if (account == null)
                {
                    errorMessage = DisplayResources.Strings.GetString(errorMessageId);
                }
            } catch (Exception ex) {
                errorMessage = ex.Message + Environment.NewLine + DisplayResources.Strings.GetString(errorMessageId);
            }

            await statusBar.ProgressIndicator.HideAsync();

            if (errorMessage != null)
            {
                await new MessageDialog(errorMessage).ShowAsync();
                SetEnabled(true);
                return;
            }

            account.RefreshInterval = TimeSpan.FromMinutes(30);
            account.Caption         = string.Concat(number.Substring(0, 2), " ", number.Substring(2, 3), " ", number.Substring(5, 3));
            app.Accounts.Add(account);
            Settings.SetAccounts(app.Accounts);
            app.HaveAccountsChanged = false;
            Settings.AddAccount(account);

            statusBar.ProgressIndicator.Text = DisplayResources.Strings.GetString("Refreshing");
            await statusBar.ProgressIndicator.ShowAsync();

            errorMessage = null;
            try {
                await account.SetBalance(client);
            } catch (Exception) {
                // Ja nespēja noskaidrot atlikumu, ļauj lietotājam to vēlāk pamēģināt.
            }
            await statusBar.ProgressIndicator.HideAsync();

            app.Account = account;
            Frame.Navigate(typeof(EditAccountPage));
        }
Ejemplo n.º 14
0
 private static OAccount findParentLevel(OAccount acc, int levelRemain)
 {
     while (levelRemain > 0)
     {
         OAccount result = findParentLevel(acc.Parent, levelRemain - 1);
         return result;
     }
     return acc;
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Return a Data Table representing the Budget Detail Summary Report table structure.
        /// </summary>
        /// <param name="location"></param>
        /// <param name="YTD"></param>
        /// <returns>DataTable</returns>
        public static DataTable BudgetDetailSummaryReport(OLocation location, DateTime YTD, OAccount account)
        {
            // Validate User Access Right
            // TO DO

            // Create Account Condition
            ExpressionCondition cond = Query.True;
            if (null != account)
                cond = cond & TablesLogic.tBudgetTransactionLog.Account.HierarchyPath.Like(account.HierarchyPath + "%");

            DateTime formattedYTD = new DateTime(YTD.Year, YTD.Month, 1);
            DataTable result = new DataTable("BudgetDetailSummary");
            // Table structure: Expenses | Y____ Budget (a) | Current Month Actual | 
            // YTD Actual (b) | YTD Budget (c) | Variance (=(e)/(a)) | Budget Balance ((a)-(b))
            result.Columns.Add("ParentAccount");
            result.Columns.Add("Expenses");
            result.Columns.Add("YearBudget", typeof(decimal));
            result.Columns.Add("CurrentMonthActual", typeof(decimal));
            result.Columns.Add("YTDActual", typeof(decimal));
            result.Columns.Add("YTDBudget", typeof(decimal));
            result.Columns.Add("Variance", typeof(decimal));
            result.Columns.Add("BudgetBalance", typeof(decimal));

            OBudgetPeriod budgetPeriod = TablesLogic.tBudgetPeriod.Load(
                TablesLogic.tBudgetPeriod.Budget.ApplicableLocations.ObjectID == location.ObjectID
                &
                TablesLogic.tBudgetPeriod.StartDate <= formattedYTD
                &
                TablesLogic.tBudgetPeriod.EndDate >= formattedYTD
                );

            if (budgetPeriod == null) return result;

            OBudget budget = budgetPeriod.Budget;

            DataList<OBudgetPeriodOpeningBalance> openingBalances = budgetPeriod.BudgetPeriodOpeningBalances;

            int count = 1;

            foreach (OBudgetPeriodOpeningBalance balance in openingBalances)
            {
                DataRow row = result.NewRow();

                row["Expenses"] = balance.Account.Parent.ObjectName;
                row["ParentAccount"] = balance.Account.ObjectName;
                row["YearBudget"] = balance.TotalOpeningBalance;

                decimal currentMonthActual = TablesLogic.tBudgetTransactionLog
                    .Select(TablesLogic.tBudgetTransactionLog.TransactionAmount.Sum())
                    .Where(TablesLogic.tBudgetTransactionLog.IsDeleted == 0
                           &
                           TablesLogic.tBudgetTransactionLog.BudgetID == budget.ObjectID
                           &
                           TablesLogic.tBudgetTransactionLog.AccountID == balance.AccountID
                           &
                           TablesLogic.tBudgetTransactionLog.TransactionType.In(1, 2, 12, 13, 14)
                           &
                           TablesLogic.tBudgetTransactionLog.DateOfExpenditure >= formattedYTD
                           &
                           TablesLogic.tBudgetTransactionLog.DateOfExpenditure <= formattedYTD.AddMonths(1)
                           &
                           cond);
                row["CurrentMonthActual"] = currentMonthActual;

                decimal YTDActual = TablesLogic.tBudgetTransactionLog
                    .Select(TablesLogic.tBudgetTransactionLog.TransactionAmount.Sum())
                    .Where(TablesLogic.tBudgetTransactionLog.IsDeleted == 0
                           &
                           TablesLogic.tBudgetTransactionLog.BudgetID == budget.ObjectID
                           &
                           TablesLogic.tBudgetTransactionLog.AccountID == balance.AccountID
                           &
                           TablesLogic.tBudgetTransactionLog.TransactionType.In(1, 2, 12, 13, 14)
                           &
                           TablesLogic.tBudgetTransactionLog.DateOfExpenditure >= budgetPeriod.StartDate
                           &
                           TablesLogic.tBudgetTransactionLog.DateOfExpenditure <= formattedYTD.AddMonths(1)
                           &
                           cond);
                row["YTDActual"] = YTDActual;

                decimal YTDBudget = 0;
                switch (formattedYTD.Month)
                {
                    case 12: YTDBudget += balance.OpeningBalance12.Value;
                        goto case 11;
                    case 11: YTDBudget += balance.OpeningBalance11.Value;
                        goto case 10;
                    case 10: YTDBudget += balance.OpeningBalance10.Value;
                        goto case 9;
                    case 9: YTDBudget += balance.OpeningBalance09.Value;
                        goto case 8;
                    case 8: YTDBudget += balance.OpeningBalance08.Value;
                        goto case 7;
                    case 7: YTDBudget += balance.OpeningBalance07.Value;
                        goto case 6;
                    case 6: YTDBudget += balance.OpeningBalance06.Value;
                        goto case 5;
                    case 5: YTDBudget += balance.OpeningBalance05.Value;
                        goto case 4;
                    case 4: YTDBudget += balance.OpeningBalance04.Value;
                        goto case 3;
                    case 3: YTDBudget += balance.OpeningBalance03.Value;
                        goto case 2;
                    case 2: YTDBudget += balance.OpeningBalance02.Value;
                        goto case 1;
                    case 1: YTDBudget += balance.OpeningBalance01.Value;
                        break;
                }

                row["YTDBudget"] = YTDBudget;

                decimal budgetBalance = balance.TotalOpeningBalance.Value - Convert.ToDecimal(row["YTDActual"]);

                row["BudgetBalance"] = budgetBalance;

                row["Variance"] = (balance.TotalOpeningBalance.Value != 0)
                                    ? budgetBalance / balance.TotalOpeningBalance.Value
                                    : 0;

                result.Rows.Add(row);
            }

            return result;
        }
Ejemplo n.º 16
0
        public ActionResult DatHang()
        {
            string  strChuoi = "";
            decimal total    = 0;

            ShoppingCartModels model = new ShoppingCartModels();

            model.Cart = (Carts)Session["Cart"];

            if (Session["Account"] == null || Session["Account"].ToString() == "")
            {
                //return RedirectToAction("Login", "Account");
                return(Json(new { Success = false, Url = Url.Action("Login", "Account") }));
            }

            OAccount account = (OAccount)Session["Account"];
            OAccount kh      = accountService.Get(account.TenDN, account.MatKhau);

            if (kh == null)
            {
                return(Redirect("Error"));
            }
            OHoaDonBan ddh = new OHoaDonBan
            {
                MaKhach   = kh.MaKhach,
                TrangThai = 0,
            };

            hdbService.Add(ddh);
            int idHdb = hdbService.GetLastId();

            foreach (var item in model.Cart.ListItem)
            {
                cTHDBService.Add(new OCTHDB
                {
                    MaHDB     = idHdb,
                    MaSanPham = item.ProductId,
                    SoLuong   = item.Quantity,
                    ThanhTien = item.Total,
                });

                strChuoi += "<li> Tên sản phẩm: " + item.ProductName + "</li> ";
                strChuoi += "<li> Giá: " + item.Price.ToString("#,##") + " đ</li> ";
                strChuoi += "<li> Số lượng: " + item.Quantity + "</li> ";
                total    += item.Total;
                var product = sachService.Get(new OSanPham {
                    MaSanPham = item.ProductId
                });
                var newproduct = sachService.Get(new OSanPham {
                    MaSanPham = item.ProductId
                });
                if (product != null)
                {
                    newproduct.SoLuong = product.SoLuong - item.Quantity;
                    sachService.Update(newproduct);
                }
            }
            strChuoi += "<li>Tổng tiền: " + total.ToString("#,##") + " đ </li>";
            SendEmail(kh.Email, strChuoi);
            Session["Cart"] = null;

            return(Json(new { Success = true, Message = "Đặt hàng thành công. Bạn hãy check email nhé !" }));
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Creates a tree node from the specified OAccount
 /// object.
 /// </summary>
 /// <param name="account"></param>
 /// <returns></returns>
 protected TreeNode CreateNode(OAccount account)
 {
     if (account != null)
         return CreateTreeNode(
             account.ObjectName,
             account.ObjectID.ToString(),
             account.Type == 0 ?
             ConfigurationManager.AppSettings["ImageUrl_LocationLogical"] :
             ConfigurationManager.AppSettings["ImageUrl_LocationPhysical"],
             "OAccount",
             account.Type == 0 ? selectCategory : selectItem);
     return null;
 }