Example #1
0
        /// <summary>
        /// Get all periods inside a schedule
        /// </summary>
        /// <param name="scheduleId">schedule id</param>
        /// <returns>Return list period if founded or error if null</returns>
        public List <DTO_Period> GetAllPeriodOfSchedule(string scheduleId)
        {
            List <DTO_Period> lstPeriods = new List <DTO_Period>();
            DataTable         dt         = dal.GetPeriodBySchedule(scheduleId);

            if (dt.Rows.Count < 0)
            {
                return(null);
            }

            try
            {
                foreach (DataRow row in dt.Rows)
                {
                    DTO_Period period = new DTO_Period();

                    period.Id        = row["Id"] == DBNull.Value ? null : row["Id"].ToString();
                    period.WeekDay   = row["DayInWeek"] == DBNull.Value ? WeekDay.MONDAY : (WeekDay)Convert.ToInt16(row["DayInWeek"]);
                    period.Schedule  = scheduleId;
                    period.StartTime = row["StartTime"] == DBNull.Value ? new DateTime(1970, 1, 1) : Convert.ToDateTime(row["StartTime"].ToString());
                    period.EndTime   = row["EndTime"] == DBNull.Value ? new DateTime(1970, 1, 1) : Convert.ToDateTime(row["EndTime"].ToString());

                    lstPeriods.Add(period);
                }

                return(lstPeriods);
            }
            catch
            {
                return(null);
            }
        }
Example #2
0
        public DTO_Period GetPeriodByKey(string periodId)
        {
            DataTable dt = dal.GetPeriodById(periodId);

            if (dt.Rows.Count < 0)
            {
                return(null);
            }

            try
            {
                DataRow row = dt.Rows[0];

                DTO_Period period = new DTO_Period();

                period.Id        = row["Id"] == DBNull.Value ? null : row["Id"].ToString();
                period.WeekDay   = row["DayInWeek"] == DBNull.Value ? WeekDay.MONDAY : (WeekDay)Convert.ToInt16(row["DayInWeek"]);
                period.Schedule  = row["Schedule"] == DBNull.Value ? null : row["Schedule"].ToString();
                period.StartTime = row["StartTime"] == DBNull.Value ? new DateTime(1970, 1, 1) : Convert.ToDateTime(row["StartTime"].ToString());
                period.EndTime   = row["EndTime"] == DBNull.Value ? new DateTime(1970, 1, 1) : Convert.ToDateTime(row["EndTime"].ToString());

                return(period);
            }
            catch
            {
                return(null);
            }
        }
Example #3
0
        /// <summary>
        /// Add new period
        /// </summary>
        /// <param name="period">The period object want to add</param>
        /// <returns>Return true if update success, Error if update fail or validate fail</returns>
        public SQLResult AddNewPeriod(DTO_Period period)
        {
            if (period == null)
            {
                return(new SQLResult(false, "Period null"));
            }

            return(dal.AddNewPeriod(period));
        }
Example #4
0
        /// <summary>
        /// Update period information
        /// </summary>
        /// <param name="period">The card period want to update</param>
        /// <returns>Return true if update success, Error if update fail or validate fail</returns>
        public SQLResult UpdatePeriod(DTO_Period period)
        {
            if (period == null)
            {
                return(new SQLResult(false, "Period null"));
            }

            return(dal.UpdatePeriod(period));
        }
Example #5
0
        private void btAddPeriod_Click(object sender, RoutedEventArgs e)
        {
            DTO_Period period = new DTO_Period();

            period.Schedule = MySchedule.Id;

            wdPeriodDetail view = new wdPeriodDetail(EType.WindowMode.ADD_MODE, period);

            if (view.ShowDialog() == true)
            {
                LoadPeriod();
            }
        }
