Example #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;
        }
        public ActionResult WithdrawMoney(WithdrawMoney model)
        {
            ViewBag.message = "";

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

            string updateBy = AccountInfo.GetUserName(Request);
            string username = model.Username;
            int withDrawMoney = model.AmountOfMoney;
            int transactionType = 3;
            string transactionContent = "Rút tiền";

            UserinfoModel userinfo = new UserinfoModel();
            DataTable userInfoDataTable = new DataTable();
            UserInfoDetailTableAdapter userInfoDetailAdapter = new UserInfoDetailTableAdapter();
            UserInfoTableAdapter userInfoAdapter = new UserInfoTableAdapter();
            userInfoDataTable = userInfoAdapter.GetDataByUsername(username);
            //string userTypeName = null;
            //string email = null;
            //if (!string.IsNullOrEmpty(userInfoDataTable.Rows[0]["TypeShortName"].ToString()))
            //{
            //	userInfoDataTable = userInfoDetailAdapter.GetDataByUsername(username);
            //	userTypeName = (string)userInfoDataTable.Rows[0]["TypeName"];
            //	email = userInfoDataTable.Rows[0]["Email"].ToString();
            //}
            //else
            //{
            //	AccountTableAdapter accountAdapter = new AccountTableAdapter();
            //	DataTable accountDataTable = new DataTable();
            //	accountDataTable = accountAdapter.GetDataByUsername(username);
            //	email = accountDataTable.Rows[0]["Email"].ToString();
            //}
            DateTime date = DateTime.Parse(userInfoDataTable.Rows[0]["LastUpdatedMoney"].ToString());
            int amountOfMoney = (int)userInfoDataTable.Rows[0]["AmountOfMoney"];

            TransactionHistoryTableAdapter transactionAdapter = new TransactionHistoryTableAdapter();
            int? money = transactionAdapter.GetCurrentMoney(username, date);
            if (money == null)
            {
                money = 0;
            }

            amountOfMoney += money.Value;

            if (withDrawMoney > amountOfMoney)
            {
                Session["withDrawMoney"] = "Giao dịch thất bại! Số tiền trong tài khoản không đủ để thực hiện giao dịch";
                return View(model);
            }
            else
            {
                try
                {
                    string transactionID = transactionAdapter.RechargeMoneyScalar(username, transactionType, amountOfMoney, transactionContent, null, false, date, updateBy, date).ToString();
                    int id = int.Parse(transactionID);
                    XmlSync.SaveTransactionHistoryXml(id, username, transactionType, amountOfMoney, transactionContent, null, false, date, updateBy, date, null);
                    Session["withDrawMoney"] = "Giao dịch thành công!";
                }
                catch (Exception ex)
                {
                    Log.ErrorLog(ex.Message);
                    Session["withDrawMoney"] = "Giao dịch thất bại!";
                }

                return RedirectToAction("WithdrawMoney","Transaction");
            }
        }
