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 EditTransaction(string TransID)
        {
            TransactionHistoryTableAdapter adapter = new TransactionHistoryTableAdapter();
            EditTransaction model = new EditTransaction();

            TransactionTypeTableAdapter tranTypeAdapter = new TransactionTypeTableAdapter();
            DataTable tranTypeDT = tranTypeAdapter.GetData();

            List<SelectListItem> items = new List<SelectListItem>();
            foreach (DataRow row in tranTypeDT.Rows)
            {
                items.Add(new SelectListItem { Text = row["Name"].ToString(), Value = row["TransactionTypeID"].ToString() });
            }
            ViewData["TransType"] = items;

            try
            {
                int transactionID = int.Parse(TransID);
                DataTable result = adapter.GetDataByKey(transactionID);

                if (result.Rows.Count != 0)
                {
                    model.Username = result.Rows[0].Field<string>("Username");
                    model.TransactionTypeID = result.Rows[0].Field<int>("TransactionTypeID");
                    model.Value = result.Rows[0].Field<int>("Value");
                    model.TransactionContent = result.Rows[0].Field<string>("TransactionContent");
                    model.ScheduleMealSetDetailID = result.Rows[0].Field<int?>("ScheduleMealSetDetailID");
                    model.IsAuto = result.Rows[0].Field<Boolean>("IsAuto");
                    model.InsertedDate = result.Rows[0].Field<DateTime>("InsertedDate");
                    model.UpdatedBy = result.Rows[0].Field<string>("UpdatedBy");
                    model.LastUpdated = result.Rows[0].Field<DateTime>("LastUpdated");
                    model.TransactionHistoryID = result.Rows[0].Field<int>("TransactionHistoryID");
                }
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
            }

            return View(model);
        }
Example #3
0
        public ActionResult Test()
        {
            DateTime monthBegin = DateTime.Parse("2015-12-1");
            DataTable dt = new CTMF_Website.DataAccessTableAdapters.TransactionHistoryTableAdapter().GetDataByDate(monthBegin, DateTime.Now);

            CTMF_Website.Util.ExcelReport.ExportToExcel(dt, "abc");
            return RedirectToAction("Index", "Report");
        }
        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");
            }
        }
        public ActionResult RechargeMoney(RechargeMoney model)
        {
            if (!ModelState.IsValid)
            {
                return View();
            }

            string updateBy = AccountInfo.GetUserName(Request);
            string username = model.Username;
            int amountOfMoney = 0;
            if (!string.IsNullOrEmpty(model.AmountOfMoney.ToString()))
            {
                amountOfMoney = model.AmountOfMoney;
            }
            string transactionContent = "Nạp tiền";
            DateTime date = DateTime.Now;
            int transactionType = 2;
            UserInfoDetailTableAdapter userInfoAdapter = new UserInfoDetailTableAdapter();
            DataTable userInfoDataTable = userInfoAdapter.GetDataByUsername(username);

            if (userInfoDataTable.Rows.Count != 1)
            {
                ModelState.AddModelError("", "Tên đăng nhập không tồn tại.");
                return View(model);
            }
            TransactionHistoryTableAdapter transactionAdapter = new TransactionHistoryTableAdapter();
            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["rechargeMoney"] = "Giao dịch thành công!";
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
                Session["rechargeMoney"] = "Giao dịch thất bại!";
            }

            return RedirectToAction("RechargeMoney", "Transaction");
        }
        public ActionResult EditTransaction(EditTransaction model)
        {
            TransactionTypeTableAdapter tranTypeAdapter = new TransactionTypeTableAdapter();
            DataTable tranTypeDT = tranTypeAdapter.GetData();

            List<SelectListItem> items = new List<SelectListItem>();
            foreach (DataRow row in tranTypeDT.Rows)
            {
                items.Add(new SelectListItem { Text = row["Name"].ToString(), Value = row["TransactionTypeID"].ToString() });
            }
            ViewData["TransType"] = items;

            if (!ModelState.IsValid)
            {
                return View(model);
            }
            int transactionHistoryID = model.TransactionHistoryID;
            string username = model.Username;
            int transactionTypeID = model.TransactionTypeID;
            int value = model.Value;
            string transactionContent = model.TransactionContent;
            int? scheduleMealSetDetailID = model.ScheduleMealSetDetailID;
            Boolean isAuto = model.IsAuto;
            DateTime insertedDate = model.InsertedDate;
            string updatedBy = model.UpdatedBy;
            DateTime lastUpdated = DateTime.Now;
            TransactionHistoryTableAdapter transAdapter = new TransactionHistoryTableAdapter();
            try
            {
                transAdapter.UpdateTransactionHistory(username, transactionTypeID, value, transactionContent
                    , scheduleMealSetDetailID, isAuto, insertedDate, AccountInfo.GetUserName(Request), lastUpdated
                    , transactionHistoryID);
                XmlSync.SaveTransactionHistoryXml(transactionHistoryID, username, transactionTypeID, value, transactionContent
                    , scheduleMealSetDetailID, isAuto, insertedDate, AccountInfo.GetUserName(Request), lastUpdated, null);
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
            }

            return RedirectToAction("ListTransaction", "Transaction");
        }
Example #7
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 #8
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 #9
0
        public ActionResult DetailUser(string username)
        {
            UserinfoModel userinfo = new UserinfoModel();
            UserInfoDetailTableAdapter userinfoAdapter = new UserInfoDetailTableAdapter();
            DataTable userinfoDataTable = userinfoAdapter.GetDataByUsername(username);
            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 = (string)userinfoDataTable.Rows[0]["TypeName"];
            userinfo.Email = userinfoDataTable.Rows[0]["Email"].ToString();
            userinfo.AmountOfMoney = amountOfMoney;
            userinfo.Role = (int)userinfoDataTable.Rows[0]["Role"];

            return View(userinfo);
        }