Ejemplo n.º 1
0
        public JsonResult SetIsDayOn(bool isDayOn, int scheduleID)
        {
            ScheduleMealSetDetailTableAdapter scheduleMealSetDetailTA = new ScheduleMealSetDetailTableAdapter();
            ScheduleTableAdapter scheduleTA = new ScheduleTableAdapter();

            scheduleMealSetDetailTA.Connection.Open();
            scheduleTA.Connection = scheduleMealSetDetailTA.Connection;

            using (SqlTransaction transaction = scheduleMealSetDetailTA.Connection.BeginTransaction())
            {
                scheduleMealSetDetailTA.AttachTransaction(transaction);
                scheduleTA.AttachTransaction(transaction);

                try
                {
                    if (!isDayOn)
                    {
                        DataTable scheduleMealSetDetailDT = scheduleMealSetDetailTA.GetDataByScheduleID(scheduleID);

                        foreach (DataRow row in scheduleMealSetDetailDT.Rows)
                        {
                            int scheduleMealSetDetailID = row.Field<int>("ScheduleMealSetDetailID");
                            scheduleMealSetDetailTA.Delete(scheduleMealSetDetailID);
                        }
                    }

                    DataTable scheduleDT = scheduleTA.GetDataByID(scheduleID);

                    if (scheduleDT.Rows.Count != 1)
                    {
                        throw new Exception("Can't find schedule with [scheduleID] = " + scheduleID);
                    }

                    DataRow scheduleRow = scheduleDT.Rows[0];
                    string username = AccountInfo.GetUserName(Request);
                    DateTime now = DateTime.Now;

                    scheduleTA.Update(scheduleRow.Field<DateTime>("Date"), scheduleRow.Field<int>("ServingTimeID"), isDayOn
                        , scheduleRow.Field<DateTime>("InsertedDate"), username, now, scheduleID);

                    XmlSync.SaveScheduleXml(scheduleID, scheduleRow.Field<DateTime>("Date"), scheduleRow.Field<int>("ServingTimeID"), isDayOn
                        , scheduleRow.Field<DateTime>("InsertedDate"), username, now, null);

                    transaction.Commit();
                    return Json(new { result = "done" }, JsonRequestBehavior.AllowGet);
                }
                catch (Exception ex)
                {
                    Log.ErrorLog(ex.Message);
                    transaction.Rollback();
                    return Json("error", JsonRequestBehavior.AllowGet);
                }
            }
        }
Ejemplo n.º 2
0
        public JsonResult RemoveScheduleMealSet(int scheduleMealSetDetailID)
        {
            try
            {
                ScheduleMealSetDetailTableAdapter scheduleMealSetDetailTA = new ScheduleMealSetDetailTableAdapter();

                int rowCount = scheduleMealSetDetailTA.Delete(scheduleMealSetDetailID);

                if (rowCount == 0)
                {
                    Log.ErrorLog("Can't find ScheduleMealSetDetail with [ScheduleMealSetDetailID] = " + scheduleMealSetDetailID);
                    return Json("error", JsonRequestBehavior.AllowGet);
                }

                XmlSync.DeleteScheduleMealSetDetailXml(scheduleMealSetDetailID);

                return Json(new { result = "done" }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
                return Json("error", JsonRequestBehavior.AllowGet);
            }
        }