Beispiel #1
0
        public static void SyncCitizens()
        {
            List <tblCitizen> lstCitizens = RestHelper.GetCitizens();

            using (EGovernmentEntities db = new EGovernmentEntities())
            {
                foreach (tblCitizen citizen in lstCitizens)
                {
                    if (db.tblCitizens.Where(x => x.NationalNumber == citizen.NationalNumber).ToList().Count == 0)
                    {
                        db.tblCitizens.AddObject(citizen);
                        db.SaveChanges();
                    }
                    else
                    {
                        tblCitizen _tblCitizen = db.tblCitizens.Where(x => x.NationalNumber == citizen.NationalNumber).FirstOrDefault();
                        _tblCitizen.FirstName            = citizen.FirstName;
                        _tblCitizen.LastName             = citizen.LastName;
                        _tblCitizen.FatherNationalNumber = citizen.FatherNationalNumber;
                        _tblCitizen.MotherNationalNumber = citizen.MotherNationalNumber;
                        _tblCitizen.Birthday             = citizen.Birthday;
                        _tblCitizen.BirthPlace           = citizen.BirthPlace;
                        _tblCitizen.KiedPlace            = citizen.KiedPlace;
                        _tblCitizen.KiedNumber           = citizen.KiedNumber;
                        _tblCitizen.Gender = citizen.Gender;

                        db.SaveChanges();
                    }
                }
            }
        }
Beispiel #2
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                using (EGovernmentEntities db = new EGovernmentEntities())
                {
                    tblCivilRegistry civilregistry = null;

                    EditPage = (btnAdd.Text == "حفظ التعديلات");

                    if (!EditPage)
                    {
                        civilregistry = new tblCivilRegistry();
                    }
                    else
                    {
                        int CivilRegistryid = int.Parse(txtCivilRegistry.Text);
                        civilregistry = db.tblCivilRegistries.Where(x => x.Id == CivilRegistryid).FirstOrDefault();
                    }
                    civilregistry.Name           = txtName.Text;
                    civilregistry.Area           = txtArea.Text;
                    civilregistry.CivilAffairsID = Int32.Parse(ddlCivilAffairs.SelectedValue);

                    if (!EditPage)
                    {
                        db.tblCivilRegistries.AddObject(civilregistry);
                    }

                    db.SaveChanges();
                }
                Response.Redirect("/Finish");
            }
        }
Beispiel #3
0
        public static void EditSocialNumber(string NationalNumber, SocialStatus _SocialStatus)
        {
            using (EGovernmentEntities db = new EGovernmentEntities())
            {
                tblCitizen citizen = db.tblCitizens.Where(x => x.NationalNumber == NationalNumber).FirstOrDefault();

                switch (_SocialStatus)
                {
                case SocialStatus._Single:
                    citizen.SocialStatus = "1";
                    break;

                case SocialStatus.Marriad:
                    citizen.SocialStatus = "2";
                    break;

                case SocialStatus.Widow:
                    citizen.SocialStatus = "3";
                    break;

                case SocialStatus.Divorced:
                    citizen.SocialStatus = "4";
                    break;
                }
                db.SaveChanges();
            }
        }
        protected void btnDisActive_Click(object sender, EventArgs e)
        {
            int id = int.Parse(ddlAccounts.SelectedValue);

            using (EGovernmentEntities db = new EGovernmentEntities())
            {
                tblCitizenRole CitizenRole = db.tblCitizenRoles.Where(y => y.UserId == id).FirstOrDefault();
                CitizenRole.Taken = false;
                db.SaveChanges();
                btnActive.Visible    = true;
                btnDisActive.Visible = false;
            }
        }
Beispiel #5
0
        public static void UnController(List <tblEmployee> lstEmployees)
        {
            using (EGovernmentEntities db = new EGovernmentEntities())
            {
                foreach (tblEmployee emp in lstEmployees)
                {
                    tblEmployeesCivilRegistry employeesCivilRegistry = db.tblEmployeesCivilRegistries.Where(x => x.EmployeNationalNumber == emp.NationalNumber).Where(y => y.E_date == null).FirstOrDefault();

                    employeesCivilRegistry.IsController = false;
                }
                db.SaveChanges();
            }
        }
Beispiel #6
0
        public static void AddBalance(string NationalNumber, int Balance)
        {
            using (EGovernmentEntities db = new EGovernmentEntities())
            {
                tblBalance balance = new tblBalance();
                balance.NationalNumber = NationalNumber;
                balance.Balance        = Balance;

                db.tblBalances.AddObject(balance);

                db.SaveChanges();
            }
        }
