コード例 #1
0
    private void SelfReplacement_Save()
    {
        dlo = new DataLoadOptions();
        dlo.LoadWith<Ajancy.Person>(p => p.User);
        dlo.LoadWith<Ajancy.User>(u => u.UsersInRoles);
        dlo.LoadWith<Ajancy.Person>(p => p.DriverCertifications);
        dlo.LoadWith<Ajancy.DriverCertification>(dc => dc.DriverCertificationCars);
        dlo.LoadWith<Ajancy.DriverCertificationCar>(dcc => dcc.CarPlateNumber);
        dlo.LoadWith<Ajancy.CarPlateNumber>(cpn => cpn.Car);
        dlo.LoadWith<Ajancy.Car>(c => c.FuelCards);
        db = new Ajancy.Kimia_Ajancy(Public.ConnectionString);
        db.LoadOptions = dlo;

        #region AjancyType

        Ajancy.Person person = db.Persons.First<Ajancy.Person>(p => p.PersonID == Public.ToInt(this.ViewState["PersonID"]));
        Ajancy.DriverCertification driverCertification = person.DriverCertifications.First<Ajancy.DriverCertification>(dc => dc.CertificationType == (byte)Public.AjancyType.TaxiAjancy);
        Ajancy.DriverCertificationCar driverCertificationCar = driverCertification.DriverCertificationCars.Last<Ajancy.DriverCertificationCar>(dcc => dcc.LockOutDate == null);
        Ajancy.CarPlateNumber carPlateNumber = driverCertificationCar.CarPlateNumber;
        Ajancy.ZonePlateNumber plateNumber = carPlateNumber.ZonePlateNumber;
        Ajancy.Car car = carPlateNumber.Car;
        Ajancy.FuelCard fuelCard = car.FuelCards.Last<Ajancy.FuelCard>();

        if (db.Cars.Any<Ajancy.Car>(c => c.VIN == this.txtCarVIN.Text.Trim() && c.CarID != car.CarID))
        {
            this.lblMessage.Text = "خودرو بخش کارت سوخت آژانسی با این شماره VIN متعلق به شخص دیگری میباشد";
            return;
        }

        if (db.FuelCards.Any<Ajancy.FuelCard>(fc => fc.PAN == this.txtFuelCardPAN.Text && fc.FuelCardID != fuelCard.FuelCardID))
        {
            this.lblMessage.Text = "شماره PAN کارت سوخت خودرو بخش کارت سوخت آژانسی قبلا برای خودرو دیگری ثبت شده";
            return;
        }

        Ajancy.ZonePlateNumber pln = db.ZonePlateNumbers.FirstOrDefault<Ajancy.ZonePlateNumber>(pl => pl.CityID == Public.ToShort(this.drpCarPlateNumberCity.SelectedValue) &&
                                                                                                      pl.Number == this.txtCarPlateNumber_5.Text.Trim() &&
                                                                                                      pl.ZonePlateNumberID != carPlateNumber.ZonePlateNumberID);
        if (pln != null)
        {
            this.lblMessage.Text = "شماره پلاک وارد شده در  بخش کارت سوخت آژانسی متعلق به شخص دیگری میباشد";
            return;
        }

        // --------------- setting values

        driverCertificationCar.LockOutDate = DateTime.Now;
        driverCertificationCar.AjancyDrivers.Last<Ajancy.AjancyDriver>(jd => jd.LockOutDate == null).LockOutDate = DateTime.Now;

        person.FirstName = this.txtFirstName.Text.Trim();
        person.LastName = this.txtLastName.Text.Trim();

        plateNumber.CityID = Public.ToShort(this.drpCarPlateNumberCity.SelectedValue);
        plateNumber.Number = this.txtCarPlateNumber_5.Text.Trim();

        car.CarTypeID = Public.ToShort(this.drpCarType.SelectedValue);
        car.FuelType = Public.ToByte(this.drpFuelType.SelectedValue);
        car.Model = this.txtCarModel.Text;

        fuelCard.CardType = (byte)Public.FuelCardType.Ajancy;
        fuelCard.PAN = this.txtFuelCardPAN.Text.Trim();
        fuelCard.DiscardDate = DateTime.Now;

        car.VIN = this.txtCarVIN.Text.Trim().ToUpper();

        #endregion

        #region PersonalType

        if (db.Cars.Any<Ajancy.Car>(c => c.VIN == this.txtCarVIN_2.Text.Trim()))
        {
            this.lblMessage.Text = "خودرو بخش کارت سوخت شخصی با این شماره VIN متعلق به شخص دیگری میباشد";
            return;
        }

        if (db.FuelCards.Any<Ajancy.FuelCard>(fc => fc.PAN == this.txtFuelCardPAN_2.Text))
        {
            this.lblMessage.Text = "شماره PAN کارت سوخت خودرو بخش کارت سوخت شخصی قبلا برای خودرو دیگری ثبت شده";
            return;
        }

        Ajancy.ZonePlateNumber pnl = db.ZonePlateNumbers.FirstOrDefault<Ajancy.ZonePlateNumber>(pl => pl.CityID == Public.ToShort(this.drpCarPlateNumberCity_2.SelectedValue) &&
                                                                                                      pl.Number == this.txtCarPlateNumber_5_2.Text.Trim());
        if (pnl != null)
        {
            this.lblMessage.Text = "شماره پلاک وارد شده در  بخش کارت سوخت شخصی متعلق به شخص دیگری میباشد";
            return;
        }

        Ajancy.DriverCertificationCar driverCertificationCar_2 = new Ajancy.DriverCertificationCar { SubmitDate = DateTime.Now };
        Ajancy.CarPlateNumber carPlateNumber_2 = new Ajancy.CarPlateNumber();
        Ajancy.ZonePlateNumber plateNumber_2 = new Ajancy.ZonePlateNumber();
        Ajancy.Car car_2 = new Ajancy.Car();
        Ajancy.FuelCard fuelCard_2 = new Ajancy.FuelCard { SubmitDate = DateTime.Now };
        driverCertificationCar_2.CarPlateNumber = carPlateNumber_2;

        carPlateNumber_2 = new Ajancy.CarPlateNumber { Car = car_2, ZonePlateNumber = plateNumber_2 };
        driverCertificationCar_2 = new Ajancy.DriverCertificationCar { CarPlateNumber = carPlateNumber_2, SubmitDate = DateTime.Now };
        driverCertificationCar_2.AjancyDrivers.Add(new Ajancy.AjancyDriver { AjancyID = Public.ToInt(this.drpAjancies_2.SelectedValue), MembershipDate = DateTime.Now });
        driverCertification.DriverCertificationCars.Add(driverCertificationCar_2);
        car_2.FuelCards.Add(fuelCard_2);

        // --------------- setting values

        if (this.txtCarPlateNumber_5.Text.Trim().Equals(this.txtCarPlateNumber_5_2.Text.Trim()) &&
            this.drpCarPlateNumberCity.SelectedValue.Equals(this.drpCarPlateNumberCity_2.SelectedValue))
        {
            carPlateNumber_2.ZonePlateNumber = plateNumber;
        }
        //else
        //{
        //    plateNumber_2.Number = this.txtCarPlateNumber_5_2.Text.Trim();
        //    plateNumber_2.CityID = Public.ToShort(this.drpCarPlateNumberCity_2.SelectedValue);
        //}

        plateNumber_2.Number = this.txtCarPlateNumber_5_2.Text.Trim();
        plateNumber_2.CityID = Public.ToShort(this.drpCarPlateNumberCity_2.SelectedValue);

        car_2.CarTypeID = Public.ToShort(this.drpCarType_2.SelectedValue);
        car_2.FuelType = Public.ToByte(this.drpFuelType_2.SelectedValue);
        car_2.Model = this.txtCarModel_2.Text;

        fuelCard_2.CardType = (byte)Public.FuelCardType.Ajancy;
        fuelCard_2.PAN = this.txtFuelCardPAN_2.Text.Trim();

        car_2.VIN = this.txtCarVIN_2.Text.Trim().ToUpper();

        #endregion

        switch ((Public.Role)Public.ActiveUserRole.RoleID)
        {
            case Public.Role.ProvinceManager:
                person.User.CityID = Public.ToShort(this.drpCity.SelectedValue);
                break;

            case Public.Role.Admin:
                person.User.ProvinceID = Public.ToByte(this.drpProvince.SelectedValue);
                person.User.CityID = Public.ToShort(this.drpCity.SelectedValue);
                break;
        }

        #region Owners

        bool ajancyTypeOwner = false;
        bool personalTypeOwner = false;
        Ajancy.Person ownerPer = null;
        Ajancy.Person ownerPer_2 = null;

        if (!string.IsNullOrEmpty(this.txtOwnerName.Text.Trim()) && !string.IsNullOrEmpty(this.txtOwnerFamily.Text.Trim()) && !string.IsNullOrEmpty(this.txtOwnerNationalCode.Text.Trim()) && !this.txtOwnerNationalCode.Text.Trim().Equals(person.NationalCode))
        {
            ajancyTypeOwner = true;
        }
        if (!string.IsNullOrEmpty(this.txtOwnerName_2.Text.Trim()) && !string.IsNullOrEmpty(this.txtOwnerFamily_2.Text.Trim()) && !string.IsNullOrEmpty(this.txtOwnerNationalCode_2.Text.Trim()) && !this.txtOwnerNationalCode_2.Text.Trim().Equals(person.NationalCode))
        {
            personalTypeOwner = true;
        }

        if (ajancyTypeOwner && personalTypeOwner && this.txtOwnerNationalCode_2.Text == this.txtOwnerNationalCode.Text) // Both owners are the same person
        {
            ownerPer = db.Persons.FirstOrDefault<Ajancy.Person>(p => p.NationalCode == this.txtOwnerNationalCode.Text.Trim());
            if (ownerPer == null)
            {
                ownerPer = new Ajancy.Person { NationalCode = this.txtOwnerNationalCode.Text.Trim(), SubmitDate = DateTime.Now };
                Ajancy.User ownerUser = new Ajancy.User
                {
                    UserName = this.txtOwnerNationalCode.Text.Trim()
                    ,
                    ProvinceID = person.User.ProvinceID
                    ,
                    CityID = person.User.CityID
                    ,
                    SubmitDate = DateTime.Now
                };
                ownerUser.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.CarOwner, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
                ownerPer.User = ownerUser;
                db.Persons.InsertOnSubmit(ownerPer);
            }
            else if (!ownerPer.User.UsersInRoles.Any<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.CarOwner))
            {
                ownerPer.User.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.CarOwner, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
            }

            ownerPer.FirstName = this.txtOwnerName.Text.Trim();
            ownerPer.LastName = this.txtOwnerFamily.Text.Trim();
            ownerPer.CarPlateNumbers.Add(carPlateNumber);
            ownerPer.CarPlateNumbers.Add(carPlateNumber_2);
        }
        else
        {
            if (personalTypeOwner && this.txtNationalCode.Text == this.txtOwnerNationalCode_2.Text) // Cross /
            {
                if (!person.User.UsersInRoles.Any<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.CarOwner))
                {
                    person.User.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.CarOwner, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
                }
                person.CarPlateNumbers.Add(carPlateNumber_2);
            }
            else
            {
                if (personalTypeOwner)
                {
                    ownerPer_2 = db.Persons.FirstOrDefault<Ajancy.Person>(p => p.NationalCode == this.txtOwnerNationalCode_2.Text.Trim());
                    if (ownerPer_2 == null)
                    {
                        ownerPer_2 = new Ajancy.Person { NationalCode = this.txtOwnerNationalCode_2.Text.Trim(), SubmitDate = DateTime.Now };
                        Ajancy.User ownerUser = new Ajancy.User
                        {
                            UserName = this.txtOwnerNationalCode_2.Text.Trim()
                            ,
                            ProvinceID = person.User.ProvinceID
                            ,
                            CityID = person.User.CityID
                            ,
                            SubmitDate = DateTime.Now
                        };
                        ownerUser.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.CarOwner, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
                        ownerPer_2.User = ownerUser;
                        db.Persons.InsertOnSubmit(ownerPer_2);
                    }
                    else if (!ownerPer_2.User.UsersInRoles.Any<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.CarOwner))
                    {
                        ownerPer_2.User.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.CarOwner, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
                    }

                    ownerPer_2.FirstName = this.txtOwnerName_2.Text.Trim();
                    ownerPer_2.LastName = this.txtOwnerFamily_2.Text.Trim();
                    ownerPer_2.CarPlateNumbers.Add(carPlateNumber_2);
                }
                else
                {
                    person.CarPlateNumbers.Add(carPlateNumber_2);
                    if (carPlateNumber_2.OwnerPersonID > 0 && carPlateNumber_2.OwnerPersonID != person.PersonID) // Set driver as owner again
                    {
                        carPlateNumber_2.Person = person;
                    }
                }
            }

            if (ajancyTypeOwner && this.txtNationalCode_2.Text == this.txtOwnerNationalCode.Text) // Cross \
            {
                if (!person.User.UsersInRoles.Any<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.CarOwner))
                {
                    person.User.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.CarOwner, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
                }
                person.CarPlateNumbers.Add(carPlateNumber);
            }
            else
            {
                if (ajancyTypeOwner)
                {
                    ownerPer = db.Persons.FirstOrDefault<Ajancy.Person>(p => p.NationalCode == this.txtOwnerNationalCode.Text.Trim());
                    if (ownerPer == null)
                    {
                        ownerPer = new Ajancy.Person { NationalCode = this.txtOwnerNationalCode.Text.Trim(), SubmitDate = DateTime.Now };
                        Ajancy.User ownerUser = new Ajancy.User
                        {
                            UserName = this.txtOwnerNationalCode.Text.Trim()
                            ,
                            ProvinceID = person.User.ProvinceID
                            ,
                            CityID = person.User.CityID
                            ,
                            SubmitDate = DateTime.Now
                        };
                        ownerUser.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.CarOwner, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
                        ownerPer.User = ownerUser;
                        db.Persons.InsertOnSubmit(ownerPer);
                    }
                    else if (!ownerPer.User.UsersInRoles.Any<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.CarOwner))
                    {
                        ownerPer.User.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.CarOwner, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
                    }

                    ownerPer.FirstName = this.txtOwnerName.Text.Trim();
                    ownerPer.LastName = this.txtOwnerFamily.Text.Trim();
                    ownerPer.CarPlateNumbers.Add(carPlateNumber);
                }
                else
                {
                    person.CarPlateNumbers.Add(carPlateNumber);
                    if (carPlateNumber.OwnerPersonID > 0 && carPlateNumber.OwnerPersonID != person.PersonID) // Set driver as owner again
                    {
                        carPlateNumber.Person = person;
                    }
                }
            }
        }

        #endregion

        if (Public.ActiveUserRole.RoleID == (short)Public.Role.ProvinceManager)
        {
            person.User.CityID = Public.ToShort(this.drpCity.SelectedValue);
        }

        Ajancy.FuelCardSubstitution formerReq = null;
        if (fuelCard.FuelCardID > 0)
        {
            formerReq = db.FuelCardSubstitutions.FirstOrDefault<Ajancy.FuelCardSubstitution>(fcs => (fcs.AjancyTypeFuelCardID == fuelCard.FuelCardID || fcs.PersonalTypeFuelCardID.GetValueOrDefault() == fuelCard.FuelCardID));
            if (formerReq != null)
            {
                this.lblMessage.Text = "برای کارت سوخت بخش آژانسی قبلا درخواست ابطال یا جایگزین ثبت شده است";
                return;
            }
        }
        if (fuelCard_2.FuelCardID > 0)
        {
            formerReq = db.FuelCardSubstitutions.FirstOrDefault<Ajancy.FuelCardSubstitution>(fcs => (fcs.AjancyTypeFuelCardID == fuelCard_2.FuelCardID || fcs.PersonalTypeFuelCardID.GetValueOrDefault() == fuelCard_2.FuelCardID));
            if (formerReq != null)
            {
                this.lblMessage.Text = "برای کارت سوخت بخش شخصی قبلا درخواست ابطال یا جایگزین ثبت شده است";
                return;
            }
        }

        formerReq = new Ajancy.FuelCardSubstitution
        {
            FuelCard = fuelCard,
            UserInRoleID = Public.ActiveUserRole.UserRoleID,
            SubmitDate = DateTime.Now
        };

        db.FuelCardSubstitutions.InsertOnSubmit(formerReq);
        db.SubmitChanges();
        formerReq.PersonalTypeFuelCardID = fuelCard_2.FuelCardID;
        db.SubmitChanges();
        DisposeContext();
        Response.Redirect("~/Message.aspx?mode=11");
    }