Example #3
0
        private static void sync(string xmlFilePath, string ignoreSyncID)
        {
            XDocument xDoc;
            XElement newDataSetEl;
            DateTime lastSync;

            xDoc = XDocument.Load(xmlFilePath);
            newDataSetEl = xDoc.Element("NewDataSet");
            lastSync = GetLastUpdatedClient(ignoreSyncID);

            UserInfoTableAdapter userInfoTA = new UserInfoTableAdapter();
            TransactionHistoryTableAdapter transactionHistoryTA = new TransactionHistoryTableAdapter();

            userInfoTA.Connection.Open();
            transactionHistoryTA.Connection = userInfoTA.Connection;

            using (SqlTransaction transaction = userInfoTA.Connection.BeginTransaction())
            {
                userInfoTA.AttachTransaction(transaction);
                transactionHistoryTA.AttachTransaction(transaction);

                try
                {
                    IList<XElement> ElList = newDataSetEl.Descendants("UserInfo").ToList();

                    foreach (XElement userInfoEl in ElList)
                    {
                        // not null value parse
                        string username = userInfoEl.Element("Username").Value;

                        // nullable value parse
                        byte[] fingerPrintIMG;
                        if (userInfoEl.Element("FingerPrintIMG") == null)
                        {
                            fingerPrintIMG = null;
                        }
                        else
                        {
                            fingerPrintIMG = Convert.FromBase64String(userInfoEl.Element("FingerPrintIMG").Value);
                        }

                        DateTime? lastUpdatedFingerPrint;
                        if (userInfoEl.Element("LastUpdatedFingerPrint") == null)
                        {
                            lastUpdatedFingerPrint = null;
                        }
                        else
                        {
                            lastUpdatedFingerPrint = DateTime.Parse(userInfoEl.Element("LastUpdatedFingerPrint").Value);
                        }

                        int? fingerPosition;
                        if (userInfoEl.Element("FingerPosition") == null)
                        {
                            fingerPosition = null;
                        }
                        else
                        {
                            fingerPosition = int.Parse(userInfoEl.Element("FingerPosition").Value);
                        }

                        DataTable userInfoDT = new UserInfoTableAdapter().GetDataByUsername(username);
                        if (userInfoDT.Rows.Count != 1)
                        {
                            throw new Exception("Comflic while Sync. The updated row doesn't exist.");
                        }

                        DataRow userInfoRow = userInfoDT.Rows[0];
                        DateTime? oriLastUpdateFingerPrint = userInfoRow.Field<DateTime?>("LastUpdatedFingerPrint");
                        if (oriLastUpdateFingerPrint == null || (lastUpdatedFingerPrint != null
                            && lastUpdatedFingerPrint > oriLastUpdateFingerPrint))
                        {
                            //userInfoTA.Update(userInfoRow.Field<string>("Name"), userInfoRow.Field<string>("TypeShortName")
                            //	, userInfoRow.Field<int>("AmountOfMoney"), userInfoRow.Field<DateTime>("LastUpdatedMoney"), fingerPrintIMG
                            //	, lastUpdatedFingerPrint, fingerPosition, userInfoRow.Field<bool>("IsCafeteriaStaff")
                            //	, userInfoRow.Field<bool>("IsActive"), userInfoRow.Field<DateTime>("InsertedDate"), userInfoRow.Field<string>("UpdatedBy")
                            //	, userInfoRow.Field<DateTime>("LastUpdated"), username);

                            userInfoTA.Update(userInfoRow.Field<string>("Name"), userInfoRow.Field<string>("TypeShortName")
                                , userInfoRow.Field<int>("AmountOfMoney"), userInfoRow.Field<DateTime>("LastUpdatedMoney"), fingerPrintIMG
                                , lastUpdatedFingerPrint, fingerPosition, userInfoRow.Field<bool>("IsCafeteriaStaff")
                                , true, userInfoRow.Field<DateTime>("InsertedDate"), userInfoRow.Field<string>("UpdatedBy")
                                , userInfoRow.Field<DateTime>("LastUpdated"), username);

                            //SaveUserInfoXml(userInfoRow.Field<string>("Username"), userInfoRow.Field<string>("Name"), userInfoRow.Field<string>("TypeShortName")
                            //	, userInfoRow.Field<int>("AmountOfMoney"), userInfoRow.Field<DateTime>("LastUpdatedMoney"), fingerPrintIMG
                            //	, lastUpdatedFingerPrint, fingerPosition, userInfoRow.Field<bool>("IsCafeteriaStaff")
                            //	, userInfoRow.Field<bool>("IsActive"), userInfoRow.Field<DateTime>("InsertedDate"), userInfoRow.Field<string>("UpdatedBy")
                            //	, userInfoRow.Field<DateTime>("LastUpdated"), ignoreSyncID);

                            SaveUserInfoXml(userInfoRow.Field<string>("Username"), userInfoRow.Field<string>("Name"), userInfoRow.Field<string>("TypeShortName")
                                , userInfoRow.Field<int>("AmountOfMoney"), userInfoRow.Field<DateTime>("LastUpdatedMoney"), fingerPrintIMG
                                , lastUpdatedFingerPrint, fingerPosition, userInfoRow.Field<bool>("IsCafeteriaStaff")
                                , true, userInfoRow.Field<DateTime>("InsertedDate"), userInfoRow.Field<string>("UpdatedBy")
                                , userInfoRow.Field<DateTime>("LastUpdated"), ignoreSyncID);
                        }
                    }

                    ElList = newDataSetEl.Descendants("TransactionHistory").ToList();

                    foreach (XElement transactionHistoryEl in ElList)
                    {
                        // not null value parse
                        int transactionHistoryID = int.Parse(transactionHistoryEl.Element("TransactionHistoryID").Value);
                        string username = transactionHistoryEl.Element("Username").Value;
                        int transactionTypeID = int.Parse(transactionHistoryEl.Element("TransactionTypeID").Value);
                        int value = int.Parse(transactionHistoryEl.Element("Value").Value);
                        string transactionContent = transactionHistoryEl.Element("TransactionContent").Value;
                        bool isAuto = bool.Parse(transactionHistoryEl.Element("IsAuto").Value);
                        DateTime insertedDate = DateTime.Parse(transactionHistoryEl.Element("InsertedDate").Value);
                        DateTime lastUpdated = DateTime.Parse(transactionHistoryEl.Element("LastUpdated").Value);

                        // nullable value parse
                        int? scheduleMealSetDetailID;
                        if (transactionHistoryEl.Element("ScheduleMealSetDetailID") == null)
                        {
                            scheduleMealSetDetailID = null;
                        }
                        else
                        {
                            scheduleMealSetDetailID = int.Parse(transactionHistoryEl.Element("ScheduleMealSetDetailID").Value);
                        }

                        string updatedBy = transactionHistoryEl.TryGetElementValue("UpdatedBy");

                        if (insertedDate > lastSync)
                        {
                            if (scheduleMealSetDetailID != null)
                            {
                                int? check = new ScheduleMealSetDetailTableAdapter().CheckID(scheduleMealSetDetailID.Value);

                                if (check == null)
                                {
                                    scheduleMealSetDetailID = null;
                                }
                            }

                            transactionHistoryTA.Insert(username, transactionTypeID, value, transactionContent, scheduleMealSetDetailID,
                                isAuto, insertedDate, updatedBy, lastUpdated);

                            SaveTransactionHistoryXml(transactionHistoryID, username, transactionTypeID, value, transactionContent
                                , scheduleMealSetDetailID, isAuto, insertedDate, updatedBy, lastUpdated, ignoreSyncID);
                        }
                    }

                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw ex;
                }
            }
        }