Beispiel #7
0
 public static void AddNewCitizenUser(int UserId, string NationalNum, int RoleId)
 {
     using (EGovernmentEntities db = new EGovernmentEntities())
     {
         tblCitizenRole citizenRole = new tblCitizenRole();
         citizenRole.UserId         = UserId;
         citizenRole.NationalNumber = NationalNum;
         citizenRole.RoleId         = RoleId;
         citizenRole.Taken          = false;
         db.tblCitizenRoles.AddObject(citizenRole);
         db.SaveChanges();
     }
 }
Beispiel #8
0
        public static void Pay(string NationalNumber, int Penalty)
        {
            using (EGovernmentEntities db = new EGovernmentEntities())
            {
                tblBalance balance = db.tblBalances.Where(x => x.NationalNumber == NationalNumber).FirstOrDefault();

                if (balance != null)
                {
                    balance.Balance = balance.Balance - Penalty;
                }

                db.SaveChanges();
            }
        }
        protected void CreateUser_Click(object sender, EventArgs e)
        {
            using (EGovernmentEntities db = new EGovernmentEntities())
            {
                tblUser user = new tblUser();

                if (!Helper.CheckIsCitizen(txtNationalNumber.Text))
                {
                    ErrorMessage.Text = "الرقم الوطني غير موجود في قاعدة البيانات";
                    return;
                }
                if (Helper.CheckUserName(txtUserName.Text))
                {
                    ErrorMessage.Text = "اسم المستخدم مستخدم مسبقاً";
                    return;
                }

                bool IsEmployee = Helper.IsEmployee(txtNationalNumber.Text);

                if (IsEmployee)
                {
                    user.EmployeeId = txtNationalNumber.Text;
                }


                user.Username = txtUserName.Text;
                user.Password = Password.Text;
                db.tblUsers.AddObject(user);
                db.SaveChanges();

                if (!IsEmployee)
                {
                    Helper.AddNewCitizenUser(user.Id, txtNationalNumber.Text, 2);
                }

                Response.Redirect("/Finish");
            }
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            using (EGovernmentEntities db = new EGovernmentEntities())
            {
                EditPage = (btnAdd.Text == "حفظ التعديلات");
                #region Checks
                if (!EditPage && db.tblCitizens.Where(x => x.NationalNumber == NationalNumber.Value).ToList().Count > 0)
                {
                    var cit = db.tblCitizens.Where(x => x.NationalNumber == NationalNumber.Value).FirstOrDefault();
                    lblErrorMSG.Visible = true;
                    lblErrorMSG1.Text   = "الرقم الوطني المدخل موجود مسبقاً في قاعدة البيانات" + Environment.NewLine + "ويعود للمواطن " + string.Format("{0} {1} {2}", cit.FirstName, Helper.GetCitizen(cit.FatherNationalNumber).FirstName, cit.LastName);
                    return;
                }
                #endregion

                tblCitizen citizen;
                string     NationalNum = string.Empty;

                if (EditPage)
                {
                    citizen = db.tblCitizens.Where(x => x.NationalNumber == NationalNumber.Value).FirstOrDefault();
                }
                else
                {
                    citizen = new tblCitizen();
                }

                citizen.Birthday             = Birthday.Value;
                citizen.BirthPlace           = BirthPlace.Value;
                citizen.FatherNationalNumber = FatherNationalNumber.Value; //
                citizen.FirstName            = FirstName.Value;
                citizen.Gender               = male.Checked ? "1" : "0";
                citizen.KiedPlace            = KiedPlace.Value;
                citizen.KiedNumber           = KiedNumber.Value;
                citizen.Religion             = Religion.Value;
                citizen.LastName             = LastName.Value;
                citizen.MotherNationalNumber = MotherNationalNumber.Value;//
                citizen.NationalNumber       = NationalNumber.Value;
                citizen.SocialStatus         = ss1.Checked ? "1" : ss2.Checked ? "2" : ss3.Checked ? "3" : "4";

                if (!EditPage)
                {
                    db.tblCitizens.AddObject(citizen);
                    RestHelper.AddCitizen(citizen);
                }
                else
                {
                    RestHelper.EditCitizen(citizen);
                }

                db.SaveChanges();


                if (!Helper.HasBalance(NationalNumber.Value))
                {
                    Helper.AddBalance(NationalNumber.Value, 50000);
                }


                if (Directory.Exists(Server.MapPath("~/Images/" + NationalNumber + "/")))
                {
                    Directory.Delete(Server.MapPath("~/Images/" + NationalNumber + "/"));
                }

                if (!string.IsNullOrEmpty(FileUploadControl.FileName))
                {
                    string filename = "Profile" + Path.GetExtension(FileUploadControl.FileName);

                    if (!Directory.Exists(Server.MapPath("~/Images/" + citizen.NationalNumber)))
                    {
                        Directory.CreateDirectory(Server.MapPath("~/Images/" + citizen.NationalNumber));
                    }

                    FileUploadControl.SaveAs(Server.MapPath("~/Images/" + citizen.NationalNumber + "/") + filename);
                }

                Session["CitizenInfo"] = null;
                Response.Redirect("/Finish");
            }
        }
