示例#1
0
        internal static DataSet GetSyncData(DateTime toDate)
        {
            MealSetTableAdapter mealSetTA = new MealSetTableAdapter();
            ScheduleTableAdapter scheduleTA = new ScheduleTableAdapter();
            ScheduleMealSetDetailTableAdapter scheduleMealSetDetailTA = new ScheduleMealSetDetailTableAdapter();
            ServingTimeTableAdapter servingTimeTA = new ServingTimeTableAdapter();
            TransactionHistoryTableAdapter transactionHistoryTA = new TransactionHistoryTableAdapter();
            TransactionTypeTableAdapter transactionTypeTA = new TransactionTypeTableAdapter();
            UserInfoTableAdapter userInfoTA = new UserInfoTableAdapter();
            UserTypeTableAdapter userTypeTA = new UserTypeTableAdapter();

            DateTime minDate = (DateTime)SqlDateTime.MinValue;

            DataSet ds = new DataSet();
            ds.Tables.Add(userTypeTA.GetDataByDate(minDate, toDate));
            ds.Tables.Add(userInfoTA.GetDataByDate(minDate, toDate));
            ds.Tables.Add(mealSetTA.GetDataByDate(minDate, toDate));
            ds.Tables.Add(servingTimeTA.GetDataByDate(minDate, toDate));
            ds.Tables.Add(scheduleTA.GetDataByDate(minDate, toDate));
            ds.Tables.Add(scheduleMealSetDetailTA.GetDataByDate(minDate, toDate));
            ds.Tables.Add(transactionTypeTA.GetDataByDate(minDate, toDate));
            ds.Tables.Add(transactionHistoryTA.GetDataByDate(minDate, toDate));

            return ds;
        }
示例#2
0
        public ActionResult AddUser()
        {
            UserTypeTableAdapter userTypeAdapter = new UserTypeTableAdapter();
            DataTable userTypeDT = userTypeAdapter.GetData();

            List<SelectListItem> items = new List<SelectListItem>();
            foreach (DataRow row in userTypeDT.Rows)
            {
                items.Add(new SelectListItem { Text = row["TypeName"].ToString(), Value = row["TypeShortName"].ToString() });
            }
            ViewData["UserType"] = items;
            return View();
        }
示例#3
0
        public ActionResult AddNewUserType(UserTypeModel userTypeModel)
        {
            if (!ModelState.IsValid)
            {
                return View(userTypeModel);
            }

            UserTypeTableAdapter userTypeTableAdapter = new UserTypeTableAdapter();

            try
            {
                string typeShortName = userTypeModel.typeShortName;
                string typeName = userTypeModel.typeName;
                int mealValue = userTypeModel.mealValue;
                int? moreMealValue = 0;

                if (!string.IsNullOrEmpty(userTypeModel.moreMealValue.ToString()))
                {
                    moreMealValue = userTypeModel.moreMealValue;
                }

                string description = userTypeModel.description;
                Boolean canDebt = userTypeModel.canDebt;
                Boolean canEatMore = userTypeModel.canEatMore;
                DateTime date = DateTime.Now;
                string updateBy = AccountInfo.GetUserName(Request);
                userTypeTableAdapter.InsertNewUserType(typeShortName, typeName, mealValue, moreMealValue, description, canDebt, canEatMore, date, updateBy, date);
                XmlSync.SaveUserTypeXml(typeShortName, typeName, mealValue, moreMealValue, description, canDebt, canEatMore, date, updateBy, date, null);
                Session["addUserType"] = "Thêm mới thành công!";
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
                Session["addUserType"] = "Thêm mới thất bại!";
            }
            return RedirectToAction("AddNewUserType", "Account");
        }
示例#4
0
 public ActionResult ViewUserType()
 {
     DataTable dataTable = new DataTable();
     UserTypeTableAdapter userTypeTableAdapter = new UserTypeTableAdapter();
     try
     {
         dataTable = userTypeTableAdapter.GetData();
     }
     catch (Exception ex)
     {
         Log.ErrorLog(ex.Message);
     }
     return View(dataTable);
 }
