Exemplo n.º 1
0
        public void bntCreate_Click(Object sender, EventArgs e)
        {
            var id            = Page.Request.Params["id"];
            var userInSession = (Users)Session["userinsession"];
            var driver        = new Drivers
            {
                CarID    = Convert.ToInt32(ddlCar.SelectedValue),
                StatusID = Convert.ToInt32(ddlStatus.SelectedValue),

                FirstName          = tbFirstName.Text.Trim(),
                LastName           = tbLastName.Text.Trim(),
                ThirdName          = tbThirdName.Text.Trim(),
                PhoneOne           = tbPhoneOne.Text.Trim(),
                PhoneTwo           = tbPhoneTwo.Text.Trim(),
                HomePhone          = tbPhoneHome.Text.Trim(),
                HomeAddress        = tbHomeAddress.Text.Trim(),
                ContactPersonFIO   = tbContactPersonFIO.Text.Trim(),
                ContactPersonPhone = tbContactPersonPhone.Text.Trim(),

                PassportSeria       = tbPassportSeria.Text.Trim(),
                PassportNumber      = tbPassportNumber.Text.Trim(),
                PersonalNumber      = tbPersonalNumber.Text.Trim(),
                ROVD                = tbROVD.Text.Trim(),
                RegistrationAddress = tbRegistrationAddress.Text.Trim(),

                DriverPassport = tbDriverPassport.Text.Trim(),
            };

            if (!String.IsNullOrEmpty(tbBirthDay.Text))
            {
                driver.BirthDay = Convert.ToDateTime(tbBirthDay.Text);
            }

            if (!String.IsNullOrEmpty(tbValidity.Text))
            {
                driver.Validity = Convert.ToDateTime(tbValidity.Text);
            }

            if (!String.IsNullOrEmpty(tbDateOfIssue.Text))
            {
                driver.DateOfIssue = Convert.ToDateTime(tbDateOfIssue.Text);
            }

            if (!String.IsNullOrEmpty(tbDriverPassportDateOfIssue.Text))
            {
                driver.DriverPassportDateOfIssue = Convert.ToDateTime(tbDriverPassportDateOfIssue.Text);
            }

            if (!String.IsNullOrEmpty(tbDriverPassportValidity.Text))
            {
                driver.DriverPassportValidity = Convert.ToDateTime(tbDriverPassportValidity.Text);
            }

            if (!String.IsNullOrEmpty(tbMedPolisDateOfIssue.Text))
            {
                driver.MedPolisDateOfIssue = Convert.ToDateTime(tbMedPolisDateOfIssue.Text);
            }

            if (!String.IsNullOrEmpty(tbMedPolisValidity.Text))
            {
                driver.MedPolisValidity = Convert.ToDateTime(tbMedPolisValidity.Text);
            }

            if (id == null)
            {
                var sameDriver = new Drivers {
                    DriverPassport = tbDriverPassport.Text.Trim()
                };
                var sameDriverTable = sameDriver.GetAllByDriverPassport();
                if (sameDriverTable.Tables[0].Rows.Count > 0)
                {
                    lblError.Text = "Водитель с таким ВУ уже существует в базе!";
                    return;
                }
                driver.CreateDate = DateTime.Now;
                driver.Create();
            }
            else
            {
                var sameDriver = new Drivers {
                    DriverPassport = tbDriverPassport.Text.Trim()
                };
                var sameDriverTable = sameDriver.GetAllByDriverPassport();
                if (sameDriverTable.Tables[0].Rows.Count > 0 && tbDriverPassport.Text.Trim() != hfDriverPassport.Value)
                {
                    lblError.Text = "Водитель с таким ВУ уже существует в базе!";
                    return;
                }
                driver.ID         = Convert.ToInt32(id);
                driver.ChangeDate = DateTime.Now;
                driver.Update(userInSession.ID, OtherMethods.GetIPAddress(), "DriversEdit");
            }
            Page.Response.Redirect("~/ManagerUI/Menu/Souls/DriversView.aspx?" + BackLink);
        }