Beispiel #1
0
        public static CustomList <ShiftPlan> GetAllShift()
        {
            ConnectionManager      conManager          = new ConnectionManager(ConnectionName.HR);
            CustomList <ShiftPlan> ShiftPlanCollection = new CustomList <ShiftPlan>();
            IDataReader            reader = null;
            const String           sql    = "select ShiftID,ALISE from ShiftPlan";

            try
            {
                conManager.OpenDataReader(sql, out reader);
                while (reader.Read())
                {
                    ShiftPlan newShiftPlan = new ShiftPlan();
                    newShiftPlan.SetDataShift(reader);
                    ShiftPlanCollection.Add(newShiftPlan);
                }
                return(ShiftPlanCollection);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                if (reader != null && !reader.IsClosed)
                {
                    reader.Close();
                }
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                CustomList <ASL.Hr.DAO.ShiftPlan> lstShiftPlan = (CustomList <ASL.Hr.DAO.ShiftPlan>)ShiftPlanMasterList;
                if (lstShiftPlan.Count == 0)
                {
                    ASL.Hr.DAO.ShiftPlan newShiftPlan = new ASL.Hr.DAO.ShiftPlan();
                    lstShiftPlan.Add(newShiftPlan);
                }
                SetDataFromControlToObj(ref lstShiftPlan);
                CustomList <ShiftBreakInfo> lstShiftBreakInfo = (CustomList <ShiftBreakInfo>)ShiftBreakInfoList;

                if (!CheckUserAuthentication(lstShiftPlan, lstShiftBreakInfo))
                {
                    return;
                }
                manager.SaveShiftPlan(ref lstShiftPlan, ref lstShiftBreakInfo);
                txtShiftID.Text = manager._ShiftID.ToString();
                ((PageBase)this.Page).SuccessMessage = (StaticInfo.SavedSuccessfullyMsg);
            }
            catch (SqlException ex)
            {
                ((PageBase)this.Page).ErrorMessage = (ExceptionHelper.getSqlExceptionMessage(ex));
            }
            catch (Exception ex)
            {
                ((PageBase)this.Page).ErrorMessage = (ExceptionHelper.getExceptionMessage(ex));
            }
        }
        private void SetDataFromControlToObj(ref CustomList <ASL.Hr.DAO.ShiftPlan> lstShiftPlan)
        {
            try
            {
                ASL.Hr.DAO.ShiftPlan obj = lstShiftPlan[0];
                obj.ShiftType   = ddlShiftType.SelectedValue.ToInt();
                obj.ALISE       = txtAlise.Text;
                obj.Description = txtDescription.Text;
                obj.ShiftIntime = DateTime.Now.ToShortDateString() + ' ' + txtShiftInTime.Text;
                DateTime I  = (DateTime.Now.ToShortDateString() + ' ' + txtShiftInTime.Text).ToDateTime();
                DateTime IS = (DateTime.Now.ToShortDateString() + ' ' + txtShiftInStartMargin.Text).ToDateTime();
                if (IS < I)
                {
                    obj.ShiftInStartMargin = DateTime.Now.ToShortDateString() + ' ' + txtShiftInStartMargin.Text;
                }
                else
                {
                    obj.ShiftInStartMargin = DateTime.Now.AddDays(-1).ToShortDateString() + ' ' + txtShiftInStartMargin.Text;
                }

                DateTime O  = (DateTime.Now.ToShortDateString() + ' ' + txtShiftOutTime.Text).ToDateTime();
                DateTime OE = (DateTime.Now.ToShortDateString() + ' ' + txtShiftOutEndMargin.Text).ToDateTime();
                if (I < O)
                {
                    obj.ShiftOutTime = DateTime.Now.ToShortDateString() + ' ' + txtShiftOutTime.Text;
                }
                else
                {
                    obj.ShiftOutTime = DateTime.Now.AddDays(1).ToShortDateString() + ' ' + txtShiftOutTime.Text;
                }
                if (I < OE)
                {
                    obj.ShiftOutEndMargin = DateTime.Now.ToShortDateString() + ' ' + txtShiftOutEndMargin.Text;
                }
                else
                {
                    obj.ShiftOutEndMargin = DateTime.Now.AddDays(1).ToShortDateString() + ' ' + txtShiftOutEndMargin.Text;
                }
                obj.AbsentEndmargin     = txtAbsentEndMargin.Text;
                obj.IsActive            = chkMakeItActive.Checked;
                obj.IsDefault           = chkMakeItDefault.Checked;
                obj.IsAutoCalculate     = chkIsAutoCalculate.Checked;
                obj.IsProcessInSameDate = chkIsProcessInSameDate.Checked;
                obj.LateMargin          = txtLateMargin.Text;
                obj.EarlyOutMargin      = txtEarlyOutMargin.Text;
                if (obj.ShiftID != 0)
                {
                    obj.SetModified();
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
        private void PopulateShiftPlanInformation(ASL.Hr.DAO.ShiftPlan shiftPlan)
        {
            try
            {
                txtShiftID.Text            = shiftPlan.ShiftID.ToString();
                ddlShiftType.SelectedValue = shiftPlan.ShiftType.ToString();
                txtAlise.Text                  = shiftPlan.ALISE;
                txtDescription.Text            = shiftPlan.Description;
                chkIsAutoCalculate.Checked     = shiftPlan.IsAutoCalculate;
                chkIsProcessInSameDate.Checked = shiftPlan.IsProcessInSameDate;
                chkMakeItActive.Checked        = shiftPlan.IsActive;
                chkMakeItDefault.Checked       = shiftPlan.IsDefault;
                txtShiftInTime.Text            = shiftPlan.ShiftIntime.ToDateTime().ToShortTimeString();
                txtShiftInStartMargin.Text     = shiftPlan.ShiftInStartMargin.ToDateTime().ToShortTimeString();
                txtShiftOutTime.Text           = shiftPlan.ShiftOutTime.ToDateTime().ToShortTimeString();
                txtShiftOutEndMargin.Text      = shiftPlan.ShiftOutEndMargin.ToDateTime().ToShortTimeString();
                txtAbsentEndMargin.Text        = shiftPlan.AbsentEndmargin.ToString() == "" ?  "": shiftPlan.AbsentEndmargin.ToDateTime().ToShortTimeString();

                /*DateTime toDate = DateTime.ParseExact(shiftPlan.ShiftOutTime, "dd/MM/yyyy hh:mm tt", CultureInfo.InvariantCulture);
                 * DateTime fromDate = DateTime.ParseExact(shiftPlan.ShiftIntime, "dd/MM/yyyy hh:mm tt", CultureInfo.InvariantCulture);
                 * TimeSpan diff = (toDate - fromDate);
                 * var seconds = diff.TotalSeconds;
                 * var minutes = Math.Floor(seconds / 60);
                 * seconds = seconds % 60;
                 * var hours = Math.Floor(minutes / 60);
                 * minutes = minutes % 60;
                 * txtWorkingHour.Text = hours + ":" + minutes;*/
                txtWorkingHour.Text = "8";

                txtEarlyOutMargin.Text = shiftPlan.EarlyOutMargin;
                txtLateMargin.Text     = shiftPlan.LateMargin;
                ShiftBreakInfoList     = manager.GetAllShiftBreakInfo(shiftPlan.ShiftID);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         ClientScript.RegisterClientScriptBlock(GetType(), "IsPostBack", "var isPostBack = true;", true);
         InitializeCombo();
         InitializeSession();
     }
     else
     {
         Page.ClientScript.GetPostBackEventReference(this, String.Empty);
         String eventTarget = Request["__EVENTTARGET"].IsNullOrEmpty() ? String.Empty : Request["__EVENTTARGET"];
         if (Request["__EVENTTARGET"] == "SearchShiftPlan")
         {
             ShiftPlanMasterList = new CustomList <ASL.Hr.DAO.ShiftPlan>();
             ASL.Hr.DAO.ShiftPlan searchShiftPlan = Session[ASL.STATIC.StaticInfo.SearchSessionVarName] as ASL.Hr.DAO.ShiftPlan;
             ShiftPlanMasterList.Add(searchShiftPlan);
             if (searchShiftPlan.IsNotNull())
             {
                 PopulateShiftPlanInformation(searchShiftPlan);
             }
         }
     }
 }