Beispiel #11
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            using (EGovernmentEntities db = new EGovernmentEntities())
            {
                tblRole role = null;

                EditPage = (btnAdd.Text == "حفظ التعديلات");

                if (!EditPage)
                {
                    role = new tblRole();
                }
                else
                {
                    int RoleId = int.Parse(txtRoleId.Text);
                    role            = db.tblRoles.Where(x => x.Id == RoleId).FirstOrDefault();
                    role.AddCitizen = role.AddCivilRegister = role.AddEmployee = role.BirthDoc = role.BirthOut = role.DeathDoc = role.DeathOut = role.DivorceDoc = role.DivorceOut = role.EditCitizen = role.EditCivilRegister = role.EditEmployee = role.ICR_Out = role.MarriageDoc = role.MarriageOut = role.SearchCitizens = role.SearchCivilRegister = role.SearchEmployee = role.StatisticsReports = role.UserActivation = false;
                }

                List <ListItem> lstSelectedItems = chklPermission.Items.Cast <ListItem>()
                                                   .Where(x => x.Selected).ToList();

                foreach (var item in lstSelectedItems)
                {
                    switch (item.Value)
                    {
                    case "إضافة مواطن":
                        role.AddCitizen = true;
                        break;

                    case "بحث عن مواطن":
                        role.SearchCitizens = true;
                        break;

                    case "تعديل مواطن":
                        role.EditCitizen = true;
                        break;

                    case "تسجيل واقعة الزواج":
                        role.MarriageDoc = true;
                        break;

                    case "تسجيل واقعة طلاق":
                        role.DivorceDoc = true;
                        break;

                    case "تسجيل بيان ولادة":
                        role.BirthDoc = true;
                        break;

                    case "تسجيل بيان وفاة":
                        role.DeathDoc = true;
                        break;

                    case "إصدار بيان زواج":
                        role.MarriageOut = true;
                        break;

                    case "إصدار بيان طلاق":
                        role.DivorceOut = true;
                        break;

                    case "إصدار بيان ولادة":
                        role.BirthOut = true;
                        break;

                    case "إصدار بيان وفاة":
                        role.DeathOut = true;
                        break;

                    case "إخراج قيد":
                        role.ICR_Out = true;
                        break;

                    case "إضافة موظف":
                        role.AddEmployee = true;
                        break;

                    case "بحث عن موظف":
                        role.SearchEmployee = true;
                        break;

                    case "تعديل بيانات موظف":
                        role.EditEmployee = true;
                        break;

                    case "إضافة سجل مدني":
                        role.AddCivilRegister = true;
                        break;

                    case "تعديل سجل مدني":
                        role.EditCivilRegister = true;
                        break;

                    case "بحث عن سجل مدني":
                        role.SearchCivilRegister = true;
                        break;

                    case "التقارير الإحصائية":
                        role.StatisticsReports = true;
                        break;

                    case "تفعيل حساب مواطن":
                        role.UserActivation = true;
                        break;
                    }
                }

                role.Name = txtRole.Text;

                if (!EditPage)
                {
                    db.tblRoles.AddObject(role);
                }

                db.SaveChanges();
            }

            Response.Redirect("/Finish");
        }