Example #4
0
        public bool getUpdatedFingerPrint(string username, byte[] image, int? fingerPosition
            , DateTime lastUpdatedFingerPrint,string ignoreSyncID)
        {
            if (!authHeader())
            {
                throw new Exception(StringResources.E00001);
            }

            UserInfoTableAdapter userInfoTA = new UserInfoTableAdapter();
            try
            {
                DataTable userInfoDT = userInfoTA.GetDataByUsername(username);
                if (userInfoDT.Rows.Count != 1)
                {
                    throw new Exception("Error while get user info by username = "******"FingerPrintIMG"] = image;
                row["FingerPosition"] = fingerPosition;
                row["LastUpdatedFingerPrint"] = lastUpdatedFingerPrint;
                row.AcceptChanges();

                userInfoTA.Update(row.Field<string>("Username"), row.Field<string>("Name"), row.Field<string>("TypeShortName")
                    , row.Field<int>("AmountOfMoney"), row.Field<DateTime>("LastUpdatedMoney"), image, lastUpdatedFingerPrint
                    , fingerPosition, row.Field<bool>("IsCafeteriaStaff"), true, row.Field<DateTime>("InsertedDate")
                    , row.Field<string>("UpdatedBy"), row.Field<DateTime>("LastUpdated"), username);
                XmlSync.SaveUserInfoXml(row.Field<string>("Username"), row.Field<string>("Name"), row.Field<string>("TypeShortName")
                    , row.Field<int>("AmountOfMoney"), row.Field<DateTime>("LastUpdatedMoney"), image, lastUpdatedFingerPrint
                    , fingerPosition, row.Field<bool>("IsCafeteriaStaff"), true, row.Field<DateTime>("InsertedDate")
                    , row.Field<string>("UpdatedBy"), row.Field<DateTime>("LastUpdated"), ignoreSyncID);
                return true;
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
                return false;
            }
        }
Example #5
0
        public ActionResult UserInfo()
        {
            string username = AccountInfo.GetUserName(Request);

            UserinfoModel userinfo = new UserinfoModel();
            DataTable userInfoDataTable = new DataTable();
            UserInfoDetailTableAdapter userInfoDetailAdapter = new UserInfoDetailTableAdapter();
            UserInfoTableAdapter userInfoAdapter = new UserInfoTableAdapter();
            userInfoDataTable = userInfoAdapter.GetDataByUsername(username);
            string userTypeName = null;
            string email = null;
            if (!string.IsNullOrEmpty(userInfoDataTable.Rows[0]["TypeShortName"].ToString()))
            {
                userInfoDataTable = userInfoDetailAdapter.GetDataByUsername(username);
                userTypeName = (string)userInfoDataTable.Rows[0]["TypeName"];
                email = userInfoDataTable.Rows[0]["Email"].ToString();
            }
            else
            {
                AccountTableAdapter accountAdapter = new AccountTableAdapter();
                DataTable accountDataTable = new DataTable();
                accountDataTable = accountAdapter.GetDataByUsername(username);
                email = accountDataTable.Rows[0]["Email"].ToString();
            }
            DateTime date = DateTime.Parse(userInfoDataTable.Rows[0]["LastUpdatedMoney"].ToString());
            int amountOfMoney = (int)userInfoDataTable.Rows[0]["AmountOfMoney"];

            TransactionHistoryTableAdapter transactionAdapter = new TransactionHistoryTableAdapter();
            int? money = transactionAdapter.GetCurrentMoney(username, date);
            if (money == null)
            {
                money = 0;
            }

            amountOfMoney += money.Value;

            userinfo.Username = username;
            userinfo.Name = userInfoDataTable.Rows[0]["Name"].ToString();
            userinfo.TypeName = userTypeName;
            userinfo.Email = email;
            userinfo.AmountOfMoney = amountOfMoney;

            return View(userinfo);
        }
Example #6
0
        public ActionResult Register(RegisterModel model)
        {
            if (!ModelState.IsValid)
            {
                return View();
            }

            string username = model.Username;
            string password = model.Password;
            string name = model.Name;
            string email = model.Email;
            DateTime date = DateTime.Now;
            string userType = "DF";

            string errormsg = null;

            UserInfoTableAdapter UserInfoAdapter = new UserInfoTableAdapter();
            DataTable UserInfoDT = UserInfoAdapter.GetDataByUsername(username);

            if (UserInfoDT.Rows.Count == 1)
            {
                errormsg += "Tên đăng nhập ";
            }

            if (!string.IsNullOrEmpty(email))
            {
                AccountTableAdapter AccountAdapter = new AccountTableAdapter();
                DataTable AccountDT = AccountAdapter.GetDataByEmail(email);

                if (AccountDT.Rows.Count == 1)
                {
                    if (errormsg != null)
                    {
                        errormsg += ", Email ";
                    }
                    else errormsg += "Email ";
                }
            }

            if (errormsg != null)
            {
                errormsg += "đã tồn tại!";
                ModelState.AddModelError("", errormsg);
                return View(model);
            }
            else
            {
                AccountTableAdapter AccountAdapter = new AccountTableAdapter();

                UserInfoAdapter.Connection.Open();
                AccountAdapter.Connection = UserInfoAdapter.Connection;

                using (SqlTransaction transaction = UserInfoAdapter.Connection.BeginTransaction())
                {
                    UserInfoAdapter.AttachTransaction(transaction);
                    AccountAdapter.AttachTransaction(transaction);

                    try
                    {
                        UserInfoAdapter.InsertUserInfo(username, name, userType, 0, date, null, null, null, false, false, date, username, date);
                        Log.ActivityLog("Insert into UserInfo: Username = "******"Insert into Account: Username = "******"register"] = "Đăng ký thành công!";
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        Log.ErrorLog(ex.Message);
                        Session["register"] = "Đăng ký thất bại!";
                    }
                }
            }

            return RedirectToAction("HomePage", "Home");
        }
Example #7
0
        public JsonResult GetUsernameList()
        {
            string query = "SELECT Username FROM UserInfo";

            UserInfoTableAdapter userInfoTA = new UserInfoTableAdapter();
            userInfoTA.Connection.Open();

            SqlCommand getDataCmd = new SqlCommand(query, userInfoTA.Connection);
            SqlDataAdapter adapter = new SqlDataAdapter(getDataCmd);

            DataTable dt = new DataTable();

            try
            {
                adapter.Fill(dt);
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
                return Json("error", JsonRequestBehavior.AllowGet);
            }

            List<string> usernameList = new List<string>();
            foreach (DataRow row in dt.Rows)
            {
                usernameList.Add(row.Field<string>("Username"));
            }

            return Json(new { result = usernameList }, JsonRequestBehavior.AllowGet);
        }
Example #8
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 });
        }