예제 #1
0
        private void tfBirthday_EditValueChanged(object sender, EventArgs e)
        {
            int year = Dates.CalculateAge(driver.Now(), tfBirthday.DateTime);

            if (year < 0 || year > 100)
            {
                year = 0;
            }
            lbBirthday.Text = String.Format("{0:d} Anos", year);
        }
예제 #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);
            }
        }