Beispiel #12
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                int Penalty = Helper.GetPenalty(HusbandNationalNum.Text, (int)(DateTime.Today - DateTime.Parse(IncidentDate.Value)).TotalDays, IncidentType.Marriage);
                if (!Helper.CheckBalance(HusbandNationalNum.Text, Penalty))
                {
                    lblErrorMSG.Visible = true;
                    lblErrorMSG1.Text   = "لا يمكن تسجيل عقد الزواج لأن حسابك لا يحوي على المبلغ الكافي لتسديد الضريبة";
                    return;
                }
                else
                {
                    lblErrorMSG.Visible = false;
                }

                using (EGovernmentEntities db = new EGovernmentEntities())
                {
                    if (db.tblCitizens.Where(x => x.NationalNumber == txtFirstWitness.Text).ToList().Count == 0)
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "الرقم الوطني المدخل للشاهد الأول غير موجود في قاعدة البيانات";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }

                    if (db.tblCitizens.Where(x => x.NationalNumber == txtSecondWitness.Text).ToList().Count == 0)
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "الرقم الوطني المدخل للشاهد الثاني غير موجود في قاعدة البيانات";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }

                    if (HusbandNationalNum.Text == txtFirstWitness.Text || HusbandNationalNum.Text == txtSecondWitness.Text)
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "لا يمكن للزوج بأن يكون أحد الشهود";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }

                    if (WifeNationalNum.Text == txtFirstWitness.Text || WifeNationalNum.Text == txtSecondWitness.Text)
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "لا يمكن للزوجة بأن تكون أحد الشهود";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }

                    if (Helper.IsDead(txtFirstWitness.Text))
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "الشاهد الأول هو شخص متوفى";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }

                    if (Helper.IsDead(txtSecondWitness.Text))
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "الشاهد الثاني هو شخص متوفى";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }

                    if (txtFirstWitness.Text == txtSecondWitness.Text)
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "لا يمكن الشهادة بشخص واحد";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }

                    if (Helper.IsMarriageBeforeDivorce(HusbandNationalNum.Text, WifeNationalNum.Text, IncidentDate.Value))
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "لا يمكن إتمام العملية، لأن تاريخ الزواج يسبق تاريخ آخر واقعة طلاق";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }

                    if (Helper.GetDate(IncidentDate.Value) > DateTime.Now)
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "تاريخ حدوث الواقعة أكبر من التاريخ الحالي";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }

                    if (Helper.GetDate(MarriageLicenseDate.Value) > DateTime.Now)
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "تاريخ رخصة الزواج أكبر من التاريخ الحالي";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }

                    tblMarriageContract marriageContract = new tblMarriageContract();

                    marriageContract.HusbandNationalNum = HusbandNationalNum.Text;
                    marriageContract.WifeNationalNum    = WifeNationalNum.Text;
                    marriageContract.FamilyNumber       = GenerateFamilyNumber(db);
                    marriageContract.ContractDate       = DateTime.Now.ToShortDateString();
                    marriageContract.Reference          = txtAuthorityAuthorizedContract.Text;
                    marriageContract.DocumentNumber     = int.Parse(txtDocumentNumber.Text);
                    marriageContract.DocumentDate       = DateTime.Now.ToShortDateString();
                    marriageContract.Notes                       = txtNotes.Text;
                    marriageContract.IncidentDate                = IncidentDate.Value;
                    marriageContract.MarriageLicenseNumber       = MarriageLicenseNumber.Text;
                    marriageContract.MarriageLicenseDate         = MarriageLicenseDate.Value;
                    marriageContract.PreMoney                    = PreMoney.Text;
                    marriageContract.PostMoney                   = PostMoney.Text;
                    marriageContract.MoneyStatus                 = ss1.Checked ? "1" : "2";
                    marriageContract.FirstWitnessNationalNumber  = txtFirstWitness.Text;
                    marriageContract.SecondWitnessNationalNumber = txtSecondWitness.Text;

                    db.tblMarriageContracts.AddObject(marriageContract);


                    Helper.EditSocialNumber(HusbandNationalNum.Text, SocialStatus.Marriad);
                    Helper.EditSocialNumber(WifeNationalNum.Text, SocialStatus.Marriad);

                    db.SaveChanges();

                    Helper.Pay(HusbandNationalNum.Text, Penalty);

                    Response.Redirect("/Finish");
                }
            }
        }