示例#5
0
        public ActionResult ListUser()
        {
            UserInfoDetailTableAdapter userInfoAdapter = new UserInfoDetailTableAdapter();
            DataTable userDT = new DataTable();

            string username = Request.QueryString["username"];
            string name = Request.QueryString["name"];
            string userType = Request.QueryString["userType"];
            string role = Request.QueryString["role"];
            string active = Request.QueryString["active"];

            string page = Request.QueryString["page"];
            string amountPerPage = Request.QueryString["amountPerPage"];

            if (String.IsNullOrWhiteSpace(userType))
            {
                userType = null;
            }

            int role_;
            if (!int.TryParse(role, out role_))
            {
                role = null;
            }

            int active_;
            if (!int.TryParse(active, out active_))
            {
                active = null;
            }

            int page_;
            if (!int.TryParse(page, out page_))
            {
                page = null;
                page_ = 1;
            }

            int amountPerPage_;
            if (!int.TryParse(amountPerPage, out amountPerPage_))
            {
                amountPerPage = "10";
                amountPerPage_ = 10;
            }

            try
            {
                string query = "SELECT * FROM ( SELECT UserInfo.Username, UserInfo.Name, UserInfo.TypeShortName, "
                    + "UserInfo.AmountOfMoney, UserInfo.LastUpdatedMoney, UserInfo.FingerPosition, UserInfo.IsCafeteriaStaff, "
                    + "UserInfo.InsertedDate, UserInfo.UpdatedBy, UserInfo.LastUpdated, Account.Email, Account.Role, "
                    + "UserType.TypeName, UserType.MealValue, UserType.MoreMealValue, UserType.CanDebt, "
                    + "UserType.CanEatMore, UserInfo.IsActive, ROW_NUMBER() OVER (order by UserInfo.InsertedDate DESC) AS RowNum "
                    + "FROM UserInfo INNER JOIN Account ON UserInfo.Username = Account.Username INNER JOIN "
                    + "UserType ON UserInfo.TypeShortName = UserType.TypeShortName ";
                string countQuery = "SELECT COUNT(UserInfo.Username) FROM UserInfo INNER JOIN Account "
                    + "ON UserInfo.Username = Account.Username ";
                string conditionQuery = "";

                if (username != null || name != null || userType != null || role != null || active != null)
                {
                    conditionQuery += "WHERE ";
                    bool isFirst = false;

                    if (username != null)
                    {
                        conditionQuery += "UserInfo.Username like '%" + username + "%' ";
                        isFirst = true;
                    }

                    if (name != null)
                    {
                        if (isFirst)
                        {
                            conditionQuery += "AND ";
                        }
                        conditionQuery += "UserInfo.Name like N'%" + name + "%' ";
                        isFirst = true;
                    }

                    if (userType != null)
                    {
                        if (isFirst)
                        {
                            conditionQuery += "AND ";
                        }
                        conditionQuery += "UserInfo.TypeShortName = '" + userType + "' ";
                        isFirst = true;
                    }

                    if (role != null)
                    {
                        if (isFirst)
                        {
                            conditionQuery += "AND ";
                        }
                        conditionQuery += "Account.Role = " + role + " ";
                        isFirst = true;
                    }

                    if (active != null)
                    {
                        if (isFirst)
                        {
                            conditionQuery += "AND ";
                        }
                        conditionQuery += "UserInfo.IsActive = " + active + " ";
                    }
                }

                int minRowNum = ((page_ - 1) * amountPerPage_) + 1;
                int maxRowNum = page_ * amountPerPage_;
                query += conditionQuery;
                query += ") AS UI WHERE UI.RowNum BETWEEN " + minRowNum + " AND " + maxRowNum + " ";

                SqlCommand countCmd = new SqlCommand(countQuery + conditionQuery, userInfoAdapter.Connection);
                SqlCommand getDataCmd = new SqlCommand(query, userInfoAdapter.Connection);
                SqlDataAdapter getDataAdapter = new SqlDataAdapter(getDataCmd);

                userInfoAdapter.Connection.Open();
                int count = (int)countCmd.ExecuteScalar();

                getDataAdapter.Fill(userDT);

                int maxPage = (count / amountPerPage_);
                if (count % amountPerPage_ != 0)
                {
                    maxPage++;
                }

                ViewBag.maxPage = maxPage;
                if (page_ > maxPage)
                {
                    page_ = maxPage;
                }

                ViewBag.curPage = page_;
                ViewBag.amountPerPage = amountPerPage_;

                ViewBag.roleList = AccountInfo.GetRoleListVnese();

                DataTable userTypeDT = new UserTypeTableAdapter().GetData();
                List<KeyValuePair<string, string>> userTypes = new List<KeyValuePair<string, string>>();
                foreach (DataRow row in userTypeDT.Rows)
                {
                    userTypes.Add(new KeyValuePair<string, string>(row.Field<string>("TypeShortName"), row.Field<string>("TypeName")));
                }
                ViewBag.userTypes = userTypes;
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
                return View("Error");
            }

            return View(userDT);
        }
