Beispiel #1
0
        private void btnupdateJob_Click(object sender, EventArgs e)
        {
            try {
                var parent = (saavyTechManinForm)MdiParent;

                if (cbostatus.SelectedIndex == 3)
                {
                    //Collect data from the form
                    var techReport = txttechReport.Text;
                    var status     = Convert.ToInt32(cbostatus.SelectedValue);
                    var job        = GetJobByID(rowid);
                    job.techReport    = techReport;
                    job.techId        = parent.userId;
                    job.statusId      = status;
                    job.dateCollected = DateTime.Now;
                    contx.SaveChanges();
                    MessageBox.Show("Job successfully updated.");
                }
                else
                {
                    var techReport = txttechReport.Text;
                    var status     = Convert.ToInt32(cbostatus.SelectedValue);
                    var job        = GetJobByID(rowid);
                    job.techReport   = techReport;
                    job.techId       = parent.userId;
                    job.statusId     = status;
                    job.dateRepaired = DateTime.Now;
                    contx.SaveChanges();
                    MessageBox.Show("Job successfully updated.");
                }
                RefreshGridView();
                txttechReport.Clear();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                //Collect data from the form
                var fname   = UppercaseFirst(txtfname.Text);
                var lname   = UppercaseFirst(txtlname.Text);
                var pNumber = txtphoneNumber.Text;
                var Email   = txtemail.Text;
                var uName   = txtusername.Text;
                var uRole   = Convert.ToInt32(cbouserRole.SelectedValue);

                //Validate minimum data is collected, as well as any other validation that you may want to enforce.
                if (isFormInvalid())
                {
                    MessageBox.Show("Please validate all data before submission!");
                }
                else
                {
                    var user = GetUserByID(rowid);
                    user.firstName   = fname;
                    user.lastName    = lname;
                    user.phoneNumber = pNumber;
                    user.email       = Email;
                    user.roleId      = uRole;

                    contx.SaveChanges();
                    MessageBox.Show("User " + uName + " successfully updated.");

                    RefreshGridView();
                    ResetForm();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"A fatal error occurred. {ex.Message}");
            }
        }
        private void btnsaveJob_Click(object sender, EventArgs e)
        {
            var parent = (saavyTechManinForm)MdiParent;
            var roleId = parent.userRole;

            try
            {
                //Collect data from the form
                var fname   = UppercaseFirst(txtfName.Text);
                var lname   = UppercaseFirst(txtlName.Text);
                var pNumber = txtphoneNum.Text;
                var mail    = txtemail.Text;
                var model   = txtmodel.Text;
                var serial  = txtserial.Text;
                var problem = txtproblem.Text;

                var equipment = Convert.ToInt32(cboequipType.SelectedValue);
                var brand     = Convert.ToInt32(cbobrand.SelectedValue);
                var status    = Convert.ToInt32(cbostatus.SelectedValue);

                //generate job number
                char[] letters      = "qwertyuiopasdfghjklzxcvbnm0123456789".ToCharArray();
                Random l            = new Random();
                string randomString = "";
                for (int i = 0; i < 6; i++)
                {
                    randomString += letters[l.Next(0, 35)].ToString();
                }
                var jobNumber = $"{fname[0]}{lname[0]}{randomString}";

                //Validate minimum data is collected, as well as any other validation that you may want to enforce.
                if (isFormInvalid())
                {
                    MessageBox.Show("Please validate all data before submission!");
                }

                //Do further validations to check if job number already exists
                else if (CheckJob(jobNumber))
                {
                    MessageBox.Show("This job already exists!");
                }
                else
                {
                    var newJob = new Jobs
                    {
                        firstName       = fname,
                        lastName        = lname,
                        contact         = pNumber,
                        email           = mail,
                        equipmentTypeId = equipment,
                        brandId         = brand,
                        model           = model,
                        serial          = serial,
                        issues          = problem,
                        statusId        = status,
                        recepId         = roleId,
                        dateIn          = DateTime.Now,
                        jobNumber       = jobNumber
                    };

                    contx.Jobs.Add(newJob);
                    contx.SaveChanges();
                    MessageBox.Show("Job #" + jobNumber + " \nfor " + fname + " " + lname + " successfully added.");

                    ResetForm();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"A fatal. {ex.Message}");
            }
        }