Beispiel #13
0
        protected void btnNext_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                string FatherNationalNumber = Helper.GetCitizen(DeadNationalNumber.Text).FatherNationalNumber;
                int    Penalty = Helper.GetPenalty(FatherNationalNumber, (int)(DateTime.Today - DateTime.Parse(DeadDate.Value)).TotalDays, IncidentType.Death);
                if (!Helper.CheckBalance(FatherNationalNumber, Penalty))
                {
                    lblErrorMSG.Visible = true;
                    lblErrorMSG1.Text   = "لا يمكن تسجيل الوفاة لأن حسابك لا يحوي على المبلغ الكافي لتسديد الضريبة";
                    return;
                }
                else
                {
                    lblErrorMSG.Visible = false;
                }

                using (EGovernmentEntities db = new EGovernmentEntities())
                {
                    if (db.tblCitizens.Where(x => x.NationalNumber == DeadNationalNumber.Text).ToList().Count == 0)
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "الرقم الوطني المدخل غير موجود في قاعدة البيانات";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }



                    if (Helper.GetDate(DeadDate.Value) > DateTime.Now)
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "تاريخ الوفاة أكبر من التاريخ الحالي";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }



                    tblDeadRegistration deadRegistration = new tblDeadRegistration();
                    deadRegistration.NationalNumber  = DeadNationalNumber.Text;
                    deadRegistration.PoliceReportNum = PoliceReportNum.Text;
                    deadRegistration.DeadPlace       = DeadPlace.Text;
                    deadRegistration.DeadDate        = DeadDate.Value;
                    deadRegistration.DoctorName      = DoctorName.Text;
                    deadRegistration.DeadReason      = DeadReason.Text;
                    deadRegistration.Notes           = Notes.Text;
                    deadRegistration.IncidentDate    = DateTime.Now.ToShortDateString();

                    db.tblDeadRegistrations.AddObject(deadRegistration);
                    db.SaveChanges();

                    List <string> lstWifes = Helper.GetActualWifes(DeadNationalNumber.Text);

                    foreach (string wife in lstWifes)
                    {
                        Helper.EditSocialNumber(wife, SocialStatus.Widow);
                    }


                    Helper.Pay(FatherNationalNumber, Penalty);

                    Response.Redirect("/Finish");
                }
            }
        }
