예제 #1
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (!validator.Validate())
     {
         return;
     }
     if (error)
     {
         return;
     }
     try
     {
         driver d = ((driver)bdgDriver.Current);
         d.Save();
     }
     catch (Exception ex)
     {
         XtraMessageBox.Show(String.Format("{0}\n\n{1}", ex.Message, ex.InnerException));
     }
     finally
     {
         if (this.MessageToSave("Motorista"))
         {
             desk.AddTabAndCloseCurrent(new DriverForm(null), "Novo Motorista", false);
         }
     }
 }
예제 #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!validator.Validate())
            {
                return;
            }
            try
            {
                using (var scope = driver.repo.GetTransaction())
                {
                    driver  dr = (driver)bdgDriver.Current;
                    address ad = (address)bdgAddress.Current;
                    if (Dates.CalculateAge(driver.Now(), tfBirthday.DateTime) < 18)
                    {
                        XtraMessageBox.Show("Idade incorreta, deve ter no mínimo 18 anos");
                        return;
                    }
                    SplashScreenManager.ShowForm(null, typeof(PleaseWaitForm), false, false, false);
                    if (IsNew)
                    {
                        dr.registred_at = driver.Now();
                        dr.registred_by = Singleton.getUser().id;
                        if (!Validations.Unique.CPFDriverIsUnique(dr))
                        {
                            XtraMessageBox.Show(String.Format("O CPF informado ja consta cadastrado, verifique!"));
                            tfCpf.Focus();
                            tfCpf.SelectAll();
                            return;
                        }

                        /*if (!Validations.Unique.CNHDriverIsUnique(dr))
                         * {
                         *  XtraMessageBox.Show(String.Format("A CNH informada ja consta cadastrada, verifique!"));
                         *  tfNumberCnh.Focus();
                         *  tfNumberCnh.SelectAll();
                         *  return;
                         * }*/
                    }
                    DateTime min = DateTime.MinValue;
                    if (DateTime.TryParse(dr.dismissed_at.ToString(), out min))
                    {
                        DialogResult rs = XtraMessageBox.Show(String.Format("Confirma a demissão do Motorista?"),
                                                              "Cadore Tecnologia", MessageBoxButtons.YesNo);
                        if (rs == DialogResult.No)
                        {
                            return;
                        }
                        dr.inactive = true;
                    }
                    else
                    {
                        dr.inactive = false;
                    }
                    ad.Save();
                    dr.address = ad.id;
                    dr.Save();
                    scope.Complete();
                    XtraMessageBox.Show(String.Format("Motorista {0} salvo com sucesso.", dr.full_name));
                    desk.AddTabAndCloseCurrent(new DriverForm(driver.SingleOrDefault(dr.id)), "Editar motorista", false);
                    //if (this.MessageToSave("Motorista"))
                    //  desk.AddTabAndCloseCurrent(new DriverForm(null), "Novo motorista", false);
                }
            }
            catch (Exception ex)
            {
                driver.repo.AbortTransaction();
                XtraMessageBox.Show(String.Format("Ocorreu um erro:\n\n{0}\n{1}", ex.Message, ex.InnerException));
            }
            finally
            {
                SplashScreenManager.CloseForm(false);
            }
        }