示例#6
0
 public ActionResult EditUserType(string typeShortName)
 {
     UserTypeModel userTypeModel = new UserTypeModel();
     DataTable userTypeDataTable = new DataTable();
     UserTypeTableAdapter userTypeTableAdapter = new UserTypeTableAdapter();
     try
     {
         userTypeDataTable = userTypeTableAdapter.GetDataByTypeShortName(typeShortName);
         userTypeModel.typeShortName = Convert.ToString(userTypeDataTable.Rows[0]["TypeShortName"]);
         userTypeModel.typeName = Convert.ToString(userTypeDataTable.Rows[0]["TypeName"]);
         userTypeModel.mealValue = Convert.ToInt32(userTypeDataTable.Rows[0]["MealValue"]);
         userTypeModel.moreMealValue = Convert.ToInt32(userTypeDataTable.Rows[0]["MoreMealValue"]);
         userTypeModel.description = Convert.ToString(userTypeDataTable.Rows[0]["Description"]);
         userTypeModel.canDebt = Convert.ToBoolean(userTypeDataTable.Rows[0]["CanDebt"]);
         userTypeModel.canEatMore = Convert.ToBoolean(userTypeDataTable.Rows[0]["CanEatMore"]);
         userTypeModel.insertedDate = Convert.ToDateTime(userTypeDataTable.Rows[0]["InsertedDate"]);
         userTypeModel.lastUpdated = Convert.ToDateTime(userTypeDataTable.Rows[0]["LastUpdated"]);
         userTypeModel.updatedBy = Convert.ToString(userTypeDataTable.Rows[0]["UpdatedBy"]);
     }
     catch (Exception ex)
     {
         Log.ErrorLog(ex.Message);
         return RedirectToAction("Error", "Error");
     }
     return View(userTypeModel);
 }
示例#7
0
        public ActionResult EditUser(EditUserModel model)
        {
            UserTypeTableAdapter userTypeAdapter = new UserTypeTableAdapter();
            DataTable userTypeDT = userTypeAdapter.GetData();

            List<SelectListItem> items = new List<SelectListItem>();
            foreach (DataRow row in userTypeDT.Rows)
            {
                items.Add(new SelectListItem { Text = row["TypeName"].ToString(), Value = row["TypeShortName"].ToString() });
            }
            ViewData["UserType"] = items;

            if (!ModelState.IsValid)
            {
                return View(model);
            }

            string email = model.Email;
            if (!string.IsNullOrEmpty(email))
            {
                AccountTableAdapter AccountAdapter = new AccountTableAdapter();
                DataTable dt = AccountAdapter.GetDataByUsername(model.Username);

                if (!dt.Rows[0]["Email"].ToString().Equals(email))
                {
                    DataTable AccountDT = AccountAdapter.GetDataByEmail(email);

                    if (AccountDT.Rows.Count == 1)
                    {
                        if (!AccountDT.Rows[0]["Username"].ToString().Equals(model.Username))
                        {
                            Log.ActivityLog(AccountDT.Rows[0]["Username"].ToString().Equals(model.Username).ToString());
                            ModelState.AddModelError("", "Email đã tồn tại");
                            return View(model);
                        }
                    }
                }
            }

            string updateBy = AccountInfo.GetUserName(Request);
            DateTime date = DateTime.Now;
            string username = model.Username;
            string name = model.Name;
            string userTypeID = model.UserTypeID;
            bool isCafeteriaStaff = false;
            int role = model.Role;
            bool isActive = model.isActive;
            if (role == 2)
            {
                isCafeteriaStaff = true;
            }

            AccountTableAdapter accountAdapter = new AccountTableAdapter();
            UserInfoTableAdapter userInfoAdapter = new UserInfoTableAdapter();

            DataTable userInfoDT = userInfoAdapter.GetDataByUsername(username);
            DataRow userInfoRow = userInfoDT.Rows[0];

            int amountOfMoney = userInfoRow.Field<int>("AmountOfMoney");
            DateTime lastUpdatedMoney = userInfoRow.Field<DateTime>("LastUpdatedMoney");
            byte[] fingerPrintIMG = userInfoRow.Field<byte[]>("FingerPrintIMG");
            DateTime? lastUpdatedFingerPrint = userInfoRow.Field<DateTime?>("LastUpdatedFingerPrint");
            int? fingerPosition = userInfoRow.Field<int?>("FingerPosition");
            DateTime insertedDate = userInfoRow.Field<DateTime>("InsertedDate");

            accountAdapter.Connection.Open();
            userInfoAdapter.Connection = accountAdapter.Connection;

            using (SqlTransaction transaction = accountAdapter.Connection.BeginTransaction())
            {
                accountAdapter.AttachTransaction(transaction);
                userInfoAdapter.AttachTransaction(transaction);

                try
                {
                    userInfoAdapter.UpdateUserInfo(username, name, userTypeID, amountOfMoney, lastUpdatedMoney, fingerPrintIMG
                        , lastUpdatedFingerPrint, fingerPosition, isCafeteriaStaff, isActive, insertedDate, updateBy, date, username);
                    Log.ActivityLog("Update to UserInfo: username = "******"Update to Account: username = "******"editUser"] = "******";
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    Log.ErrorLog(ex.Message);
                    Session["editUser"] = "******";
                }
            }

            return RedirectToAction("EditUser", "Account", new { @username = model.Username });
        }