コード例 #2
0
ファイル: Ajancy.cs プロジェクト: BehnamAbdy/Ajancy
 partial void DeleteFuelCardSubstitution(FuelCardSubstitution instance);
コード例 #3
0
ファイル: Ajancy.cs プロジェクト: BehnamAbdy/Ajancy
		private void detach_FuelCardSubstitutions(FuelCardSubstitution entity)
		{
			this.SendPropertyChanging();
			entity.FuelCard = null;
		}
コード例 #4
0
ファイル: Ajancy.cs プロジェクト: BehnamAbdy/Ajancy
 partial void UpdateFuelCardSubstitution(FuelCardSubstitution instance);
コード例 #5
0
ファイル: Ajancy.cs プロジェクト: BehnamAbdy/Ajancy
 partial void InsertFuelCardSubstitution(FuelCardSubstitution instance);
コード例 #6
0
ファイル: Ajancy.cs プロジェクト: BehnamAbdy/Ajancy
		private void attach_FuelCardSubstitutions(FuelCardSubstitution entity)
		{
			this.SendPropertyChanging();
			entity.UsersInRole = this;
		}
コード例 #7
0
    private void SelfReplacement_Save()
    {
        DataLoadOptions dlo = new DataLoadOptions();
        dlo.LoadWith<Ajancy.Person>(p => p.User);
        dlo.LoadWith<Ajancy.User>(u => u.UsersInRoles);
        dlo.LoadWith<Ajancy.Person>(p => p.DriverCertifications);
        dlo.LoadWith<Ajancy.DriverCertification>(dc => dc.DriverCertificationCars);
        dlo.LoadWith<Ajancy.DriverCertificationCar>(dcc => dcc.CarPlateNumber);
        dlo.LoadWith<Ajancy.CarPlateNumber>(cpn => cpn.Car);
        dlo.LoadWith<Ajancy.Car>(c => c.FuelCards);
        db = new Ajancy.Kimia_Ajancy(Public.ConnectionString);
        db.LoadOptions = dlo;

        #region AjancyType

        Ajancy.Person person = new Ajancy.Person();
        Ajancy.DriverCertification driverCertification = new Ajancy.DriverCertification();
        Ajancy.DriverCertificationCar driverCertificationCar = new Ajancy.DriverCertificationCar();
        Ajancy.CarPlateNumber carPlateNumber = new Ajancy.CarPlateNumber();
        Ajancy.PlateNumber plateNumber = new Ajancy.PlateNumber();
        Ajancy.Car car = new Ajancy.Car();
        Ajancy.FuelCard fuelCard = new Ajancy.FuelCard();

        if (db.Cars.Any<Ajancy.Car>(c => c.VIN == this.txtCarVIN.Text.Trim()))
        {
            this.lblMessage.Text = "خودرو بخش کارت سوخت آژانسی با این شماره VIN متعلق به شخص دیگری میباشد";
            return;
        }

        if (db.FuelCards.Any<Ajancy.FuelCard>(fc => fc.PAN == this.txtFuelCardPAN.Text))
        {
            this.lblMessage.Text = "شماره PAN کارت سوخت خودرو بخش کارت سوخت آژانسی قبلا برای خودرو دیگری ثبت شده";
            return;
        }

        Ajancy.PlateNumber pln = db.PlateNumbers.FirstOrDefault<Ajancy.PlateNumber>(pl => pl.TwoDigits == this.txtCarPlateNumber_1.Text.Trim() &&
                                                                                                                            pl.Alphabet == this.drpCarPlateNumber.SelectedValue &&
                                                                                                                            pl.ThreeDigits == this.txtCarPlateNumber_2.Text.Trim() &&
                                                                                                                            pl.RegionIdentifier == this.txtCarPlateNumber_3.Text.Trim());
        if (pln != null)
        {
            this.lblMessage.Text = "شماره پلاک وارد شده در  بخش کارت سوخت آژانسی متعلق به شخص دیگری میباشد";
            return;
        }

        if (this.ViewState["PersonID"] == null && this.ViewState["PersonID_2"] == null) // New Person
        {
            Ajancy.User user = new Ajancy.User();
            user.UserName = this.txtNationalCode.Text.Trim();
            user.ProvinceID = Public.ToByte(this.drpProvince.SelectedValue);
            user.CityID = Public.ToShort(this.drpCity.SelectedValue);
            user.SubmitDate = DateTime.Now;
            user.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.AcademyTeacher, MembershipDate = DateTime.Now });
            person.User = user;
            person.NationalCode = this.txtNationalCode.Text.Trim();
            person.SubmitDate = DateTime.Now;

            driverCertification = new Ajancy.DriverCertification
            {
                CertificationType = (byte)Public.AjancyType.Academy,
                SubmitDate = DateTime.Now
            };
            carPlateNumber = new Ajancy.CarPlateNumber { Car = car, PlateNumber = plateNumber };
            driverCertificationCar = new Ajancy.DriverCertificationCar { CarPlateNumber = carPlateNumber, SubmitDate = DateTime.Now, LockOutDate = DateTime.Now };
            driverCertificationCar.AjancyDrivers.Add(new Ajancy.AjancyDriver { AjancyID = Public.ToInt(this.drpAjancies.SelectedValue), MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
            driverCertification.DriverCertificationCars.Add(driverCertificationCar);
            person.DriverCertifications.Add(driverCertification);
            fuelCard.SubmitDate = DateTime.Now;
            fuelCard.DiscardDate = DateTime.Now;
            car.FuelCards.Add(fuelCard);
            db.Persons.InsertOnSubmit(person);
        }
        else // Person Exists
        {
            if (Public.ActiveUserRole.RoleID == (short)Public.Role.AcademyProvince)
            {
                person.User.CityID = Public.ToShort(this.drpCity_2.SelectedValue);
            }

            person = db.Persons.FirstOrDefault<Ajancy.Person>(p => p.PersonID == Public.ToInt(this.ViewState["PersonID"]));
            person.User.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.AcademyTeacher, MembershipDate = DateTime.Now });
            driverCertification = new Ajancy.DriverCertification
            {
                CertificationType = (byte)Public.AjancyType.Academy,
                SubmitDate = DateTime.Now
            };
            carPlateNumber = new Ajancy.CarPlateNumber { Car = car, PlateNumber = plateNumber };
            driverCertificationCar = new Ajancy.DriverCertificationCar { CarPlateNumber = carPlateNumber, SubmitDate = DateTime.Now, LockOutDate = DateTime.Now };
            driverCertificationCar.AjancyDrivers.Add(new Ajancy.AjancyDriver { AjancyID = Public.ToInt(this.drpAjancies.SelectedValue), DriverCertificationCar = driverCertificationCar, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
            driverCertification.DriverCertificationCars.Add(driverCertificationCar);
            person.DriverCertifications.Add(driverCertification);
            fuelCard.SubmitDate = DateTime.Now;
            fuelCard.DiscardDate = DateTime.Now;
            car.FuelCards.Add(fuelCard);

            switch ((Public.Role)Public.ActiveUserRole.RoleID)
            {
                case Public.Role.AcademyProvince:
                    person.User.CityID = Public.ToShort(this.drpCity.SelectedValue);
                    break;

                case Public.Role.Admin:
                    person.User.ProvinceID = Public.ToByte(this.drpProvince.SelectedValue);
                    person.User.CityID = Public.ToShort(this.drpCity.SelectedValue);
                    break;
            }
        }

        // --------------- setting values

        person.FirstName = this.txtFirstName.Text.Trim();
        person.LastName = this.txtLastName.Text.Trim();

        plateNumber.TwoDigits = this.txtCarPlateNumber_1.Text.Trim();
        plateNumber.Alphabet = this.drpCarPlateNumber.SelectedValue;
        plateNumber.ThreeDigits = this.txtCarPlateNumber_2.Text.Trim();
        plateNumber.RegionIdentifier = this.txtCarPlateNumber_3.Text.Trim();

        car.CarTypeID = Public.ToShort(this.drpCarType.SelectedValue);
        car.FuelType = Public.ToByte(this.drpFuelType.SelectedValue);
        car.Model = this.txtCarModel.Text;

        fuelCard.CardType = (byte)Public.FuelCardType.Ajancy;
        fuelCard.PAN = this.txtFuelCardPAN.Text.Trim();

        car.VIN = this.txtCarVIN.Text.Trim().ToUpper();

        #endregion

        #region PersonalType

        Ajancy.DriverCertificationCar driverCertificationCar_2 = new Ajancy.DriverCertificationCar { SubmitDate = DateTime.Now };
        Ajancy.CarPlateNumber carPlateNumber_2 = new Ajancy.CarPlateNumber();
        Ajancy.PlateNumber plateNumber_2 = new Ajancy.PlateNumber();
        Ajancy.Car car_2 = new Ajancy.Car();
        Ajancy.FuelCard fuelCard_2 = new Ajancy.FuelCard();

        if (db.Cars.Any<Ajancy.Car>(c => c.VIN == this.txtCarVIN_2.Text.Trim()))
        {
            this.lblMessage.Text = "خودرو بخش کارت سوخت شخصی با این شماره VIN متعلق به شخص دیگری میباشد";
            return;
        }

        if (db.FuelCards.Any<Ajancy.FuelCard>(fc => fc.PAN == this.txtFuelCardPAN_2.Text))
        {
            this.lblMessage.Text = "شماره PAN کارت سوخت خودرو بخش کارت سوخت شخصی قبلا برای خودرو دیگری ثبت شده";
            return;
        }

        Ajancy.PlateNumber pnl = db.PlateNumbers.FirstOrDefault<Ajancy.PlateNumber>(pl => pl.TwoDigits == this.txtCarPlateNumber_1_2.Text.Trim() &&
                                                                                                                           pl.Alphabet == this.drpCarPlateNumber_2.SelectedValue &&
                                                                                                                           pl.ThreeDigits == this.txtCarPlateNumber_2_2.Text.Trim() &&
                                                                                                                           pl.RegionIdentifier == this.txtCarPlateNumber_3_2.Text.Trim());
        if (pnl != null)
        {
            this.lblMessage.Text = "شماره پلاک وارد شده در  بخش کارت سوخت شخصی متعلق به شخص دیگری میباشد";
            return;
        }

        if (this.ViewState["PersonID"] == null && this.ViewState["PersonID_2"] == null) // New Person
        {
            carPlateNumber_2 = new Ajancy.CarPlateNumber { Car = car_2, PlateNumber = plateNumber_2 };
            driverCertificationCar_2 = new Ajancy.DriverCertificationCar { CarPlateNumber = carPlateNumber_2, SubmitDate = DateTime.Now };
            driverCertificationCar_2.AjancyDrivers.Add(new Ajancy.AjancyDriver { AjancyID = Public.ToInt(this.drpAjancies_2.SelectedValue), MembershipDate = DateTime.Now });
            driverCertification.DriverCertificationCars.Add(driverCertificationCar_2);
            fuelCard_2.SubmitDate = DateTime.Now;
            car_2.FuelCards.Add(fuelCard_2);
        }
        else // Person Exists
        {
            carPlateNumber_2 = new Ajancy.CarPlateNumber { Car = car_2, PlateNumber = plateNumber_2 };
            driverCertificationCar_2 = new Ajancy.DriverCertificationCar { CarPlateNumber = carPlateNumber_2, SubmitDate = DateTime.Now };
            driverCertificationCar_2.AjancyDrivers.Add(new Ajancy.AjancyDriver { AjancyID = Public.ToInt(this.drpAjancies_2.SelectedValue), MembershipDate = DateTime.Now });
            driverCertification.DriverCertificationCars.Add(driverCertificationCar_2);
            fuelCard_2.SubmitDate = DateTime.Now;
            car_2.FuelCards.Add(fuelCard_2);
        }

        // --------------- setting values

        if (this.txtCarPlateNumber_1.Text.Trim().Equals(this.txtCarPlateNumber_1_2.Text.Trim()) &&
            this.drpCarPlateNumber.SelectedValue.Equals(this.drpCarPlateNumber_2.SelectedValue) &&
            this.txtCarPlateNumber_2.Text.Trim().Equals(this.txtCarPlateNumber_2_2.Text.Trim()) &&
            this.txtCarPlateNumber_3.Text.Trim().Equals(this.txtCarPlateNumber_3_2.Text.Trim()))
        {
            carPlateNumber_2.PlateNumber = plateNumber;
        }
        else
        {
            plateNumber_2.TwoDigits = this.txtCarPlateNumber_1_2.Text.Trim();
            plateNumber_2.Alphabet = this.drpCarPlateNumber_2.SelectedValue;
            plateNumber_2.ThreeDigits = this.txtCarPlateNumber_2_2.Text.Trim();
            plateNumber_2.RegionIdentifier = this.txtCarPlateNumber_3_2.Text.Trim();
        }

        car_2.CarTypeID = Public.ToShort(this.drpCarType_2.SelectedValue);
        car_2.FuelType = Public.ToByte(this.drpFuelType_2.SelectedValue);
        car_2.Model = this.txtCarModel_2.Text;

        fuelCard_2.CardType = (byte)Public.FuelCardType.Ajancy;
        fuelCard_2.PAN = this.txtFuelCardPAN_2.Text.Trim();

        car_2.VIN = this.txtCarVIN_2.Text.Trim().ToUpper();

        #endregion

        #region Owners

        bool ajancyTypeOwner = false;
        bool personalTypeOwner = false;
        Ajancy.Person ownerPer = null;
        Ajancy.Person ownerPer_2 = null;

        if (!string.IsNullOrEmpty(this.txtOwnerName.Text.Trim()) && !string.IsNullOrEmpty(this.txtOwnerFamily.Text.Trim()) && !string.IsNullOrEmpty(this.txtOwnerNationalCode.Text.Trim()) && !this.txtOwnerNationalCode.Text.Trim().Equals(person.NationalCode))
        {
            ajancyTypeOwner = true;
        }
        if (!string.IsNullOrEmpty(this.txtOwnerName_2.Text.Trim()) && !string.IsNullOrEmpty(this.txtOwnerFamily_2.Text.Trim()) && !string.IsNullOrEmpty(this.txtOwnerNationalCode_2.Text.Trim()) && !this.txtOwnerNationalCode_2.Text.Trim().Equals(person.NationalCode))
        {
            personalTypeOwner = true;
        }

        if (ajancyTypeOwner && personalTypeOwner && this.txtOwnerNationalCode_2.Text == this.txtOwnerNationalCode.Text) // Both owners are the same person
        {
            ownerPer = db.Persons.FirstOrDefault<Ajancy.Person>(p => p.NationalCode == this.txtOwnerNationalCode.Text.Trim());
            if (ownerPer == null)
            {
                ownerPer = new Ajancy.Person { NationalCode = this.txtOwnerNationalCode.Text.Trim(), SubmitDate = DateTime.Now };
                Ajancy.User ownerUser = new Ajancy.User
                {
                    UserName = this.txtOwnerNationalCode.Text.Trim()
                    ,
                    ProvinceID = person.User.ProvinceID
                    ,
                    CityID = person.User.CityID
                    ,
                    SubmitDate = DateTime.Now
                };
                ownerUser.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.CarOwner, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
                ownerPer.User = ownerUser;
                db.Persons.InsertOnSubmit(ownerPer);
            }
            else if (!ownerPer.User.UsersInRoles.Any<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.CarOwner))
            {
                ownerPer.User.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.CarOwner, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
            }

            ownerPer.FirstName = this.txtOwnerName.Text.Trim();
            ownerPer.LastName = this.txtOwnerFamily.Text.Trim();
            ownerPer.CarPlateNumbers.Add(carPlateNumber);
            ownerPer.CarPlateNumbers.Add(carPlateNumber_2);
        }
        else
        {
            if (personalTypeOwner && this.txtNationalCode.Text == this.txtOwnerNationalCode_2.Text) // Cross /
            {
                if (!person.User.UsersInRoles.Any<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.CarOwner))
                {
                    person.User.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.CarOwner, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
                }
                person.CarPlateNumbers.Add(carPlateNumber_2);
            }
            else
            {
                if (personalTypeOwner)
                {
                    ownerPer_2 = db.Persons.FirstOrDefault<Ajancy.Person>(p => p.NationalCode == this.txtOwnerNationalCode_2.Text.Trim());
                    if (ownerPer_2 == null)
                    {
                        ownerPer_2 = new Ajancy.Person { NationalCode = this.txtOwnerNationalCode_2.Text.Trim(), SubmitDate = DateTime.Now };
                        Ajancy.User ownerUser = new Ajancy.User
                        {
                            UserName = this.txtOwnerNationalCode_2.Text.Trim()
                            ,
                            ProvinceID = person.User.ProvinceID
                            ,
                            CityID = person.User.CityID
                            ,
                            SubmitDate = DateTime.Now
                        };
                        ownerUser.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.CarOwner, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
                        ownerPer_2.User = ownerUser;
                        db.Persons.InsertOnSubmit(ownerPer_2);
                    }
                    else if (!ownerPer_2.User.UsersInRoles.Any<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.CarOwner))
                    {
                        ownerPer_2.User.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.CarOwner, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
                    }

                    ownerPer_2.FirstName = this.txtOwnerName_2.Text.Trim();
                    ownerPer_2.LastName = this.txtOwnerFamily_2.Text.Trim();
                    ownerPer_2.CarPlateNumbers.Add(carPlateNumber_2);
                }
                else
                {
                    person.CarPlateNumbers.Add(carPlateNumber_2);
                    if (carPlateNumber_2.OwnerPersonID > 0 && carPlateNumber_2.OwnerPersonID != person.PersonID) // Set driver as owner again
                    {
                        carPlateNumber_2.Person = person;
                    }
                }
            }

            if (ajancyTypeOwner && this.txtNationalCode_2.Text == this.txtOwnerNationalCode.Text) // Cross \
            {
                if (!person.User.UsersInRoles.Any<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.CarOwner))
                {
                    person.User.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.CarOwner, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
                }
                person.CarPlateNumbers.Add(carPlateNumber);
            }
            else
            {
                if (ajancyTypeOwner)
                {
                    ownerPer = db.Persons.FirstOrDefault<Ajancy.Person>(p => p.NationalCode == this.txtOwnerNationalCode.Text.Trim());
                    if (ownerPer == null)
                    {
                        ownerPer = new Ajancy.Person { NationalCode = this.txtOwnerNationalCode.Text.Trim(), SubmitDate = DateTime.Now };
                        Ajancy.User ownerUser = new Ajancy.User
                        {
                            UserName = this.txtOwnerNationalCode.Text.Trim()
                            ,
                            ProvinceID = person.User.ProvinceID
                            ,
                            CityID = person.User.CityID
                            ,
                            SubmitDate = DateTime.Now
                        };
                        ownerUser.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.CarOwner, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
                        ownerPer.User = ownerUser;
                        db.Persons.InsertOnSubmit(ownerPer);
                    }
                    else if (!ownerPer.User.UsersInRoles.Any<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.CarOwner))
                    {
                        ownerPer.User.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.CarOwner, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
                    }

                    ownerPer.FirstName = this.txtOwnerName.Text.Trim();
                    ownerPer.LastName = this.txtOwnerFamily.Text.Trim();
                    ownerPer.CarPlateNumbers.Add(carPlateNumber);
                }
                else
                {
                    person.CarPlateNumbers.Add(carPlateNumber);
                    if (carPlateNumber.OwnerPersonID > 0 && carPlateNumber.OwnerPersonID != person.PersonID) // Set driver as owner again
                    {
                        carPlateNumber.Person = person;
                    }
                }
            }
        }

        #endregion

        Ajancy.FuelCardSubstitution fcsReq = new Ajancy.FuelCardSubstitution
        {
            FuelCard = fuelCard,
            UserInRoleID = Public.ActiveUserRole.UserRoleID,
            SubmitDate = DateTime.Now
        };

        db.FuelCardSubstitutions.InsertOnSubmit(fcsReq);
        db.SubmitChanges();
        fcsReq.PersonalTypeFuelCardID = fuelCard_2.FuelCardID;
        db.SubmitChanges();
        DisposeContext();
        Response.Redirect("~/Message.aspx?mode=11");
    }