Example #6
0
        /// <summary>
        /// Insert new period to database
        /// </summary>
        /// <param name="card"></param>
        /// <returns></returns>
        public SQLResult AddNewPeriod(DTO_Period period)
        {
            DataTable dt     = new DataTable();
            SQLResult result = new SQLResult(false, "");

            try
            {
                _conn.Open();

                SqlCommand command = new SqlCommand();
                command.Connection  = _conn;
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "spLPeriodSave";
                command.Parameters.AddWithValue("WorkType", "A");
                command.Parameters.AddWithValue("@Id", "");
                command.Parameters.AddWithValue("@DayInWeek", period.WeekDay);
                command.Parameters.AddWithValue("@Schedule", period.Schedule);
                command.Parameters.AddWithValue("@StartTime", period.StartTime);
                command.Parameters.AddWithValue("@EndTime", period.EndTime);

                SqlDataAdapter adapter = new SqlDataAdapter();
                adapter.SelectCommand = command;
                adapter.Fill(dt);

                if (dt.Rows[0]["Result"].ToString() == "OK")
                {
                    result.Result = true;
                }

                result.Detail    = dt.Rows[0]["Detail"].ToString();
                result.ExtraData = dt.Rows[0]["ExtraData"].ToString();
            }
            catch (Exception ex)
            {
                result.Detail = ex.Message;
            }
            finally
            {
                _conn.Close();
            }

            return(result);
        }
Example #7
0
        private void DelPeriodWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (result.Result)
            {
                foreach (DTO_Schedule schedule in Repository.lstAllSchedules)
                {
                    DTO_Period pr = schedule.Periods.FirstOrDefault(p => p.Id == period.Id);
                    if (pr != null)
                    {
                        schedule.Periods.Remove(pr);
                    }
                }

                this.DialogResult = true;
                this.Hide();
            }
            else
            {
                MessageBox.Show(result.Detail, "", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Example #8
0
        private void MyPeriodWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            btSave.IsEnabled = true;

            if (result.Result)
            {
                if (this.mode == EType.WindowMode.ADD_MODE)
                {
                    if (getPeriodWorker.IsBusy)
                    {
                        getPeriodWorker.CancelAsync();
                    }
                    else
                    {
                        getPeriodWorker.RunWorkerAsync();
                    }
                }
                else
                {
                    DTO_Schedule schedule = Repository.lstAllSchedules.FirstOrDefault(c => c.Id == period.Schedule);
                    if (schedule != null)
                    {
                        DTO_Period oldPeriod = schedule.Periods.FirstOrDefault(p => p.Id == period.Id);
                        if (oldPeriod != null)
                        {
                            oldPeriod = period;
                        }
                    }

                    this.DialogResult = true;
                    this.Hide();
                }
            }
            else
            {
                MessageBox.Show(result.Detail, "", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Example #9
0
        private string GenPeriodDetail(DTO_Period MyPeriod)
        {
            string weekday = "";

            switch (MyPeriod.WeekDay)
            {
            case EType.WeekDay.MONDAY:
                weekday = "Thứ 2";
                break;

            case EType.WeekDay.TUESDAY:
                weekday = "Thứ 3";
                break;

            case EType.WeekDay.WEDNESDAY:
                weekday = "Thứ 4";
                break;

            case EType.WeekDay.THURSDAY:
                weekday = "Thứ 5";
                break;

            case EType.WeekDay.FRIDAY:
                weekday = "Thứ 6";
                break;

            case EType.WeekDay.SATURDAY:
                weekday = "Thứ 7";
                break;

            case EType.WeekDay.SUNDAY:
                weekday = "CN";
                break;
            }

            return(string.Format("{0}  {1} - {2}", weekday, MyPeriod.StartTime.ToString("HH:mm"), MyPeriod.EndTime.ToString("HH:mm")));
        }
Example #10
0
 public wdPeriodDetail(EType.WindowMode mode, DTO_Period period)
 {
     InitializeComponent();
     this.period = period;
     this.mode   = mode;
 }