示例#8
0
        public ActionResult EditUser(string username)
        {
            UserTypeTableAdapter userTypeAdapter = new UserTypeTableAdapter();
            DataTable userTypeDT = userTypeAdapter.GetData();

            List<SelectListItem> items = new List<SelectListItem>();
            foreach (DataRow row in userTypeDT.Rows)
            {
                items.Add(new SelectListItem { Text = row["TypeName"].ToString(), Value = row["TypeShortName"].ToString() });
            }
            ViewData["UserType"] = items;

            EditUserModel userInfo = new EditUserModel();
            UserInfoDetailTableAdapter userinfoAdapter = new UserInfoDetailTableAdapter();
            DataTable userinfoDataTable = userinfoAdapter.GetDataByUsername(username);

            try
            {
                userInfo.Username = username;
                userInfo.Name = userinfoDataTable.Rows[0]["Name"].ToString();
                userInfo.UserTypeID = (string)userinfoDataTable.Rows[0]["TypeShortName"];
                userInfo.Email = userinfoDataTable.Rows[0]["Email"].ToString();
                userInfo.Role = (int)userinfoDataTable.Rows[0]["Role"];
                userInfo.isActive = (bool)userinfoDataTable.Rows[0]["IsActive"];

                return View(userInfo);
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
                return RedirectToAction("Error", "Error");
            }
        }
示例#9
0
 public ActionResult DetailsUserType(string typeShortName)
 {
     UserTypeTableAdapter userTypeDataTableAdapter = new UserTypeTableAdapter();
     DataTable dt = userTypeDataTableAdapter.GetDataByTypeShortName(typeShortName);
     UserTypeModel userTypeModel = new UserTypeModel();
     try
     {
         userTypeModel.typeShortName = Convert.ToString(dt.Rows[0]["TypeShortName"]);
         userTypeModel.typeName = Convert.ToString(dt.Rows[0]["TypeName"]);
         userTypeModel.mealValue = Convert.ToInt32(dt.Rows[0]["MealValue"]);
         userTypeModel.moreMealValue = Convert.ToInt32(dt.Rows[0]["MoreMealValue"]);
         userTypeModel.description = Convert.ToString(dt.Rows[0]["Description"]);
         userTypeModel.canDebt = Convert.ToBoolean(dt.Rows[0]["CanDebt"]);
         userTypeModel.canEatMore = Convert.ToBoolean(dt.Rows[0]["CanEatMore"]);
     }
     catch (Exception ex)
     {
         Log.ErrorLog(ex.Message);
     }
     if (userTypeModel == null)
     {
         return HttpNotFound();
     }
     return View(userTypeModel);
 }
示例#10
0
        public ActionResult DeleteUserType(string typeShortName)
        {
            UserTypeTableAdapter userTypeTableAdapter = new UserTypeTableAdapter();

            try
            {
                userTypeTableAdapter.Delete(typeShortName);
                Session["deleteUserType"] = "Xóa thành công!";
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
                Session["deleteUserType"] = "Xóa thất bại! Loại người dùng này đang được sử dụng.";
            }

            return RedirectToAction("ViewUserType", "Account");
        }