Beispiel #14
0
        protected void btnNext_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                int Penalty = Helper.GetPenalty(FatherNationalNumber.Text, (int)(DateTime.Today - DateTime.Parse(IncidentDate.Value)).TotalDays, IncidentType.Birth);
                if (!Helper.CheckBalance(FatherNationalNumber.Text, Penalty))
                {
                    lblErrorMSG.Visible = true;
                    lblErrorMSG1.Text   = "لا يمكن تسجيل الولادة لأن حسابك لا يحوي على المبلغ الكافي لتسديد الضريبة";
                    return;
                }
                else
                {
                    lblErrorMSG.Visible = false;
                }

                using (EGovernmentEntities db = new EGovernmentEntities())
                {
                    if (db.tblCitizens.Where(x => x.NationalNumber == FatherNationalNumber.Text).ToList().Count == 0)
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "الرقم الوطني المدخل للأب غير موجود في قاعدة البيانات";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }

                    if (db.tblCitizens.Where(x => x.NationalNumber == MotherNationalNumber.Text).ToList().Count == 0)
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "الرقم الوطني المدخل للأم غير موجود في قاعدة البيانات";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }

                    if (!Helper.CheckIsWife(FatherNationalNumber.Text, MotherNationalNumber.Text))
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "الأم ليست على ذمة هذا الرجل";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }

                    if (!Helper.CheckPregnancy(Pregnancy.Text))
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "مدة الحمل غير نظامية";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }

                    if (Helper.GetDate(IncidentDate.Value) > DateTime.Now)
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "تاريخ الولادة أكبر من التاريخ الحالي";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }

                    tblCitizen father = Helper.GetCitizen(FatherNationalNumber.Text);

                    tblCitizen citize = new tblCitizen();
                    citize.NationalNumber       = Helper.GetNationalNumber(db, new List <string>());
                    citize.KiedPlace            = father.KiedPlace;
                    citize.KiedNumber           = father.KiedNumber;
                    citize.LastName             = father.LastName;
                    citize.BirthPlace           = BirthPlace1.Text;
                    citize.Birthday             = IncidentDate.Value;
                    citize.Gender               = male.Checked ? "1" : "0";
                    citize.SocialStatus         = "1";
                    citize.Religion             = father.Religion;
                    citize.FirstName            = ChildName.Text;
                    citize.FatherNationalNumber = FatherNationalNumber.Text;
                    citize.MotherNationalNumber = MotherNationalNumber.Text;
                    db.tblCitizens.AddObject(citize);
                    db.SaveChanges();


                    tblBirthRegistration birthRegistration = new tblBirthRegistration();
                    birthRegistration.NationalNumber = citize.NationalNumber;
                    birthRegistration.Pregnancy      = int.Parse(Pregnancy.Text);
                    birthRegistration.Doctor         = Doctor.Text;
                    birthRegistration.BirthPlace     = ss1.Checked ? "1" : ss2.Checked ? "2" : "3";
                    birthRegistration.BirthType      = ss4.Checked ? "1" : ss5.Checked ? "2" : "3";
                    birthRegistration.Notes          = txtNotes.Text;
                    birthRegistration.IncidentDate   = DateTime.Now.ToShortDateString();
                    db.tblBirthRegistrations.AddObject(birthRegistration);
                    db.SaveChanges();

                    Helper.Pay(FatherNationalNumber.Text, Penalty);

                    Response.Redirect("/Finish");
                }
            }
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                using (EGovernmentEntities db = new EGovernmentEntities())
                {
                    EditPage = (btnAdd.Text == "حفظ التعديلات");
                    tblEmployee employee;
                    if (EditPage)
                    {
                        employee = db.tblEmployees.Where(x => x.NationalNumber == labelNationalNum.Text).FirstOrDefault();
                    }
                    else
                    {
                        employee = new tblEmployee();
                    }

                    var citizen = db.tblCitizens.Where(b => b.NationalNumber == EmployeeNationalNum.Text).FirstOrDefault();
                    employee.NationalNumber = labelNationalNum.Text;
                    employee.Address        = txtAddress.Text;
                    employee.Specialization = txtSpecialization.Text;
                    employee.Phone          = txtPhoneNumber.Text;

                    if (!EditPage)
                    {
                        if (db.tblEmployees.Where(x => x.NationalNumber == employee.NationalNumber).ToList().Count == 0)
                        {
                            db.tblEmployees.AddObject(employee);
                        }
                    }

                    tblEmployeesCivilRegistry empcivil;
                    if (EditPage)
                    {
                        empcivil = db.tblEmployeesCivilRegistries.Where(x => x.EmployeNationalNumber == labelNationalNum.Text).OrderByDescending(x => x.Id).FirstOrDefault();
                    }
                    else
                    {
                        empcivil = new tblEmployeesCivilRegistry();
                    }

                    empcivil.IsManager         = rdoManager.Checked;
                    empcivil.IsCivilRegisterer = rdoIsCivilRegisterer.Checked;
                    empcivil.IsController      = rdoIsController.Checked;
                    empcivil.RoleId            = int.Parse(ddlRole.SelectedValue);
                    if (!CheckBox1.Checked)
                    {
                        empcivil.E_date = DateTime.Now;
                    }

                    int CivilRegistryID = int.Parse(ddlCivilRegistry.SelectedValue);
                    if (!rdoManager.Checked)
                    {
                        empcivil.CivilRegistryID = CivilRegistryID;
                    }

                    empcivil.EmployeNationalNumber = employee.NationalNumber;
                    empcivil.S_date = DateTime.Now;

                    if (!EditPage)
                    {
                        db.tblEmployeesCivilRegistries.AddObject(empcivil);
                    }

                    if (Convert.ToBoolean(empcivil.IsManager))
                    {
                        List <tblEmployee> lstEmployees = Helper.GetEmployeeByAffairs(CivilRegistryID);
                        Helper.UnManager(lstEmployees);
                    }

                    if (Convert.ToBoolean(empcivil.IsCivilRegisterer))
                    {
                        List <tblEmployee> lstEmployees = Helper.GetEmployeeByCivilRegisterar(CivilRegistryID);
                        Helper.UnCivilRegisterer(lstEmployees);
                    }

                    if (Convert.ToBoolean(empcivil.IsController))
                    {
                        List <tblEmployee> lstEmployees = Helper.GetEmployeeByCivilRegisterar(CivilRegistryID);
                        Helper.UnController(lstEmployees);
                    }



                    db.SaveChanges();

                    Response.Redirect("/Finish");
                }
            }
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                int Penalty = Helper.GetPenalty(HusbandNationalNum.Text, (int)(DateTime.Today - DateTime.Parse(IncidentDate.Value)).TotalDays, IncidentType.Divorce);
                if (!Helper.CheckBalance(HusbandNationalNum.Text, Penalty))
                {
                    lblErrorMSG.Visible = true;
                    lblErrorMSG1.Text   = "لا يمكن إتمام واقعة الطلاق لأن حسابك لا يحوي على المبلغ الكافي لتسديد الضريبة";
                    return;
                }
                else
                {
                    lblErrorMSG.Visible = false;
                }
                using (EGovernmentEntities db = new EGovernmentEntities())
                {
                    if (db.tblCitizens.Where(x => x.NationalNumber == txtFirstWitness.Text).ToList().Count == 0)
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "الرقم الوطني المدخل للشاهد الأول غير موجود في قاعدة البيانات";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }

                    if (db.tblCitizens.Where(x => x.NationalNumber == txtSecondWitness.Text).ToList().Count == 0)
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "الرقم الوطني المدخل للشاهد الثاني غير موجود في قاعدة البيانات";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }


                    if (HusbandNationalNum.Text == txtFirstWitness.Text || HusbandNationalNum.Text == txtSecondWitness.Text)
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "لا يمكن للزوج بأن يكون أحد الشهود";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }

                    if (WifeNationalNum.Text == txtFirstWitness.Text || WifeNationalNum.Text == txtSecondWitness.Text)
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "لا يمكن للزوجة بأن تكون أحد الشهود";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }


                    if (txtFirstWitness.Text == txtSecondWitness.Text)
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "لا يمكن الشهادة بشخص واحد";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }

                    if (Helper.IsDead(txtFirstWitness.Text))
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "الشاهد الأول هو شخص متوفى";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }

                    if (Helper.IsDead(txtSecondWitness.Text))
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "الشاهد الثاني هو شخص متوفى";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }

                    if (!Helper.CheckIsWife(HusbandNationalNum.Text, WifeNationalNum.Text))
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "لا يمكن إتمام العملية، لأن هذه المواطنة ليست على ذمة هذا الرجل";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }

                    if (Helper.IsDivorceBeforeMarriage(HusbandNationalNum.Text, WifeNationalNum.Text, IncidentDate.Value))
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "لا يمكن إتمام العملية، لأن تاريخ الطلاق يسبق تاريخ آخر واقعة زواج";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }

                    if (Helper.GetDate(IncidentDate.Value) > DateTime.Now)
                    {
                        lblErrorMSG.Visible = true;
                        lblErrorMSG1.Text   = "تاريخ الطلاق أكبر من التاريخ الحالي";
                        return;
                    }
                    else
                    {
                        lblErrorMSG.Visible = false;
                    }

                    tblDivorceIncident divorceIncident = new tblDivorceIncident();

                    divorceIncident.HusbandNationalNum = HusbandNationalNum.Text;
                    divorceIncident.WifeNationalNum    = WifeNationalNum.Text;
                    divorceIncident.IncidentDate       = IncidentDate.Value;
                    divorceIncident.DivorceType        = ss1.Checked ? "1" : "0";
                    divorceIncident.DivorcePlace       = txtDivorcePlace.Text;
                    divorceIncident.DivorceReason      = txtDivorceReason.Text;
                    divorceIncident.Notes          = txtNotes.Text;
                    divorceIncident.Reference      = txtAuthorityAuthorizedContract.Text;
                    divorceIncident.DocumentNumber = int.Parse(txtDocumentNumber.Text);
                    divorceIncident.DocumentDate   = DateTime.Now.ToShortDateString();

                    int temp = -1;
                    int.TryParse(txtAdvocacyNum.Text, out temp);

                    if (temp != -1)
                    {
                        divorceIncident.AdvocacyNum = temp;
                    }

                    divorceIncident.FirstWitnessNationalNumber  = txtFirstWitness.Text;
                    divorceIncident.SecondWitnessNationalNumber = txtSecondWitness.Text;

                    db.tblDivorceIncidents.AddObject(divorceIncident);

                    if (Helper.GetActualWifes(HusbandNationalNum.Text).Count == 0)
                    {
                        Helper.EditSocialNumber(HusbandNationalNum.Text, SocialStatus.Divorced);
                    }

                    Helper.EditSocialNumber(WifeNationalNum.Text, SocialStatus.Divorced);

                    db.SaveChanges();

                    Helper.Pay(HusbandNationalNum.Text, Penalty);

                    Response.Redirect("/Finish");
                }
            }
        }