コード例 #8
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            if (this.txtCarVIN.Text.ToUpper().Trim().Equals(this.txtCarVIN_2.Text.ToUpper().Trim()))
            {
                this.lblMessage.Text = "VIN خودرو بخش آژانسی با VIN خودرو بخش  شخصی نباید یکسان باشد";
                return;
            }

            if (this.txtFuelCardPAN.Text.ToUpper().Trim().Equals(this.txtFuelCardPAN_2.Text.ToUpper().Trim()))
            {
                this.lblMessage.Text = "PAN کارت سوخت بخش آژانسی با PAN کارت سوخت بخش  شخصی نباید یکسان باشد";
                return;
            }

            if (this.txtNationalCode.Text.Trim() == this.txtNationalCode_2.Text.Trim() && this.ViewState["Mode"] == null)
            {
                SelfReplacement_Save();
            }

            if (this.txtCarPlateNumber_1.Text.Trim().Equals(this.txtCarPlateNumber_1_2.Text.Trim()) &&
                this.drpCarPlateNumber.SelectedValue.Equals(this.drpCarPlateNumber_2.SelectedValue) &&
                this.txtCarPlateNumber_2.Text.Trim().Equals(this.txtCarPlateNumber_2_2.Text.Trim()) &&
                this.txtCarPlateNumber_3.Text.Trim().Equals(this.txtCarPlateNumber_3_2.Text.Trim()))
            {
                this.lblMessage.Text = "پلاک خودرو بخش آژانسی با پلاک خودرو بخش شخصی نباید یکسان باشد";
                return;
            }

            DataLoadOptions dlo = new DataLoadOptions();
            dlo.LoadWith<Ajancy.Person>(p => p.User);
            dlo.LoadWith<Ajancy.User>(u => u.UsersInRoles);
            dlo.LoadWith<Ajancy.Person>(p => p.DriverCertifications);
            dlo.LoadWith<Ajancy.DriverCertification>(dc => dc.DriverCertificationCars);
            dlo.LoadWith<Ajancy.DriverCertificationCar>(dcc => dcc.CarPlateNumber);
            dlo.LoadWith<Ajancy.CarPlateNumber>(cpn => cpn.Car);
            dlo.LoadWith<Ajancy.Car>(c => c.FuelCards);
            db = new Ajancy.Kimia_Ajancy(Public.ConnectionString);
            db.LoadOptions = dlo;

            #region AjancyType

            Ajancy.Person person = new Ajancy.Person();
            Ajancy.DriverCertification driverCertification = new Ajancy.DriverCertification();
            Ajancy.DriverCertificationCar driverCertificationCar = new Ajancy.DriverCertificationCar();
            Ajancy.CarPlateNumber carPlateNumber = new Ajancy.CarPlateNumber();
            Ajancy.PlateNumber plateNumber = new Ajancy.PlateNumber();
            Ajancy.Car car = new Ajancy.Car();
            Ajancy.FuelCard fuelCard = new Ajancy.FuelCard();

            if (this.ViewState["PersonID"] == null) // New Person
            {
                if (db.Cars.Any<Ajancy.Car>(c => c.VIN == this.txtCarVIN.Text.Trim()))
                {
                    this.lblMessage.Text = "خودرو بخش کارت سوخت آژانسی با این شماره VIN متعلق به شخص دیگری میباشد";
                    return;
                }

                if (db.FuelCards.Any<Ajancy.FuelCard>(fc => fc.PAN == this.txtFuelCardPAN.Text))
                {
                    this.lblMessage.Text = "شماره PAN کارت سوخت خودرو بخش کارت سوخت آژانسی قبلا برای خودرو دیگری ثبت شده";
                    return;
                }

                Ajancy.PlateNumber pln = db.PlateNumbers.FirstOrDefault<Ajancy.PlateNumber>(pl => pl.TwoDigits == this.txtCarPlateNumber_1.Text.Trim() &&
                                                                                                                                    pl.Alphabet == this.drpCarPlateNumber.SelectedValue &&
                                                                                                                                    pl.ThreeDigits == this.txtCarPlateNumber_2.Text.Trim() &&
                                                                                                                                    pl.RegionIdentifier == this.txtCarPlateNumber_3.Text.Trim());
                if (pln != null)
                {
                    this.lblMessage.Text = "شماره پلاک وارد شده در  بخش کارت سوخت آژانسی متعلق به شخص دیگری میباشد";
                    return;
                }

                Ajancy.User user = new Ajancy.User();
                user.UserName = this.txtNationalCode.Text.Trim();
                user.ProvinceID = Public.ToByte(this.drpProvince.SelectedValue);
                user.CityID = Public.ToShort(this.drpCity.SelectedValue);
                user.SubmitDate = DateTime.Now;
                user.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.TaxiDriver, MembershipDate = DateTime.Now });
                person.User = user;
                person.NationalCode = this.txtNationalCode.Text.Trim();
                person.SubmitDate = DateTime.Now;

                driverCertification = new Ajancy.DriverCertification
                {
                    CertificationType = (byte)Public.AjancyType.TaxiAjancy,
                    SubmitDate = DateTime.Now
                };
                carPlateNumber = new Ajancy.CarPlateNumber { Car = car, PlateNumber = plateNumber };
                driverCertificationCar = new Ajancy.DriverCertificationCar { CarPlateNumber = carPlateNumber, SubmitDate = DateTime.Now };
                driverCertificationCar.AjancyDrivers.Add(new Ajancy.AjancyDriver { AjancyID = Public.ToInt(this.drpAjancies.SelectedValue), MembershipDate = DateTime.Now });
                driverCertification.DriverCertificationCars.Add(driverCertificationCar);
                person.DriverCertifications.Add(driverCertification);
                fuelCard.SubmitDate = DateTime.Now;
                car.FuelCards.Add(fuelCard);
                db.Persons.InsertOnSubmit(person);
            }
            else // Person Exists
            {
                person = db.Persons.FirstOrDefault<Ajancy.Person>(p => p.PersonID == Public.ToInt(this.ViewState["PersonID"]));

                if (person.User.UsersInRoles.Any<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.TaxiDriver))  // Person is a driver
                {
                    driverCertification = person.DriverCertifications.First<Ajancy.DriverCertification>(dc => dc.CertificationType == (byte)Public.AjancyType.TaxiAjancy);
                    driverCertificationCar = driverCertification.DriverCertificationCars.Last<Ajancy.DriverCertificationCar>(dcc => dcc.LockOutDate == null);
                    carPlateNumber = driverCertificationCar.CarPlateNumber;
                    plateNumber = carPlateNumber.PlateNumber;
                    car = carPlateNumber.Car;
                    fuelCard = car.FuelCards.Last<Ajancy.FuelCard>();
                    fuelCard.DiscardDate = null;

                    if (db.Cars.Any<Ajancy.Car>(c => c.VIN == this.txtCarVIN.Text.Trim() && c.CarID != car.CarID))
                    {
                        this.lblMessage.Text = "خودرو بخش کارت سوخت آژانسی با این شماره VIN متعلق به شخص دیگری میباشد";
                        return;
                    }

                    if (db.FuelCards.Any<Ajancy.FuelCard>(fc => fc.PAN == this.txtFuelCardPAN.Text && fc.FuelCardID != fuelCard.FuelCardID))
                    {
                        this.lblMessage.Text = "شماره PAN کارت سوخت خودرو بخش کارت سوخت آژانسی قبلا برای خودرو دیگری ثبت شده";
                        return;
                    }

                    Ajancy.PlateNumber pln = db.PlateNumbers.FirstOrDefault<Ajancy.PlateNumber>(pl => pl.TwoDigits == this.txtCarPlateNumber_1.Text.Trim() &&
                                                                                                                                        pl.Alphabet == this.drpCarPlateNumber.SelectedValue &&
                                                                                                                                        pl.ThreeDigits == this.txtCarPlateNumber_2.Text.Trim() &&
                                                                                                                                        pl.RegionIdentifier == this.txtCarPlateNumber_3.Text.Trim() &&
                                                                                                                                        pl.PlateNumberID != carPlateNumber.PlateNumber.PlateNumberID);
                    if (pln != null)
                    {
                        this.lblMessage.Text = "شماره پلاک وارد شده در  بخش کارت سوخت آژانسی متعلق به شخص دیگری میباشد";
                        return;
                    }

                    Ajancy.AjancyDriver ajancyDriver = driverCertificationCar.AjancyDrivers.Last<Ajancy.AjancyDriver>(jd => jd.LockOutDate == null);
                    int ajancyId = Public.ToInt(this.drpAjancies.SelectedValue);
                    if (ajancyDriver.AjancyID != ajancyId) // Driver has moved to one other ajancy
                    {
                        ajancyDriver.LockOutDate = DateTime.Now;
                        driverCertificationCar.AjancyDrivers.Add(new Ajancy.AjancyDriver { AjancyID = ajancyId, MembershipDate = DateTime.Now });
                    }

                    //if (Public.ActiveUserRole.RoleID == (short)Public.Role.ProvinceManager)
                    //{
                    //    person.User.CityID = Public.ToShort(this.drpCity.SelectedValue);
                    //}
                }
                else // Person is not driver
                {
                    if (db.Cars.Any<Ajancy.Car>(c => c.VIN == this.txtCarVIN.Text.Trim()))
                    {
                        this.lblMessage.Text = "خودرو بخش کارت سوخت آژانسی با این شماره VIN متعلق به شخص دیگری میباشد";
                        return;
                    }

                    if (db.FuelCards.Any<Ajancy.FuelCard>(fc => fc.PAN == this.txtFuelCardPAN.Text))
                    {
                        this.lblMessage.Text = "شماره PAN کارت سوخت خودرو بخش کارت سوخت آژانسی قبلا برای خودرو دیگری ثبت شده";
                        return;
                    }

                    Ajancy.PlateNumber pln = db.PlateNumbers.FirstOrDefault<Ajancy.PlateNumber>(pl => pl.TwoDigits == this.txtCarPlateNumber_1.Text.Trim() &&
                                                                                                                                        pl.Alphabet == this.drpCarPlateNumber.SelectedValue &&
                                                                                                                                        pl.ThreeDigits == this.txtCarPlateNumber_2.Text.Trim() &&
                                                                                                                                        pl.RegionIdentifier == this.txtCarPlateNumber_3.Text.Trim());
                    if (pln != null)
                    {
                        this.lblMessage.Text = "شماره پلاک وارد شده در  بخش کارت سوخت آژانسی متعلق به شخص دیگری میباشد";
                        return;
                    }

                    person.User.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.TaxiDriver, MembershipDate = DateTime.Now });
                    driverCertification = new Ajancy.DriverCertification
                    {
                        CertificationType = (byte)Public.AjancyType.TaxiAjancy,
                        SubmitDate = DateTime.Now
                    };
                    carPlateNumber = new Ajancy.CarPlateNumber { Car = car, PlateNumber = plateNumber };
                    driverCertificationCar = new Ajancy.DriverCertificationCar { CarPlateNumber = carPlateNumber, SubmitDate = DateTime.Now };
                    driverCertificationCar.AjancyDrivers.Add(new Ajancy.AjancyDriver { AjancyID = Public.ToInt(this.drpAjancies.SelectedValue), DriverCertificationCar = driverCertificationCar, MembershipDate = DateTime.Now });
                    driverCertification.DriverCertificationCars.Add(driverCertificationCar);
                    person.DriverCertifications.Add(driverCertification);
                    fuelCard.SubmitDate = DateTime.Now;
                    car.FuelCards.Add(fuelCard);
                }

                switch ((Public.Role)Public.ActiveUserRole.RoleID)
                {
                    case Public.Role.ProvinceManager:
                        person.User.CityID = Public.ToShort(this.drpCity.SelectedValue);
                        break;

                    case Public.Role.Admin:
                        person.User.ProvinceID = Public.ToByte(this.drpProvince.SelectedValue);
                        person.User.CityID = Public.ToShort(this.drpCity.SelectedValue);
                        break;
                }
            }

            // --------------- setting values

            person.FirstName = this.txtFirstName.Text.Trim();
            person.LastName = this.txtLastName.Text.Trim();

            plateNumber.TwoDigits = this.txtCarPlateNumber_1.Text.Trim();
            plateNumber.Alphabet = this.drpCarPlateNumber.SelectedValue;
            plateNumber.ThreeDigits = this.txtCarPlateNumber_2.Text.Trim();
            plateNumber.RegionIdentifier = this.txtCarPlateNumber_3.Text.Trim();

            car.CarTypeID = Public.ToShort(this.drpCarType.SelectedValue);
            car.FuelType = Public.ToByte(this.drpFuelType.SelectedValue);
            car.Model = this.txtCarModel.Text;

            fuelCard.CardType = (byte)Public.FuelCardType.Ajancy;
            fuelCard.PAN = this.txtFuelCardPAN.Text.Trim();

            car.VIN = this.txtCarVIN.Text.Trim().ToUpper();

            #endregion

            #region PersonalType

            Ajancy.Person person_2 = new Ajancy.Person();
            Ajancy.DriverCertification driverCertification_2 = new Ajancy.DriverCertification();
            Ajancy.DriverCertificationCar driverCertificationCar_2 = new Ajancy.DriverCertificationCar();
            Ajancy.CarPlateNumber carPlateNumber_2 = new Ajancy.CarPlateNumber();
            Ajancy.PlateNumber plateNumber_2 = new Ajancy.PlateNumber();
            Ajancy.Car car_2 = new Ajancy.Car();
            Ajancy.FuelCard fuelCard_2 = new Ajancy.FuelCard();

            if (this.ViewState["PersonID_2"] == null) // New Person
            {
                if (db.Cars.Any<Ajancy.Car>(c => c.VIN == this.txtCarVIN_2.Text.Trim()))
                {
                    this.lblMessage.Text = "خودرو بخش کارت سوخت شخصی با این شماره VIN متعلق به شخص دیگری میباشد";
                    return;
                }

                if (db.FuelCards.Any<Ajancy.FuelCard>(fc => fc.PAN == this.txtFuelCardPAN_2.Text))
                {
                    this.lblMessage.Text = "شماره PAN کارت سوخت خودرو بخش کارت سوخت شخصی قبلا برای خودرو دیگری ثبت شده";
                    return;
                }

                Ajancy.PlateNumber pnl = db.PlateNumbers.FirstOrDefault<Ajancy.PlateNumber>(pl => pl.TwoDigits == this.txtCarPlateNumber_1_2.Text.Trim() &&
                                                                                                                                   pl.Alphabet == this.drpCarPlateNumber_2.SelectedValue &&
                                                                                                                                   pl.ThreeDigits == this.txtCarPlateNumber_2_2.Text.Trim() &&
                                                                                                                                   pl.RegionIdentifier == this.txtCarPlateNumber_3_2.Text.Trim());
                if (pnl != null)
                {
                    this.lblMessage.Text = "شماره پلاک وارد شده در  بخش کارت سوخت شخصی متعلق به شخص دیگری میباشد";
                    return;
                }

                Ajancy.User user = new Ajancy.User();
                user.UserName = this.txtNationalCode_2.Text.Trim();
                user.ProvinceID = Public.ToByte(this.drpProvince_2.SelectedValue);
                user.CityID = Public.ToShort(this.drpCity_2.SelectedValue);
                user.SubmitDate = DateTime.Now;
                user.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.TaxiDriver, MembershipDate = DateTime.Now });
                person_2.User = user;
                person_2.NationalCode = this.txtNationalCode_2.Text.Trim();
                person_2.SubmitDate = DateTime.Now;

                driverCertification_2 = new Ajancy.DriverCertification
                {
                    CertificationType = (byte)Public.AjancyType.TaxiAjancy,
                    SubmitDate = DateTime.Now
                };
                carPlateNumber_2 = new Ajancy.CarPlateNumber { Car = car_2, PlateNumber = plateNumber_2 };
                driverCertificationCar_2 = new Ajancy.DriverCertificationCar { CarPlateNumber = carPlateNumber_2, SubmitDate = DateTime.Now };
                driverCertificationCar_2.AjancyDrivers.Add(new Ajancy.AjancyDriver { AjancyID = Public.ToInt(this.drpAjancies_2.SelectedValue), MembershipDate = DateTime.Now });
                driverCertification_2.DriverCertificationCars.Add(driverCertificationCar_2);
                person_2.DriverCertifications.Add(driverCertification_2);
                fuelCard_2.SubmitDate = DateTime.Now;
                car_2.FuelCards.Add(fuelCard_2);
                db.Persons.InsertOnSubmit(person_2);
            }
            else // Person Exists
            {
                person_2 = db.Persons.FirstOrDefault<Ajancy.Person>(p => p.PersonID == Public.ToInt(this.ViewState["PersonID_2"]));
                if (person_2.User.UsersInRoles.Any<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.TaxiDriver))  // Person is a driver
                {
                    driverCertification_2 = person_2.DriverCertifications.First<Ajancy.DriverCertification>(dc => dc.CertificationType == (byte)Public.AjancyType.TaxiAjancy);
                    driverCertificationCar_2 = driverCertification_2.DriverCertificationCars.Last<Ajancy.DriverCertificationCar>(dcc => dcc.LockOutDate == null);
                    carPlateNumber_2 = driverCertificationCar_2.CarPlateNumber;
                    plateNumber_2 = carPlateNumber_2.PlateNumber;
                    car_2 = carPlateNumber_2.Car;
                    fuelCard_2 = car_2.FuelCards.Last<Ajancy.FuelCard>();
                    fuelCard_2.DiscardDate = null;

                    if (db.Cars.Any<Ajancy.Car>(c => c.VIN == this.txtCarVIN_2.Text.Trim() && c.CarID != car_2.CarID))
                    {
                        this.lblMessage.Text = "خودرو بخش کارت سوخت شخصی با این شماره VIN متعلق به شخص دیگری میباشد";
                        return;
                    }

                    if (db.FuelCards.Any<Ajancy.FuelCard>(fc => fc.PAN == this.txtFuelCardPAN_2.Text && fc.FuelCardID != fuelCard_2.FuelCardID))
                    {
                        this.lblMessage.Text = "شماره PAN کارت سوخت خودرو بخش کارت سوخت شخصی قبلا برای خودرو دیگری ثبت شده";
                        return;
                    }

                    Ajancy.PlateNumber pnl = db.PlateNumbers.FirstOrDefault<Ajancy.PlateNumber>(pl => pl.TwoDigits == this.txtCarPlateNumber_1_2.Text.Trim() &&
                                                                                                                                       pl.Alphabet == this.drpCarPlateNumber_2.SelectedValue &&
                                                                                                                                       pl.ThreeDigits == this.txtCarPlateNumber_2_2.Text.Trim() &&
                                                                                                                                       pl.RegionIdentifier == this.txtCarPlateNumber_3_2.Text.Trim() &&
                                                                                                                                       pl.PlateNumberID != carPlateNumber_2.PlateNumber.PlateNumberID);
                    if (pnl != null)
                    {
                        this.lblMessage.Text = "شماره پلاک وارد شده در  بخش کارت سوخت شخصی متعلق به شخص دیگری میباشد";
                        return;
                    }

                    Ajancy.AjancyDriver ajancyDriver_2 = driverCertificationCar_2.AjancyDrivers.Last<Ajancy.AjancyDriver>(jd => jd.LockOutDate == null);
                    int ajancyId_2 = Public.ToInt(this.drpAjancies_2.SelectedValue);
                    if (ajancyDriver_2.AjancyID != ajancyId_2) // Driver has moved to one other ajancy
                    {
                        ajancyDriver_2.LockOutDate = DateTime.Now;
                        driverCertificationCar_2.AjancyDrivers.Add(new Ajancy.AjancyDriver { AjancyID = ajancyId_2, MembershipDate = DateTime.Now });
                    }

                    //if (Public.ActiveUserRole.RoleID == (short)Public.Role.ProvinceManager)
                    //{
                    //    person_2.User.CityID = Public.ToShort(this.drpCity_2.SelectedValue);
                    //}
                }
                else // Person is not driver
                {
                    if (db.Cars.Any<Ajancy.Car>(c => c.VIN == this.txtCarVIN_2.Text.Trim()))
                    {
                        this.lblMessage.Text = "خودرو بخش کارت سوخت شخصی با این شماره VIN متعلق به شخص دیگری میباشد";
                        return;
                    }

                    if (db.FuelCards.Any<Ajancy.FuelCard>(fc => fc.PAN == this.txtFuelCardPAN_2.Text))
                    {
                        this.lblMessage.Text = "شماره PAN کارت سوخت خودرو بخش کارت سوخت شخصی قبلا برای خودرو دیگری ثبت شده";
                        return;
                    }

                    Ajancy.PlateNumber pnl = db.PlateNumbers.FirstOrDefault<Ajancy.PlateNumber>(pl => pl.TwoDigits == this.txtCarPlateNumber_1_2.Text.Trim() &&
                                                                                                                                       pl.Alphabet == this.drpCarPlateNumber_2.SelectedValue &&
                                                                                                                                       pl.ThreeDigits == this.txtCarPlateNumber_2_2.Text.Trim() &&
                                                                                                                                       pl.RegionIdentifier == this.txtCarPlateNumber_3_2.Text.Trim());
                    if (pnl != null)
                    {
                        this.lblMessage.Text = "شماره پلاک وارد شده در  بخش کارت سوخت شخصی متعلق به شخص دیگری میباشد";
                        return;
                    }

                    person_2.User.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.TaxiDriver, MembershipDate = DateTime.Now });
                    driverCertification_2 = new Ajancy.DriverCertification
                    {
                        CertificationType = (byte)Public.AjancyType.TaxiAjancy,
                        SubmitDate = DateTime.Now
                    };
                    carPlateNumber_2 = new Ajancy.CarPlateNumber { Car = car_2, PlateNumber = plateNumber_2 };
                    driverCertificationCar_2 = new Ajancy.DriverCertificationCar { CarPlateNumber = carPlateNumber_2, SubmitDate = DateTime.Now };
                    driverCertificationCar_2.AjancyDrivers.Add(new Ajancy.AjancyDriver { AjancyID = Public.ToInt(this.drpAjancies_2.SelectedValue), DriverCertificationCar = driverCertificationCar_2, MembershipDate = DateTime.Now });
                    driverCertification_2.DriverCertificationCars.Add(driverCertificationCar_2);
                    person_2.DriverCertifications.Add(driverCertification_2);
                    fuelCard_2.SubmitDate = DateTime.Now;
                    car_2.FuelCards.Add(fuelCard_2);
                }

                switch ((Public.Role)Public.ActiveUserRole.RoleID)
                {
                    case Public.Role.ProvinceManager:
                        person_2.User.CityID = Public.ToShort(this.drpCity_2.SelectedValue);
                        break;

                    case Public.Role.Admin:
                        person_2.User.ProvinceID = Public.ToByte(this.drpProvince_2.SelectedValue);
                        person_2.User.CityID = Public.ToShort(this.drpCity_2.SelectedValue);
                        break;
                }
            }

            // --------------- setting values

            person_2.FirstName = this.txtFirstName_2.Text.Trim();
            person_2.LastName = this.txtLastName_2.Text.Trim();

            plateNumber_2.TwoDigits = this.txtCarPlateNumber_1_2.Text.Trim();
            plateNumber_2.Alphabet = this.drpCarPlateNumber_2.SelectedValue;
            plateNumber_2.ThreeDigits = this.txtCarPlateNumber_2_2.Text.Trim();
            plateNumber_2.RegionIdentifier = this.txtCarPlateNumber_3_2.Text.Trim();

            car_2.CarTypeID = Public.ToShort(this.drpCarType_2.SelectedValue);
            car_2.FuelType = Public.ToByte(this.drpFuelType_2.SelectedValue);
            car_2.Model = this.txtCarModel_2.Text;

            fuelCard_2.CardType = (byte)Public.FuelCardType.Ajancy;
            fuelCard_2.PAN = this.txtFuelCardPAN_2.Text.Trim();

            car_2.VIN = this.txtCarVIN_2.Text.Trim().ToUpper();

            #endregion

            #region Owners

            bool ajancyTypeOwner = false;
            bool personalTypeOwner = false;
            Ajancy.Person ownerPer = null;
            Ajancy.Person ownerPer_2 = null;

            if (!string.IsNullOrEmpty(this.txtOwnerName.Text.Trim()) && !string.IsNullOrEmpty(this.txtOwnerFamily.Text.Trim()) && !string.IsNullOrEmpty(this.txtOwnerNationalCode.Text.Trim()) && !this.txtOwnerNationalCode.Text.Trim().Equals(person.NationalCode))
            {
                ajancyTypeOwner = true;
            }
            if (!string.IsNullOrEmpty(this.txtOwnerName_2.Text.Trim()) && !string.IsNullOrEmpty(this.txtOwnerFamily_2.Text.Trim()) && !string.IsNullOrEmpty(this.txtOwnerNationalCode_2.Text.Trim()) && !this.txtOwnerNationalCode_2.Text.Trim().Equals(person_2.NationalCode))
            {
                personalTypeOwner = true;
            }

            if (ajancyTypeOwner && personalTypeOwner && this.txtOwnerNationalCode_2.Text == this.txtOwnerNationalCode.Text) // Both owners are the same person
            {
                ownerPer = db.Persons.FirstOrDefault<Ajancy.Person>(p => p.NationalCode == this.txtOwnerNationalCode.Text.Trim());
                if (ownerPer == null)
                {
                    ownerPer = new Ajancy.Person { NationalCode = this.txtOwnerNationalCode.Text.Trim(), SubmitDate = DateTime.Now };
                    Ajancy.User ownerUser = new Ajancy.User
                    {
                        UserName = this.txtOwnerNationalCode.Text.Trim()
                        ,
                        ProvinceID = person.User.ProvinceID
                        ,
                        CityID = person.User.CityID
                        ,
                        SubmitDate = DateTime.Now
                    };
                    ownerUser.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.CarOwner, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
                    ownerPer.User = ownerUser;
                    db.Persons.InsertOnSubmit(ownerPer);
                }
                else if (!ownerPer.User.UsersInRoles.Any<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.CarOwner))
                {
                    ownerPer.User.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.CarOwner, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
                }

                ownerPer.FirstName = this.txtOwnerName.Text.Trim();
                ownerPer.LastName = this.txtOwnerFamily.Text.Trim();
                ownerPer.CarPlateNumbers.Add(carPlateNumber);
                ownerPer.CarPlateNumbers.Add(carPlateNumber_2);
            }
            else
            {
                if (personalTypeOwner && this.txtNationalCode.Text == this.txtOwnerNationalCode_2.Text) // Cross /
                {
                    if (!person.User.UsersInRoles.Any<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.CarOwner))
                    {
                        person.User.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.CarOwner, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
                    }
                    person.CarPlateNumbers.Add(carPlateNumber_2);
                }
                else
                {
                    if (personalTypeOwner)
                    {
                        ownerPer_2 = db.Persons.FirstOrDefault<Ajancy.Person>(p => p.NationalCode == this.txtOwnerNationalCode_2.Text.Trim());
                        if (ownerPer_2 == null)
                        {
                            ownerPer_2 = new Ajancy.Person { NationalCode = this.txtOwnerNationalCode_2.Text.Trim(), SubmitDate = DateTime.Now };
                            Ajancy.User ownerUser = new Ajancy.User
                            {
                                UserName = this.txtOwnerNationalCode_2.Text.Trim()
                                ,
                                ProvinceID = person_2.User.ProvinceID
                                ,
                                CityID = person_2.User.CityID
                                ,
                                SubmitDate = DateTime.Now
                            };
                            ownerUser.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.CarOwner, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
                            ownerPer_2.User = ownerUser;
                            db.Persons.InsertOnSubmit(ownerPer_2);
                        }
                        else if (!ownerPer_2.User.UsersInRoles.Any<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.CarOwner))
                        {
                            ownerPer_2.User.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.CarOwner, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
                        }

                        ownerPer_2.FirstName = this.txtOwnerName_2.Text.Trim();
                        ownerPer_2.LastName = this.txtOwnerFamily_2.Text.Trim();
                        ownerPer_2.CarPlateNumbers.Add(carPlateNumber_2);
                    }
                    else
                    {
                        person_2.CarPlateNumbers.Add(carPlateNumber_2);
                        if (carPlateNumber_2.OwnerPersonID > 0 && carPlateNumber_2.OwnerPersonID != person_2.PersonID) // Set driver as owner again
                        {
                            carPlateNumber_2.Person = person_2;
                        }
                    }
                }

                if (ajancyTypeOwner && this.txtNationalCode_2.Text == this.txtOwnerNationalCode.Text) // Cross \
                {
                    if (!person_2.User.UsersInRoles.Any<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.CarOwner))
                    {
                        person_2.User.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.CarOwner, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
                    }
                    person_2.CarPlateNumbers.Add(carPlateNumber);
                }
                else
                {
                    if (ajancyTypeOwner)
                    {
                        ownerPer = db.Persons.FirstOrDefault<Ajancy.Person>(p => p.NationalCode == this.txtOwnerNationalCode.Text.Trim());
                        if (ownerPer == null)
                        {
                            ownerPer = new Ajancy.Person { NationalCode = this.txtOwnerNationalCode.Text.Trim(), SubmitDate = DateTime.Now };
                            Ajancy.User ownerUser = new Ajancy.User
                            {
                                UserName = this.txtOwnerNationalCode.Text.Trim()
                                ,
                                ProvinceID = person.User.ProvinceID
                                ,
                                CityID = person.User.CityID
                                ,
                                SubmitDate = DateTime.Now
                            };
                            ownerUser.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.CarOwner, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
                            ownerPer.User = ownerUser;
                            db.Persons.InsertOnSubmit(ownerPer);
                        }
                        else if (!ownerPer.User.UsersInRoles.Any<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.CarOwner))
                        {
                            ownerPer.User.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.CarOwner, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now });
                        }

                        ownerPer.FirstName = this.txtOwnerName.Text.Trim();
                        ownerPer.LastName = this.txtOwnerFamily.Text.Trim();
                        ownerPer.CarPlateNumbers.Add(carPlateNumber);
                    }
                    else
                    {
                        person.CarPlateNumbers.Add(carPlateNumber);
                        if (carPlateNumber.OwnerPersonID > 0 && carPlateNumber.OwnerPersonID != person.PersonID) // Set driver as owner again
                        {
                            carPlateNumber.Person = person;
                        }
                    }
                }
            }

            #endregion

            if (this.ViewState["Mode"] == null) // Add mode
            {
                Ajancy.FuelCardSubstitution formerReq = null;
                if (fuelCard.FuelCardID > 0)
                {
                    formerReq = db.FuelCardSubstitutions.FirstOrDefault<Ajancy.FuelCardSubstitution>(fcs => (fcs.AjancyTypeFuelCardID == fuelCard.FuelCardID || fcs.PersonalTypeFuelCardID.GetValueOrDefault() == fuelCard.FuelCardID));
                    if (formerReq != null)
                    {
                        this.lblMessage.Text = "برای کارت سوخت بخش آژانسی قبلا درخواست ابطال یا جایگزین ثبت شده است";
                        return;
                    }
                }
                if (fuelCard_2.FuelCardID > 0)
                {
                    formerReq = db.FuelCardSubstitutions.FirstOrDefault<Ajancy.FuelCardSubstitution>(fcs => (fcs.AjancyTypeFuelCardID == fuelCard_2.FuelCardID || fcs.PersonalTypeFuelCardID.GetValueOrDefault() == fuelCard_2.FuelCardID));
                    if (formerReq != null)
                    {
                        this.lblMessage.Text = "برای کارت سوخت بخش شخصی قبلا درخواست ابطال یا جایگزین ثبت شده است";
                        return;
                    }
                }

                Ajancy.FuelCardSubstitution fcsReq = new Ajancy.FuelCardSubstitution
                {
                    FuelCard = fuelCard,
                    UserInRoleID = Public.ActiveUserRole.UserRoleID,
                    SubmitDate = DateTime.Now
                };

                db.FuelCardSubstitutions.InsertOnSubmit(fcsReq);
                db.SubmitChanges();
                fcsReq.PersonalTypeFuelCardID = fuelCard_2.FuelCardID;
            }
            else // Edit mode
            {
                db.FuelCardSubstitutions.FirstOrDefault<Ajancy.FuelCardSubstitution>(fcs => (fcs.AjancyTypeFuelCardID == fuelCard.FuelCardID && fcs.PersonalTypeFuelCardID.GetValueOrDefault() == fuelCard_2.FuelCardID)).SubmitDate = DateTime.Now;
            }

            db.SubmitChanges();
            DisposeContext();
            Response.Redirect("~/Message.aspx?mode=11");
        }
    }