Esempio n. 1
0
        public ReturnValueInfo InsertRecord(MaintainPlan_mtp_Info reasonInfo)
        {
            ReturnValueInfo returnValue = new ReturnValueInfo();

            if (reasonInfo != null)
            {
                try
                {
                    using (MainDBDataContext db = new MainDBDataContext())
                    {
                        LinqToSQLModel.MaintainPlan_mtp newTab = Common.General.CopyObjectValue<Model.HBPMS.Master.MaintainPlan_mtp_Info, LinqToSQLModel.MaintainPlan_mtp>(reasonInfo);
                        newTab.mtp_dAddDate = DateTime.Now;
                        db.MaintainPlan_mtp.InsertOnSubmit(newTab);
                        db.SubmitChanges();

                        returnValue.boolValue = true;
                        returnValue.isError = false;
                        returnValue.ValueObject = newTab;
                        returnValue.messageText = "保存成功";
                    }
                }
                catch (Exception Ex)
                {
                    throw Ex;
                }
            }
            else
            {
                returnValue.boolValue = false;
                returnValue.isError = true;
                returnValue.messageText = "保存的對象為空";
            }

            return returnValue;
        }
Esempio n. 2
0
        /// <summary>
        /// 檢查當前日期是否需要該保養
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        private static bool CheckTodayPlan(MaintainPlan_mtp_Info info)
        {
            string yesterday = System.DateTime.Now.ToShortDateString();
            string tomorrow = System.DateTime.Now.AddDays(1).ToShortDateString();

            DateTime yesterdayDT = Convert.ToDateTime(yesterday);//當日零時
            DateTime tomorrowDT = Convert.ToDateTime(tomorrow);

            if (info != null)
            {
                string weekDay = "";//當前星期
                switch (yesterdayDT.DayOfWeek)
                {
                    case DayOfWeek.Monday:
                        weekDay = "1";
                        break;
                    case DayOfWeek.Tuesday:
                        weekDay = "2";
                        break;
                    case DayOfWeek.Wednesday:
                        weekDay = "3";
                        break;
                    case DayOfWeek.Thursday:
                        weekDay = "4";
                        break;
                    case DayOfWeek.Friday:
                        weekDay = "5";
                        break;
                    case DayOfWeek.Saturday:
                        weekDay = "6";
                        break;
                    case DayOfWeek.Sunday:
                        weekDay = "7";
                        break;
                }

                int day = yesterdayDT.Day;//當前日

                switch (info.mtp_iPeriodType)
                {
                    case 0://一次
                        if (info.mtp_dBeginDate < tomorrowDT && info.mtp_dBeginDate > yesterdayDT)
                        {
                            return true;
                        }
                        else
                        {
                            return false;
                        }
                    case 1://每天
                        if (info.mtp_dExpireTime <= tomorrowDT)
                        {
                            return false;
                        }
                        else
                        {
                            DateTime begionDate = Convert.ToDateTime(((DateTime)info.mtp_dBeginDate).ToString("yyyy/MM/dd"));

                            System.TimeSpan ts = yesterdayDT.Subtract(begionDate);//TimeSpan得到dt1和dt2的时间间隔
                            int countday = ts.Days;//

                            int separated = Int32.Parse(info.mtp_cDateIndex);

                            if (countday % separated == 0)
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                    case 2://每周
                        if (info.mtp_dExpireTime <= tomorrowDT)
                        {
                            return false;
                        }
                        else
                        {
                            string[] weeks = info.mtp_cDateIndex.Split(',');

                            for (int index = 0; index < weeks.Length; index++)
                            {
                                if (weeks[index] == weekDay)
                                {
                                    return true;
                                }
                            }
                            return false;
                        }
                    case 3:
                        if (info.mtp_dExpireTime <= tomorrowDT)
                        {
                            return false;
                        }
                        else
                        {

                            if (day.ToString() == info.mtp_cDateIndex)
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                    case 4:

                        string[] dayNos = info.mtp_cDateIndex.Split(',');

                        if (dayNos[1] == weekDay)
                        {
                            int no = 0;

                            for (int index = day; index >= 0; index = index - 7)//確定當日是當月的第幾個星期
                            {
                                no++;
                            }

                            if (no.ToString() == dayNos[0])
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    default:
                        break;
                }
            }

            return false;
        }
        private MaintainPlan_mtp_Info getBaseObj()
        {
            MaintainPlan_mtp_Info info = new MaintainPlan_mtp_Info();

            info.mtp_iPeriodType = this.LoopChecked;

            info.mtp_dBeginDate = this.dtpDayStart.Value;
            info.mtp_lIsAtive = this.chbIsAtive.Checked;

            if (this.rbtIsEndTime.Checked)
            {
                if (this.dtpDayEnd.Value < this.dtpDayStart.Value)
                {
                    MessageBox.Show(this, "結束時間小于開始時間,請檢查!");
                    return null;
                }

                info.mtp_dExpireTime = this.dtpDayEnd.Value;
            }

            switch (this.LoopChecked)
            {
                case 0:

                    break;
                case 1:
                    info.mtp_cDateIndex = this.nudDay.Value.ToString();
                    break;
                case 2:
                    List<CheckBox> checkBoxList = GetWeekList();
                    string weeks = "";

                    for (int weekNo = 0; weekNo < checkBoxList.Count; weekNo++)
                    {
                        if (checkBoxList[weekNo].Checked)
                        {
                            if (weeks != "")
                            {
                                weeks += ",";
                            }
                            weeks += (weekNo + 1).ToString();
                        }
                    }

                    if (weeks.Trim() == "")
                    {
                        MessageBox.Show(this, "請選擇一個星期!");
                        return null;
                    }

                    info.mtp_cDateIndex = weeks;

                    break;
                case 3:
                    if (rbtMonthDay.Checked)
                    {
                        info.mtp_cDateIndex = this.nudMonthDay.Value.ToString();
                    }
                    else if (rbtMonthWeek.Checked)
                    {
                        info.mtp_iPeriodType = 4;
                        weeks = (this.cmbWeekNo.SelectedIndex + 1) + "," + (this.cmbWeekDay.SelectedIndex + 1);
                        info.mtp_cDateIndex = weeks;
                    }
                    break;
            }

            info.mtp_cAdd = "System";
            info.mtp_dAddDate = System.DateTime.Now;
            //notInfo.not_cLast = this.UserInformation.usm_cUserLoginID;
            info.mtp_cLast = "System";
            info.mtp_dLastDate = System.DateTime.Now;
            info.mtp_dWorkTime = this.dtpWorkTime.Value;

            return info;
        }
Esempio n. 4
0
        public ReturnValueInfo UpdateRecord(MaintainPlan_mtp_Info reasonInfo)
        {
            ReturnValueInfo returnValue = new ReturnValueInfo();
            if (reasonInfo != null)
            {
                try
                {
                    using (MainDBDataContext db = new MainDBDataContext())
                    {
                        MaintainPlan_mtp query = db.MaintainPlan_mtp.SingleOrDefault(t => t.mtp_iRecordID == reasonInfo.mtp_iRecordID);

                        if (query != null)
                        {
                            query.mtp_iPeriodType = reasonInfo.mtp_iPeriodType;
                            query.mtp_dWorkTime = reasonInfo.mtp_dWorkTime;
                            query.mtp_dLastDate = reasonInfo.mtp_dLastDate;
                            query.mtp_dBeginDate = reasonInfo.mtp_dBeginDate;
                            query.mtp_dExpireTime = reasonInfo.mtp_dExpireTime;
                            query.mtp_cLast = reasonInfo.mtp_cLast;
                            query.mtp_cDateIndex = reasonInfo.mtp_cDateIndex;
                            query.mtp_lIsAtive = reasonInfo.mtp_lIsAtive;

                            db.SubmitChanges();
                        }

                        returnValue.boolValue = true;
                        returnValue.isError = false;
                        returnValue.ValueObject = query;
                        returnValue.messageText = "保存成功";
                    }
                }
                catch (Exception Ex)
                {
                    throw Ex;
                }
            }
            return returnValue;
        }
Esempio n. 5
0
        public List<MaintainPlan_mtp_Info> SearchRecord(MaintainPlan_mtp_Info searchInfo)
        {
            List<MaintainPlan_mtp_Info> listReturn = new List<MaintainPlan_mtp_Info>();
            try
            {

                using (MainDBDataContext db = new MainDBDataContext())
                {
                    var result = from m in db.MaintainPlan_mtp
                                 join o in db.MaintainOperationMaster_mom on m.mtp_iMOMID equals o.mom_iRecordID
                                 orderby m.mtp_iRecordID
                                 select new MaintainPlan_mtp_Info
                                 {
                                     mom_cOperationName = o.mom_cOperationName,
                                     mtp_cAdd = m.mtp_cAdd,
                                     mtp_cDateIndex = m.mtp_cDateIndex,
                                     mtp_cLast = m.mtp_cLast,
                                     mtp_cMachineModel = m.mtp_cMachineModel,
                                     mtp_dAddDate = m.mtp_dAddDate,
                                     mtp_dBeginDate = m.mtp_dBeginDate,
                                     mtp_dExpireTime = m.mtp_dExpireTime,
                                     mtp_dLastDate = m.mtp_dLastDate,
                                     mtp_dWorkTime = m.mtp_dWorkTime,
                                     mtp_iMOMID = m.mtp_iMOMID,
                                     mtp_iPeriodType = m.mtp_iPeriodType,
                                     mtp_iRecordID = m.mtp_iRecordID,
                                     mtp_lIsAtive = m.mtp_lIsAtive

                                 };
                    if (searchInfo.SearchDate.HasValue)
                    {
                        result = result.Where(d =>
                            (d.mtp_dBeginDate <= searchInfo.SearchDate && d.mtp_dExpireTime == null)
                            ||
                            (d.mtp_dBeginDate <= searchInfo.SearchDate && d.mtp_dExpireTime != null && d.mtp_dExpireTime >= searchInfo.SearchDate)
                            );
                    }
                    if (string.IsNullOrEmpty(searchInfo.mtp_cMachineModel))
                    {
                        result = result.Where(d => d.mtp_cMachineModel == searchInfo.mtp_cMachineModel);
                    }
                    result = result.Where(d => d.mtp_lIsAtive == true);
                    //foreach (var item in result)
                    //{
                    //    MaintainPlan_mtp_Info newTab = Common.General.CopyObjectValue<MaintainPlan_mtp, MaintainPlan_mtp_Info>(item);
                    //    listReturn.Add(newTab);
                    //}.

                    listReturn = result.ToList();

                }

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return listReturn;
        }
Esempio n. 6
0
 public ReturnValueInfo UpdateRecord(MaintainPlan_mtp_Info reasonInfo)
 {
     try
     {
         return this._IMaintainPlanDA.UpdateRecord(reasonInfo);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 7
0
 public List<MaintainPlan_mtp_Info> SearchRecord(MaintainPlan_mtp_Info searchInfo)
 {
     try
     {
         return this._IMaintainPlanDA.SearchRecord(searchInfo);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 8
0
        /// <summary>
        /// 保養計劃主檔
        /// </summary>
        public List<MaintainPlan_mtp_Info> GetMaintainPlanMaster(string machineType)
        {
            List<MaintainPlan_mtp_Info> list = new List<MaintainPlan_mtp_Info>();
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine("select ");
            strSql.AppendLine("mtp_iRecordID,mtp_cMachineModel,mtp_iMOMID,mtp_dWorkTime,mtp_dBeginDate,mtp_dExpireTime,mtp_lIsAtive,mtp_iPeriodType,mtp_cDateIndex,mtp_cAdd,mtp_dAddDate,mtp_cLast,mtp_dLastDate ");
            strSql.AppendLine("from MaintainPlan_mtp ");
            strSql.AppendLine("where mtp_cMachineModel='" + machineType.Trim()+"'");
            strSql.AppendLine("and mtp_lIsAtive=1 ");

            try
            {
                using (SqlDataReader sdr = DbHelperSQL.ExecuteReader(strSql.ToString()))
                {
                    while (sdr.Read())
                    {
                        MaintainPlan_mtp_Info model = new MaintainPlan_mtp_Info();
                        if (sdr["mtp_iRecordID"] != null && sdr["mtp_iRecordID"].ToString() != "")
                        {
                            model.mtp_iRecordID = int.Parse(sdr["mtp_iRecordID"].ToString());
                        }
                        if (sdr["mtp_cMachineModel"] != null && sdr["mtp_cMachineModel"].ToString() != "")
                        {
                            model.mtp_cMachineModel = sdr["mtp_cMachineModel"].ToString();
                        }
                        if (sdr["mtp_iMOMID"] != null && sdr["mtp_iMOMID"].ToString() != "")
                        {
                            model.mtp_iMOMID = int.Parse(sdr["mtp_iMOMID"].ToString());
                        }
                        if (sdr["mtp_dWorkTime"] != null && sdr["mtp_dWorkTime"].ToString() != "")
                        {
                            model.mtp_dWorkTime = DateTime.Parse(sdr["mtp_dWorkTime"].ToString());
                        }
                        if (sdr["mtp_dBeginDate"] != null && sdr["mtp_dBeginDate"].ToString() != "")
                        {
                            model.mtp_dBeginDate = DateTime.Parse(sdr["mtp_dBeginDate"].ToString());
                        }
                        if (sdr["mtp_dExpireTime"] != null && sdr["mtp_dExpireTime"].ToString() != "")
                        {
                            model.mtp_dExpireTime = DateTime.Parse(sdr["mtp_dExpireTime"].ToString());
                        }
                        if (sdr["mtp_lIsAtive"] != null && sdr["mtp_lIsAtive"].ToString() != "")
                        {
                            if ((sdr["mtp_lIsAtive"].ToString() == "1") || (sdr["mtp_lIsAtive"].ToString().ToLower() == "true"))
                            {
                                model.mtp_lIsAtive = true;
                            }
                            else
                            {
                                model.mtp_lIsAtive = false;
                            }
                        }
                        if (sdr["mtp_iPeriodType"] != null && sdr["mtp_iPeriodType"].ToString() != "")
                        {
                            model.mtp_iPeriodType = int.Parse(sdr["mtp_iPeriodType"].ToString());
                        }
                        if (sdr["mtp_cDateIndex"] != null && sdr["mtp_cDateIndex"].ToString() != "")
                        {
                            model.mtp_cDateIndex = sdr["mtp_cDateIndex"].ToString();
                        }
                        if (sdr["mtp_cAdd"] != null && sdr["mtp_cAdd"].ToString() != "")
                        {
                            model.mtp_cAdd = sdr["mtp_cAdd"].ToString();
                        }
                        if (sdr["mtp_dAddDate"] != null && sdr["mtp_dAddDate"].ToString() != "")
                        {
                            model.mtp_dAddDate = DateTime.Parse(sdr["mtp_dAddDate"].ToString());
                        }
                        if (sdr["mtp_cLast"] != null && sdr["mtp_cLast"].ToString() != "")
                        {
                            model.mtp_cLast = sdr["mtp_cLast"].ToString();
                        }
                        if (sdr["mtp_dLastDate"] != null && sdr["mtp_dLastDate"].ToString() != "")
                        {
                            model.mtp_dLastDate = DateTime.Parse(sdr["mtp_dLastDate"].ToString());
                        }
                        list.Add(model);
                    }
                }
                return list;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 9
0
 private string GetMaintainPlanMasterSQL(MaintainPlan_mtp_Info model)
 {
     StringBuilder strSql = new StringBuilder();
     StringBuilder strSql1 = new StringBuilder();
     StringBuilder strSql2 = new StringBuilder();
     if (model.mtp_iRecordID != null)
     {
         strSql1.Append("mtp_iRecordID,");
         strSql2.Append("" + model.mtp_iRecordID + ",");
     }
     if (model.mtp_cMachineModel != null)
     {
         strSql1.Append("mtp_cMachineModel,");
         strSql2.Append("'" + model.mtp_cMachineModel + "',");
     }
     if (model.mtp_iMOMID != null)
     {
         strSql1.Append("mtp_iMOMID,");
         strSql2.Append("" + model.mtp_iMOMID + ",");
     }
     if (model.mtp_dWorkTime != null)
     {
         strSql1.Append("mtp_dWorkTime,");
         strSql2.Append("'" + model.mtp_dWorkTime.Value.ToString(this._sqlLiteDatetimeFormat) + "',");
     }
     if (model.mtp_dBeginDate != null)
     {
         strSql1.Append("mtp_dBeginDate,");
         strSql2.Append("'" + model.mtp_dBeginDate.Value.ToString(this._sqlLiteDatetimeFormat) + "',");
     }
     if (model.mtp_dExpireTime != null)
     {
         strSql1.Append("mtp_dExpireTime,");
         strSql2.Append("'" + model.mtp_dExpireTime.Value.ToString(this._sqlLiteDatetimeFormat) + "',");
     }
     if (model.mtp_lIsAtive.HasValue)
     {
         strSql1.Append("mtp_lIsAtive,");
         strSql2.Append("" + (model.mtp_lIsAtive.Value ? 1 : 0) + ",");
     }
     if (model.mtp_iPeriodType != null)
     {
         strSql1.Append("mtp_iPeriodType,");
         strSql2.Append("" + model.mtp_iPeriodType + ",");
     }
     if (model.mtp_cDateIndex != null)
     {
         strSql1.Append("mtp_cDateIndex,");
         strSql2.Append("'" + model.mtp_cDateIndex + "',");
     }
     if (model.mtp_cAdd != null)
     {
         strSql1.Append("mtp_cAdd,");
         strSql2.Append("'" + model.mtp_cAdd + "',");
     }
     if (model.mtp_dAddDate != null)
     {
         strSql1.Append("mtp_dAddDate,");
         strSql2.Append("'" + model.mtp_dAddDate.Value.ToString(this._sqlLiteDatetimeFormat) + "',");
     }
     if (model.mtp_cLast != null)
     {
         strSql1.Append("mtp_cLast,");
         strSql2.Append("'" + model.mtp_cLast + "',");
     }
     if (model.mtp_dLastDate != null)
     {
         strSql1.Append("mtp_dLastDate,");
         strSql2.Append("'" + model.mtp_dLastDate.Value.ToString(this._sqlLiteDatetimeFormat) + "',");
     }
     strSql.Append("insert into MaintainPlan_mtp(");
     strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
     strSql.Append(")");
     strSql.Append(" values (");
     strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
     strSql.Append(")");
     return strSql.ToString();
 }