示例#1
0
        protected void gridListInvoice_DetailRowExpandedChanged(object sender, ASPxGridViewDetailRowEventArgs e)
        {
            //initialize control
            BootstrapGridView grid             = (BootstrapGridView)sender;
            BootstrapTextBox  txtInvoiceNumber = (BootstrapTextBox)grid.FindDetailRowTemplateControl(e.VisibleIndex, "txtInvoiceNumber");
            BootstrapTextBox  txtApproveBy     = (BootstrapTextBox)grid.FindDetailRowTemplateControl(e.VisibleIndex, "txtApproveBy");
            BootstrapDateEdit dateInvoice      = (BootstrapDateEdit)grid.FindDetailRowTemplateControl(e.VisibleIndex, "dateInvoice");
            BootstrapMemo     txtNote          = (BootstrapMemo)grid.FindDetailRowTemplateControl(e.VisibleIndex, "txtNote");

            //bind control
            if (txtInvoiceNumber == null)
            {
                return;
            }

            txtInvoiceNumber.Text = grid.GetRowValues(e.VisibleIndex, "InvoiceNumber").ToString();
            txtApproveBy.Text     = grid.GetRowValues(e.VisibleIndex, "ApproveBy") != null?grid.GetRowValues(e.VisibleIndex, "ApproveBy").ToString() : string.Empty;

            txtNote.Text = grid.GetRowValues(e.VisibleIndex, "Note") != null?grid.GetRowValues(e.VisibleIndex, "Note").ToString() : string.Empty;

            DateTime InvoiceDate = Convert.ToDateTime(grid.GetRowValues(e.VisibleIndex, "InvoiceDate"));

            if (InvoiceDate != DateTime.Parse("1/1/1900"))
            {
                dateInvoice.Value = InvoiceDate;
            }
            else
            {
                dateInvoice.Value = null;
            }
        }
        protected void deBirthday_Init(object sender, EventArgs e)
        {
            BootstrapDateEdit de = sender as BootstrapDateEdit;

            if (!gv.IsNewRowEditing)
            {
                de.Date = Convert.ToDateTime(gv.GetRowValues(gv.EditingRowVisibleIndex, "Birthday"));
            }
        }
        protected MasterDataModel.MasterDataDriver GetGvValue(BootstrapGridView gv, int key = 0)
        {
            BootstrapTextBox  txtName        = gv.FindEditFormTemplateControl("txtName") as BootstrapTextBox;
            BootstrapComboBox cmbTransportir = gv.FindEditFormTemplateControl("cmbTransportir") as BootstrapComboBox;
            BootstrapDateEdit deBirthday     = gv.FindEditFormTemplateControl("deBirthday") as BootstrapDateEdit;
            BootstrapMemo     txtAddress     = gv.FindEditFormTemplateControl("txtAddress") as BootstrapMemo;
            BootstrapTextBox  txtEmail       = gv.FindEditFormTemplateControl("txtEmail") as BootstrapTextBox;
            BootstrapTextBox  txtPhone1      = gv.FindEditFormTemplateControl("txtPhone1") as BootstrapTextBox;
            BootstrapTextBox  txtPhone2      = gv.FindEditFormTemplateControl("txtPhone2") as BootstrapTextBox;

            MasterDataModel.MasterDataDriver item = new MasterDataModel.MasterDataDriver();
            item.Driver_ID      = key;
            item.Name           = txtName.Text;
            item.Transporter_ID = Convert.ToInt32(cmbTransportir.Value);
            if (deBirthday.Value != null)
            {
                item.Birthday = deBirthday.Date;
            }
            else
            {
                item.Birthday = null;
            }
            item.Address    = txtAddress.Text;
            item.Email      = txtEmail.Text;
            item.Phone1     = txtPhone1.Text;
            item.Phone2     = txtPhone2.Text;
            item.CreationBy = UserProfile.Username;
            item.UpdateBy   = UserProfile.Username;
            if (Session["DriverPhotoImageName"] != null && Session["DriverPhotoImageBytes"] != null)
            {
                item.ImageName  = Convert.ToString(Session["DriverPhotoImageName"]);
                item.ImageBytes = (byte[])Session["DriverPhotoImageBytes"];
                Session["DriverPhotoImageName"]  = null;
                Session["DriverPhotoImageBytes"] = null;
            }

            return(item);
        }
        /// <summary>
        /// This method fires when the user clicks the save button for a row and it saves the trainings
        /// for the user to the database
        /// </summary>
        /// <param name="sender">The lbSaveTrainings LinkButton</param>
        /// <param name="e">The click event</param>
        protected void lbSaveTrainings_Click(object sender, EventArgs e)
        {
            try
            {
                //To hold the training dates
                DateTime?PBCDate = null, ICECPDate = null, TPOTDate = null, TPITOSDate = null;

                //Get the calling button
                LinkButton thisButton = (LinkButton)sender;

                //Get the calling button container
                GridViewDataItemTemplateContainer buttonContainer = (GridViewDataItemTemplateContainer)thisButton.NamingContainer;

                //Get the DateEdits from the row in which the button resides
                BootstrapDateEdit dePBC                = (BootstrapDateEdit)bsGREmployees.FindRowCellTemplateControl(buttonContainer.VisibleIndex, (GridViewDataColumn)bsGREmployees.Columns["CoachColumn"], "dePBCDate");
                BootstrapDateEdit deICECPDate          = (BootstrapDateEdit)bsGREmployees.FindRowCellTemplateControl(buttonContainer.VisibleIndex, (GridViewDataColumn)bsGREmployees.Columns["CoachColumn"], "deICECPDate");
                BootstrapDateEdit deTPOTTrainingDate   = (BootstrapDateEdit)bsGREmployees.FindRowCellTemplateControl(buttonContainer.VisibleIndex, (GridViewDataColumn)bsGREmployees.Columns["ObserverColumn"], "deTPOTTrainingDate");
                BootstrapDateEdit deTPITOSTrainingDate = (BootstrapDateEdit)bsGREmployees.FindRowCellTemplateControl(buttonContainer.VisibleIndex, (GridViewDataColumn)bsGREmployees.Columns["ObserverColumn"], "deTPITOSTrainingDate");

                //Get the employee PK and name
                int    employeePK   = Convert.ToInt32(bsGREmployees.GetRowValues(buttonContainer.VisibleIndex, "ProgramEmployeePK"));
                string employeeName = Convert.ToString(bsGREmployees.GetRowValues(buttonContainer.VisibleIndex, "Name"));

                //Get the training dates from the DateEdits
                PBCDate    = (dePBC.Value == null ? (DateTime?)null : Convert.ToDateTime(dePBC.Value));
                ICECPDate  = (deICECPDate.Value == null ? (DateTime?)null : Convert.ToDateTime(deICECPDate.Value));
                TPOTDate   = (deTPOTTrainingDate.Value == null ? (DateTime?)null : Convert.ToDateTime(deTPOTTrainingDate.Value));
                TPITOSDate = (deTPITOSTrainingDate.Value == null ? (DateTime?)null : Convert.ToDateTime(deTPITOSTrainingDate.Value));

                //Only continue if the employee PK has a value
                if (employeePK > 0)
                {
                    using (PyramidContext context = new PyramidContext())
                    {
                        //To hold the training acronyms of the added trainings
                        List <string> trainingsAdded = new List <string>();

                        //Check each training date to see if it was added
                        if (PBCDate.HasValue)
                        {
                            //Add the PBC training to the database
                            Training PBCTraining = new Training();
                            PBCTraining.CreateDate        = DateTime.Now;
                            PBCTraining.Creator           = User.Identity.Name;
                            PBCTraining.ProgramEmployeeFK = employeePK;
                            PBCTraining.TrainingCodeFK    = (int)Utilities.TrainingFKs.PRACTICE_BASED_COACHING;
                            PBCTraining.TrainingDate      = PBCDate.Value;
                            context.Training.Add(PBCTraining);

                            //Add the PBC training to the list
                            trainingsAdded.Add("PBC");
                        }
                        if (ICECPDate.HasValue)
                        {
                            //Add the ICECP training to the database
                            Training ICECPTraining = new Training();
                            ICECPTraining.CreateDate        = DateTime.Now;
                            ICECPTraining.Creator           = User.Identity.Name;
                            ICECPTraining.ProgramEmployeeFK = employeePK;
                            ICECPTraining.TrainingCodeFK    = (int)Utilities.TrainingFKs.INTRODUCTION_TO_COACHING;
                            ICECPTraining.TrainingDate      = ICECPDate.Value;
                            context.Training.Add(ICECPTraining);

                            //Add the ICECP training to the list
                            trainingsAdded.Add("ICECP");
                        }
                        if (TPOTDate.HasValue)
                        {
                            //Add the TPOT observer training to the database
                            Training TPOTTraining = new Training();
                            TPOTTraining.CreateDate        = DateTime.Now;
                            TPOTTraining.Creator           = User.Identity.Name;
                            TPOTTraining.ProgramEmployeeFK = employeePK;
                            TPOTTraining.TrainingCodeFK    = (int)Utilities.TrainingFKs.TPOT_OBSERVER;
                            TPOTTraining.TrainingDate      = TPOTDate.Value;
                            context.Training.Add(TPOTTraining);

                            //Add the TPOT observer training to the list
                            trainingsAdded.Add("TPOT Observer");
                        }
                        if (TPITOSDate.HasValue)
                        {
                            //Add the TPITOS observer training to the database
                            Training TPITOSTraining = new Training();
                            TPITOSTraining.CreateDate        = DateTime.Now;
                            TPITOSTraining.Creator           = User.Identity.Name;
                            TPITOSTraining.ProgramEmployeeFK = employeePK;
                            TPITOSTraining.TrainingCodeFK    = (int)Utilities.TrainingFKs.TPITOS_OBSERVER;
                            TPITOSTraining.TrainingDate      = TPITOSDate.Value;
                            context.Training.Add(TPITOSTraining);

                            //Add the TPITOS observer training to the list
                            trainingsAdded.Add("TPITOS Observer");
                        }

                        //Check to see if any changes were made
                        if (trainingsAdded.Count > 0)
                        {
                            //Save the trainings to the database
                            context.SaveChanges();

                            //Refresh the gridview
                            bsGREmployees.DataBind();

                            //Show the user a message
                            msgSys.ShowMessageToUser("success", "Trainings Added", string.Join(",", trainingsAdded) + " trainings were added for " + employeeName, 10000);
                        }
                        else
                        {
                            //Show the user a warning
                            msgSys.ShowMessageToUser("warning", "No Dates Detected", "No training dates were entered, and no changes have been saved.", 5000);
                        }
                    }
                }
                else
                {
                    //Show the user a warning
                    msgSys.ShowMessageToUser("warning", "No Employee Info Found", "The system was unable to determine the employee, please try again.", 5000);
                }
            }
            catch (Exception ex)
            {
                //Log the exception
                Utilities.LogException(ex);

                //Show the user the message
                msgSys.ShowMessageToUser("danger", "Error!", "An error occurred.  Message: " + ex.Message, 5000);
            }
        }