コード例 #1
0
        internal void cmdSave_Click(Object eventSender, System.EventArgs eventArgs)
        {
            using (var async1 = this.Async(true))
            {
                //Save Training Record
                PTSProject.clsTraining cTraining = Container.Resolve <clsTraining>();

                if (ViewModel.lSpecificID == 0)
                {
                    ViewManager.ShowMessage("Please Select Specific Training Type.", "Save Training Record(s)", UpgradeHelpers.Helpers.BoxButtons.OK);
                    this.Return();
                    return;
                }
                ViewModel.cmdSave.Enabled = false;

                if (modGlobal.Shared.gSecondaryID != 0)
                {
                    async1.Append(() =>
                    {
                        ViewManager.NavigateToView(
                            dlgMessage.DefInstance, true);
                    });
                    async1.Append(() =>
                    {
                        if (modGlobal.Shared.gMessageText == "")
                        {
                            ViewModel.cmdSave.Enabled = false;
                            ClearScreen();
                            this.Return();
                            return;
                        }
                    });
                }
                async1.Append(() =>
                {
                    if (modGlobal.Clean(ViewModel.txtComments.Text) == "")
                    {
                        cTraining.RecordComments = "";
                    }
                    else
                    {
                        cTraining.RecordComments = modGlobal.Clean(modGlobal.ProofSQLString(ViewModel.txtComments.Text));
                    }

                    cTraining.RecordSpecificCode = ViewModel.lSpecificID;
                    cTraining.RecordTrainingDate = DateTime.Parse(ViewModel.calTrainDate.SelectionRange.Start.ToString("M/d/yyyy"));
                    if (ViewModel.cboHours.Visible)
                    {
                        cTraining.RecordHours = (float)Double.Parse(ViewModel.cboHours.Text);
                    }
                    else
                    {
                        cTraining.RecordHours = 0;
                    }

                    cTraining.RecordCreateBy = modPTSPayroll.Shared.gUserSAPid;

                    cTraining.RecordProviderFlag   = 0;
                    cTraining.RecordInstructorFlag = 0;

                    if (ViewModel.frmProvInst.Visible)
                    {
                        if (ViewModel.chkProvider.CheckState == UpgradeHelpers.Helpers.CheckState.Checked)
                        {
                            cTraining.RecordProviderFlag = 1;
                        }
                    }

                    if (ViewModel.frmProvInst.Visible)
                    {
                        if (ViewModel.chkInstructor.CheckState == UpgradeHelpers.Helpers.CheckState.Checked)
                        {
                            cTraining.RecordInstructorFlag = 1;
                        }
                    }

                    cTraining.RecordPassFail = "";
                    if (ViewModel.frmPassFail.Visible)
                    {
                        if (ViewModel.optPass.Checked)
                        {
                            cTraining.RecordPassFail = "P";
                        }
                        else if (ViewModel.optFail.Checked)
                        {
                            cTraining.RecordPassFail = "F";
                        }
                    }

                    if (ViewModel.frmCategories.Visible)
                    {
                        if (ViewModel.OptCat1.Checked)
                        {
                            cTraining.RecordCategoryID = 1;
                        }
                        else if (ViewModel.OptCat2.Checked)
                        {
                            cTraining.RecordCategoryID = 2;
                        }
                        else if (ViewModel.OptCat3.Checked)
                        {
                            cTraining.RecordCategoryID = 3;
                        }
                        else if (ViewModel.OptCat4.Checked)
                        {
                            cTraining.RecordCategoryID = 4;
                        }
                        else
                        {
                            cTraining.RecordCategoryID = 0;
                        }
                    }
                    else
                    {
                        cTraining.RecordCategoryID = 0;
                    }

                    //will need to loop through the lstTrainStaff
                    for (int i = 0; i <= ViewModel.lstTrainStaff.Items.Count - 1; i++)
                    {
                        cTraining.RecordEmployeeID = ViewModel.lstTrainStaff.GetListItem(i).Substring(Math.Max(ViewModel.lstTrainStaff.GetListItem(i).Length - 5, 0));
                        if (~cTraining.AddTrainingRecord() != 0)
                        {
                            ViewManager.ShowMessage("Ooops! Something is wrong!!  Training Record was not saved.", "Add New Training Record", UpgradeHelpers.Helpers.BoxButtons.OK);
                            ViewModel.cmdSave.Enabled = true;
                        }
                    }
                    ViewModel.lbSaveMsg.Visible = true;
                    UpgradeSolution1Support.PInvoke.SafeNative.kernel32.Sleep(1500);
                    ViewModel.lbSaveMsg.Visible = false;
                    ViewModel.cmdSave.Enabled   = false;
                });
            }
        }