コード例 #1
0
ファイル: DataAccess.cs プロジェクト: Grania/ctm-project
        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 JsonResult AddScheduleMealSet(int mealSetID, int scheduleID, bool isDayOn)
        {
            //if isDayOn = true, just insert into ScheduleMealSetDetail
            // else open transaction and set isDayOn of schedule = true
            if (isDayOn)
            {
                try
                {
                    ScheduleMealSetDetailTableAdapter scheduleMealSetDetailTA = new ScheduleMealSetDetailTableAdapter();

                    DataTable dt = scheduleMealSetDetailTA.GetDataByMealSetIDScheduleID(mealSetID, scheduleID);
                    if (dt.Rows.Count != 0)
                    {
                        return Json("duplicate", JsonRequestBehavior.AllowGet);
                    }

                    DateTime now = DateTime.Now;
                    string newScheduleMealSetDetailIDStr = scheduleMealSetDetailTA.InsertScalar(mealSetID, scheduleID, now, now).ToString();
                    int newScheduleMealSetDetailID = int.Parse(newScheduleMealSetDetailIDStr);

                    XmlSync.SaveScheduleMealSetDetailXml(newScheduleMealSetDetailID, mealSetID, scheduleID, now, now, null);

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

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

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

                        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"), true
                            , scheduleRow.Field<DateTime>("InsertedDate"), username, now, scheduleID);

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

                        string newScheduleMealSetDetailIDStr = scheduleMealSetDetailTA.InsertScalar(mealSetID, scheduleID, now, now).ToString();
                        int newScheduleMealSetDetailID = int.Parse(newScheduleMealSetDetailIDStr);

                        XmlSync.SaveScheduleMealSetDetailXml(newScheduleMealSetDetailID, mealSetID, scheduleID, now, now, null);

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        Log.ErrorLog(ex.Message);
                        return Json("error", JsonRequestBehavior.AllowGet);
                    }
                }

                return Json(new { result = "done" }, JsonRequestBehavior.AllowGet);
            }
        }
コード例 #3
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);
                }
            }
        }
コード例 #4
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);
            }
        }
コード例 #5
0
ファイル: XmlSync.cs プロジェクト: Grania/ctm-project
        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;
                }
            }
        }