예제 #1
0
        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);
        }