Пример #1
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (this.Page.IsValid)
        {
            int ajancyId = 0;
            Ajancy.Person person = null;
            Ajancy.Ajancy ajancy = new Ajancy.Ajancy();
            Ajancy.BusinessLicense businessLicense = new Ajancy.BusinessLicense();
            db = new Ajancy.Kimia_Ajancy(Public.ConnectionString);

            if (HttpContext.Current.User.IsInRole(Public.Role.AjancyManager.ToString())) // Add mode
            {
                if (db.Ajancies.Any<Ajancy.Ajancy>(j => j.PostalCode == this.txtPlacePostalCode.Text.Trim()))
                {
                    this.lblMessage.Text = "کد پستی واحد تجاری تکراری میباشد";// Duplicate PostalCode
                    return;
                }
                else if (db.Ajancies.Any<Ajancy.Ajancy>(j => j.CityID == int.Parse(this.drpCity.SelectedValue) &&
                                                                                       j.AjancyType != (byte)Public.AjancyType.Academy &&
                                                                                       j.AjancyName.Equals(this.txtAjancyName.Text.Trim())))
                {
                    this.lblMessage.Text = string.Format("آژانسی با نام <b>{0}</b> در شهرستان <b>{1}</b> موجود میباشد", ajancy.AjancyName, this.drpCity.SelectedItem.Text);
                    return;
                }

                dlo = new DataLoadOptions();
                dlo.LoadWith<Ajancy.Person>(p => p.User);
                dlo.LoadWith<Ajancy.User>(u => u.UsersInRoles);
                dlo.LoadWith<Ajancy.UsersInRole>(ur => ur.AjancyPartners);
                db.LoadOptions = dlo;

                person = db.Persons.First<Ajancy.Person>(p => p.NationalCode == HttpContext.Current.User.Identity.Name);
                Ajancy.AjancyPartner partner = person.User.UsersInRoles.Single<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.AjancyManager && ur.LockOutDate == null).AjancyPartners.Single<Ajancy.AjancyPartner>(jp => jp.AjancyID == null);
                ajancy.AjancyPartners.Add(partner);
                ajancy.BusinessLicenses.Add(businessLicense);
                businessLicense.BusinessLicenseRevivals.Add(new Ajancy.BusinessLicenseRevival { StartDate = this.txtStartDate.GeorgianDate.Value, EndDate = this.txtEndDate.GeorgianDate.Value, SubmitDate = DateTime.Now });
                ajancy.SubmitDate = DateTime.Now;
                db.Ajancies.InsertOnSubmit(ajancy);
            }
            else if (!HttpContext.Current.User.IsInRole(Public.Role.AjancyManager.ToString()) && int.TryParse(this.ViewState["AjancyID"].ToString(), out ajancyId)) // Edit mode
            {
                dlo = new DataLoadOptions();
                dlo.LoadWith<Ajancy.Ajancy>(j => j.AjancyUtilities);
                dlo.LoadWith<Ajancy.Ajancy>(j => j.BusinessLicenses);
                dlo.LoadWith<Ajancy.BusinessLicense>(bl => bl.BusinessLicenseRevivals);
                dlo.LoadWith<Ajancy.Ajancy>(j => j.AjancyPartners);
                dlo.LoadWith<Ajancy.AjancyPartner>(jp => jp.UsersInRole);
                dlo.LoadWith<Ajancy.UsersInRole>(ur => ur.User);
                dlo.LoadWith<Ajancy.User>(u => u.Person);
                db.LoadOptions = dlo;

                ajancy = db.Ajancies.FirstOrDefault<Ajancy.Ajancy>(j => j.AjancyID == ajancyId);
                businessLicense = ajancy.BusinessLicenses.First<Ajancy.BusinessLicense>();
                person = ajancy.AjancyPartners.Single<Ajancy.AjancyPartner>(jp => jp.UsersInRole.RoleID == (short)Public.Role.AjancyManager && jp.LockOutDate == null).UsersInRole.User.Person;
            }

            person.FirstName = this.txtFirstName.Text.Trim();
            person.LastName = this.txtLastName.Text.Trim();
            person.Father = this.txtFather.Text.Trim();
            person.BirthCertificateNo = this.txtBirthCertificateNo.Text.Trim();
            person.BirthCertificateSerial = this.txtBirthCertificateSerial.Text.Trim();
            person.BirthCertificateSerie = this.txtBirthCertificateSerie.Text.Trim();
            person.BirthCertificateAlfa = this.drpBirthCertificateAlfa.SelectedValue;
            person.Gender = Public.ToByte(this.drpGender.SelectedValue);
            person.Marriage = Public.ToByte(this.drpMarriage.SelectedValue);
            person.BirthDate = this.txtBirthDate.GeorgianDate.Value;
            person.BirthPlace = this.txtBirthPlace.Text.Trim();
            person.BirthCertificatePlace = this.txtBirthCertificatePlace.Text.Trim();
            person.FamilyMembersCount = this.txtFamilyMembersCount.Text.Trim();
            person.Education = Public.ToByte(this.drpEducation.SelectedValue);
            person.MilitaryService = Public.ToByte(this.drpMilitaryService.SelectedValue);
            person.Religion = Public.ToByte(this.drpReligion.SelectedValue);
            person.Subreligion = this.txtSubreligion.Text.Trim();
            person.JobStatus = Public.ToByte(this.drpJobStatus.SelectedValue);
            person.Phone = this.txtPhone.Text.Trim();
            person.Mobile = this.txtMobile.Text.Trim();
            person.PostalCode = this.txtPostalCode.Text.Trim();
            person.Address = this.txtAddress.Text.Trim();

            ajancy.AjancyType = Public.ToByte(this.drpAjancyType.SelectedValue);
            ajancy.AjancyName = this.txtAjancyName.Text.Trim();
            ajancy.CityID = Public.ToShort(this.drpCity.SelectedValue);
            ajancy.BusinessLicenseType = Public.ToByte(this.drpBusinessLicenseType.SelectedValue);
            ajancy.OfficePosition = Public.ToByte(this.drpOfficePosition.SelectedValue);
            ajancy.OfficeLevel = this.txtOfficeLevel.Text.Trim();
            ajancy.OfficeSpace = this.txtOfficeSpace.Text.Trim();
            ajancy.BalconySpace = this.txtBalconySpace.Text.Trim();
            ajancy.BalconyHeight = this.txtBalconyHeight.Text.Trim();
            ajancy.ParkingSpace = this.txtParkingSpace.Text.Trim();
            ajancy.ParkingState = this.drpParkingState.SelectedIndex == 0 ? true : false;
            ajancy.BusinessScope = this.txtBusinessScope.Text.Trim();
            ajancy.PoliceStation = this.txtPoliceStation.Text.Trim();
            ajancy.Mayor = (byte)this.drpMayor.SelectedIndex;
            ajancy.Address = this.txtPlaceAddress.Text.Trim();
            ajancy.Phone = this.txtBusinessPlacePhone.Text.Trim();
            ajancy.RegisteredPelak = this.txtRegisteredPelak.Text.Trim();
            ajancy.BluePelak = this.txtBluePelak.Text.Trim();
            ajancy.PostalCode = this.txtPlacePostalCode.Text.Trim();
            ajancy.EstateType = Public.ToByte(this.drpEstateType.SelectedValue);
            ajancy.DocumentType = Public.ToByte(this.drpDocumentType.SelectedValue);
            ajancy.PlaceOwner = this.txtPlaceOwner.Text.Trim();

            businessLicense.BusinessLicenseNo = this.txtBusinessLicenseNo.Text.Trim();
            businessLicense.MemberShipCode = this.txtMemberShipCode.Text.Trim();
            businessLicense.NationalCardBarCode = this.txtNationalCardBarCode.Text.Trim();
            businessLicense.SerialNo = this.txtSerialNo.Text.Trim();
            businessLicense.CategoryCode = this.txtCategoryCode.Text.Trim();
            businessLicense.ISIC = this.txtISIC.Text.Trim();
            businessLicense.SubmitDate = DateTime.Now;

            Ajancy.AjancyUtility utility = null;
            foreach (ListItem item in this.lstUtility.Items)
            {
                utility = ajancy.AjancyUtilities.FirstOrDefault<Ajancy.AjancyUtility>(u => u.Utility == Public.ToByte(item.Value));
                if (!item.Selected && utility != null)
                {
                    db.AjancyUtilities.DeleteOnSubmit(utility);
                }
                else if (item.Selected && utility == null)
                {
                    ajancy.AjancyUtilities.Add(new Ajancy.AjancyUtility { Utility = Public.ToByte(item.Value) });
                }
            }

            #region SetPartners

            if (!string.IsNullOrEmpty(this.txtPartnerName1.Text.Trim()) && !string.IsNullOrEmpty(this.txtPartnerFamily1.Text.Trim()) && !string.IsNullOrEmpty(this.txtPartnerNationalCode1.Text.Trim()))
            {
                Ajancy.Person prsn = db.Persons.FirstOrDefault<Ajancy.Person>(p => p.NationalCode == this.txtPartnerNationalCode1.Text.Trim());
                Ajancy.UsersInRole userRole = null;
                if (prsn == null)
                {
                    prsn = new Ajancy.Person { NationalCode = this.txtPartnerNationalCode1.Text.Trim(), FirstName = this.txtPartnerName1.Text.Trim(), LastName = this.txtPartnerFamily1.Text.Trim(), SubmitDate = DateTime.Now };
                    Ajancy.User user = new Ajancy.User();
                    user.UserName = this.txtPartnerNationalCode1.Text.Trim();
                    user.ProvinceID = Public.ToByte(this.drpProvince.SelectedValue);
                    user.CityID = Public.ToShort(this.drpCity.SelectedValue);
                    user.SubmitDate = DateTime.Now;
                    userRole = new Ajancy.UsersInRole { RoleID = (short)Public.Role.AjancyPartner, MembershipDate = DateTime.Now };
                    userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                    user.UsersInRoles.Add(userRole);
                    prsn.User = user;
                    db.Persons.InsertOnSubmit(prsn);
                }
                else
                {
                    userRole = prsn.User.UsersInRoles.SingleOrDefault<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.AjancyPartner);
                    if (userRole == null)
                    {
                        userRole = new Ajancy.UsersInRole { RoleID = (short)Public.Role.AjancyPartner, MembershipDate = DateTime.Now };
                        userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                        prsn.User.UsersInRoles.Add(userRole);
                    }
                    else if (!userRole.AjancyPartners.Any<Ajancy.AjancyPartner>(jp => jp.AjancyID == ajancy.AjancyID))
                    {
                        userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                    }
                }
            }
            if (!string.IsNullOrEmpty(this.txtPartnerName2.Text.Trim()) && !string.IsNullOrEmpty(this.txtPartnerFamily2.Text.Trim()) && !string.IsNullOrEmpty(this.txtPartnerNationalCode2.Text.Trim()))
            {
                Ajancy.Person prsn = db.Persons.FirstOrDefault<Ajancy.Person>(p => p.NationalCode == this.txtPartnerNationalCode2.Text.Trim());
                Ajancy.UsersInRole userRole = null;
                if (prsn == null)
                {
                    prsn = new Ajancy.Person { NationalCode = this.txtPartnerNationalCode2.Text.Trim(), FirstName = this.txtPartnerName2.Text.Trim(), LastName = this.txtPartnerFamily2.Text.Trim(), SubmitDate = DateTime.Now };
                    Ajancy.User user = new Ajancy.User();
                    user.UserName = this.txtPartnerNationalCode2.Text.Trim();
                    user.ProvinceID = Public.ToByte(this.drpProvince.SelectedValue);
                    user.CityID = Public.ToShort(this.drpCity.SelectedValue);
                    user.SubmitDate = DateTime.Now;
                    userRole = new Ajancy.UsersInRole { RoleID = (short)Public.Role.AjancyPartner, MembershipDate = DateTime.Now };
                    userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                    user.UsersInRoles.Add(userRole);
                    prsn.User = user;
                    db.Persons.InsertOnSubmit(prsn);
                }
                else
                {
                    userRole = prsn.User.UsersInRoles.SingleOrDefault<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.AjancyPartner);
                    if (userRole == null)
                    {
                        userRole = new Ajancy.UsersInRole { RoleID = (short)Public.Role.AjancyPartner, MembershipDate = DateTime.Now };
                        userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                        prsn.User.UsersInRoles.Add(userRole);
                    }
                    else if (!userRole.AjancyPartners.Any<Ajancy.AjancyPartner>(jp => jp.AjancyID == ajancy.AjancyID))
                    {
                        userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                    }
                }
            }
            if (!string.IsNullOrEmpty(this.txtPartnerName3.Text.Trim()) && !string.IsNullOrEmpty(this.txtPartnerFamily3.Text.Trim()) && !string.IsNullOrEmpty(this.txtPartnerNationalCode3.Text.Trim()))
            {
                Ajancy.Person prsn = db.Persons.FirstOrDefault<Ajancy.Person>(p => p.NationalCode == this.txtPartnerNationalCode3.Text.Trim());
                Ajancy.UsersInRole userRole = null;
                if (prsn == null)
                {
                    prsn = new Ajancy.Person { NationalCode = this.txtPartnerNationalCode3.Text.Trim(), FirstName = this.txtPartnerName3.Text.Trim(), LastName = this.txtPartnerFamily3.Text.Trim(), SubmitDate = DateTime.Now };
                    Ajancy.User user = new Ajancy.User();
                    user.UserName = this.txtPartnerNationalCode3.Text.Trim();
                    user.ProvinceID = Public.ToByte(this.drpProvince.SelectedValue);
                    user.CityID = Public.ToShort(this.drpCity.SelectedValue);
                    user.SubmitDate = DateTime.Now;
                    userRole = new Ajancy.UsersInRole { RoleID = (short)Public.Role.AjancyPartner, MembershipDate = DateTime.Now };
                    userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                    user.UsersInRoles.Add(userRole);
                    prsn.User = user;
                    db.Persons.InsertOnSubmit(prsn);
                }
                else
                {
                    userRole = prsn.User.UsersInRoles.SingleOrDefault<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.AjancyPartner);
                    if (userRole == null)
                    {
                        userRole = new Ajancy.UsersInRole { RoleID = (short)Public.Role.AjancyPartner, MembershipDate = DateTime.Now };
                        userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                        prsn.User.UsersInRoles.Add(userRole);
                    }
                    else if (!userRole.AjancyPartners.Any<Ajancy.AjancyPartner>(jp => jp.AjancyID == ajancy.AjancyID))
                    {
                        userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                    }
                }
            }

            #endregion

            try
            {
                db.SubmitChanges();
                DisposeContext();
                this.Session["Ajancy"] = new Ajancy.Ajancy { AjancyID = ajancy.AjancyID, AjancyType = ajancy.AjancyType, AjancyName = ajancy.AjancyName };
                Response.Redirect("~/Message.aspx?mode=4");
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("IX_BusinessLicenses"))
                {
                    this.lblMessage.Text = "شماره پروانه کسب تکراری میباشد";
                }
                else
                {
                    throw ex;
                }
            }
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (this.Page.IsValid)
        {
            int ajancyId = 0;
            if (Request.QueryString["j"] != null && int.TryParse(TamperProofString.QueryStringDecode(Request.QueryString["j"]), out ajancyId))
            {
                new Ajancy.Kimia_Ajancy(Public.ConnectionString);
                DataLoadOptions dlo = new DataLoadOptions();
                dlo.LoadWith<Ajancy.Ajancy>(j => j.AjancyPartners);
                dlo.LoadWith<Ajancy.AjancyPartner>(jp => jp.UsersInRole);
                dlo.LoadWith<Ajancy.UsersInRole>(ur => ur.User);
                dlo.LoadWith<Ajancy.User>(u => u.Person);
                db.LoadOptions = dlo;
                Ajancy.Ajancy ajancy = db.Ajancies.FirstOrDefault<Ajancy.Ajancy>(j => j.AjancyID == ajancyId);
                if (ajancy != null)
                {
                    Ajancy.BusinessLicense businessLicense = new Ajancy.BusinessLicense();

                    #region BusinessLicenseInquiry

                    Ajancy.BusinessLicenseInquiry blq_0 = businessLicense.BusinessLicenseInquiries.SingleOrDefault<Ajancy.BusinessLicenseInquiry>(blq => blq.Type == 0);
                    Ajancy.BusinessLicenseInquiry blq_1 = businessLicense.BusinessLicenseInquiries.SingleOrDefault<Ajancy.BusinessLicenseInquiry>(blq => blq.Type == 1);
                    Ajancy.BusinessLicenseInquiry blq_2 = businessLicense.BusinessLicenseInquiries.SingleOrDefault<Ajancy.BusinessLicenseInquiry>(blq => blq.Type == 2);
                    Ajancy.BusinessLicenseInquiry blq_3 = businessLicense.BusinessLicenseInquiries.SingleOrDefault<Ajancy.BusinessLicenseInquiry>(blq => blq.Type == 3);
                    Ajancy.BusinessLicenseInquiry blq_4 = businessLicense.BusinessLicenseInquiries.SingleOrDefault<Ajancy.BusinessLicenseInquiry>(blq => blq.Type == 4);

                    if (blq_0 == null && !string.IsNullOrEmpty(this.txtDaraeeNo.Text) && this.txtDaraeeDate.HasDate)
                    {
                        blq_0 = new Ajancy.BusinessLicenseInquiry { Type = 0, SerialNumber = this.txtDaraeeNo.Text, InquiryDate = this.txtDaraeeDate.GeorgianDate.Value, Comment = this.txtComment_0.Text, SubmitDate = DateTime.Now };
                        businessLicense.BusinessLicenseInquiries.Add(blq_0);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(this.txtDaraeeNo.Text))
                        {
                            blq_0.SerialNumber = this.txtDaraeeNo.Text;
                        }
                        if (this.txtDaraeeDate.HasDate)
                        {
                            blq_0.InquiryDate = this.txtDaraeeDate.GeorgianDate.Value;
                        }
                        blq_0.Comment = this.txtComment_0.Text;
                    }

                    if (blq_1 == null && !string.IsNullOrEmpty(this.txtShhrdariNo.Text) && this.txtShhrdariDate.HasDate)
                    {
                        blq_1 = new Ajancy.BusinessLicenseInquiry { Type = 1, SerialNumber = this.txtShhrdariNo.Text, InquiryDate = this.txtShhrdariDate.GeorgianDate.Value, Comment = this.txtComment_1.Text, SubmitDate = DateTime.Now };
                        businessLicense.BusinessLicenseInquiries.Add(blq_1);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(this.txtShhrdariNo.Text))
                        {
                            blq_1.SerialNumber = this.txtShhrdariNo.Text;
                        }
                        if (this.txtShhrdariDate.HasDate)
                        {
                            blq_1.InquiryDate = this.txtShhrdariDate.GeorgianDate.Value;
                        }
                        blq_1.Comment = this.txtComment_1.Text;
                    }

                    if (blq_2 == null && !string.IsNullOrEmpty(this.txtAmakenNo.Text) && this.txtAmakenDate.HasDate)
                    {
                        blq_2 = new Ajancy.BusinessLicenseInquiry { Type = 2, SerialNumber = this.txtAmakenNo.Text, InquiryDate = this.txtAmakenDate.GeorgianDate.Value, Comment = this.txtComment_2.Text, SubmitDate = DateTime.Now };
                        businessLicense.BusinessLicenseInquiries.Add(blq_2);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(this.txtAmakenNo.Text))
                        {
                            blq_2.SerialNumber = this.txtAmakenNo.Text;
                        }
                        if (this.txtAmakenDate.HasDate)
                        {
                            blq_2.InquiryDate = this.txtAmakenDate.GeorgianDate.Value;
                        }
                        blq_2.Comment = this.txtComment_2.Text;
                    }

                    if (blq_3 == null && !string.IsNullOrEmpty(this.txtAngoshNegariNo.Text) && this.txtAngoshNegariDate.HasDate)
                    {
                        blq_3 = new Ajancy.BusinessLicenseInquiry { Type = 3, SerialNumber = this.txtAngoshNegariNo.Text, InquiryDate = this.txtAngoshNegariDate.GeorgianDate.Value, Comment = this.txtComment_3.Text, SubmitDate = DateTime.Now };
                        businessLicense.BusinessLicenseInquiries.Add(blq_3);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(this.txtAngoshNegariNo.Text))
                        {
                            blq_3.SerialNumber = this.txtAngoshNegariNo.Text;
                        }
                        if (this.txtAngoshNegariDate.HasDate)
                        {
                            blq_3.InquiryDate = this.txtAngoshNegariDate.GeorgianDate.Value;
                        }
                        blq_3.Comment = this.txtComment_3.Text;
                    }

                    if (blq_4 == null && !string.IsNullOrEmpty(this.txtAsnafNo.Text) && this.txtAsnafDate.HasDate)
                    {
                        blq_4 = new Ajancy.BusinessLicenseInquiry { Type = 4, SerialNumber = this.txtAsnafNo.Text, InquiryDate = this.txtAsnafDate.GeorgianDate.Value, Comment = this.txtComment_4.Text, SubmitDate = DateTime.Now };
                        businessLicense.BusinessLicenseInquiries.Add(blq_4);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(this.txtAsnafNo.Text))
                        {
                            blq_4.SerialNumber = this.txtAsnafNo.Text;
                        }
                        if (this.txtAsnafDate.HasDate)
                        {
                            blq_4.InquiryDate = this.txtAsnafDate.GeorgianDate.Value;
                        }
                        blq_4.Comment = this.txtComment_4.Text;
                    }

                    #endregion

                    #region BusinessLicenseInitialPayment

                    Ajancy.BusinessLicenseInitialPayment blp_0 = businessLicense.BusinessLicenseInitialPayments.SingleOrDefault<Ajancy.BusinessLicenseInitialPayment>(blp => blp.Type == 0);
                    Ajancy.BusinessLicenseInitialPayment blp_1 = businessLicense.BusinessLicenseInitialPayments.SingleOrDefault<Ajancy.BusinessLicenseInitialPayment>(blp => blp.Type == 1);
                    Ajancy.BusinessLicenseInitialPayment blp_2 = businessLicense.BusinessLicenseInitialPayments.SingleOrDefault<Ajancy.BusinessLicenseInitialPayment>(blp => blp.Type == 2);
                    Ajancy.BusinessLicenseInitialPayment blp_3 = businessLicense.BusinessLicenseInitialPayments.SingleOrDefault<Ajancy.BusinessLicenseInitialPayment>(blp => blp.Type == 3);
                    Ajancy.BusinessLicenseInitialPayment blp_4 = businessLicense.BusinessLicenseInitialPayments.SingleOrDefault<Ajancy.BusinessLicenseInitialPayment>(blp => blp.Type == 4);
                    Ajancy.BusinessLicenseInitialPayment blp_5 = businessLicense.BusinessLicenseInitialPayments.SingleOrDefault<Ajancy.BusinessLicenseInitialPayment>(blp => blp.Type == 5);

                    if (blp_0 == null && !string.IsNullOrEmpty(this.txtBillNoKhazane.Text) && !string.IsNullOrEmpty(this.txtBillKhazaneAmount.Text))
                    {
                        blp_0 = new Ajancy.BusinessLicenseInitialPayment { Type = 0, BillNumber = this.txtBillNoKhazane.Text, Amount = Public.ToInt(this.txtBillKhazaneAmount.Text) };
                        businessLicense.BusinessLicenseInitialPayments.Add(blp_0);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(this.txtBillNoKhazane.Text))
                        {
                            blp_0.BillNumber = this.txtBillNoKhazane.Text;
                        }
                        if (!string.IsNullOrEmpty(this.txtBillKhazaneAmount.Text))
                        {
                            blp_0.Amount = Public.ToInt(this.txtBillKhazaneAmount.Text);
                        }
                    }

                    if (blp_1 == null && !string.IsNullOrEmpty(this.txtBillNoEtehadieh.Text) && !string.IsNullOrEmpty(this.txtBillEtehadiehAmount.Text))
                    {
                        blp_1 = new Ajancy.BusinessLicenseInitialPayment { Type = 1, BillNumber = this.txtBillNoEtehadieh.Text, Amount = Public.ToInt(this.txtBillEtehadiehAmount.Text) };
                        businessLicense.BusinessLicenseInitialPayments.Add(blp_1);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(this.txtBillNoEtehadieh.Text))
                        {
                            blp_1.BillNumber = this.txtBillNoEtehadieh.Text;
                        }
                        if (!string.IsNullOrEmpty(this.txtBillEtehadiehAmount.Text))
                        {
                            blp_1.Amount = Public.ToInt(this.txtBillEtehadiehAmount.Text);
                        }
                    }

                    if (blp_2 == null && !string.IsNullOrEmpty(this.txtBillNoAsnaf.Text) && !string.IsNullOrEmpty(this.txtBillAsnafAmount.Text))
                    {
                        blp_2 = new Ajancy.BusinessLicenseInitialPayment { Type = 2, BillNumber = this.txtBillNoAsnaf.Text, Amount = Public.ToInt(this.txtBillAsnafAmount.Text) };
                        businessLicense.BusinessLicenseInitialPayments.Add(blp_2);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(this.txtBillNoAsnaf.Text))
                        {
                            blp_2.BillNumber = this.txtBillNoAsnaf.Text;
                        }
                        if (!string.IsNullOrEmpty(this.txtBillAsnafAmount.Text))
                        {
                            blp_2.Amount = Public.ToInt(this.txtBillAsnafAmount.Text);
                        }
                    }

                    if (blp_3 == null && !string.IsNullOrEmpty(this.txtBillNoOzviat.Text) && !string.IsNullOrEmpty(this.txtBillOzviatAmount.Text))
                    {
                        blp_3 = new Ajancy.BusinessLicenseInitialPayment { Type = 3, BillNumber = this.txtBillNoOzviat.Text, Amount = Public.ToInt(this.txtBillOzviatAmount.Text) };
                        businessLicense.BusinessLicenseInitialPayments.Add(blp_3);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(this.txtBillNoOzviat.Text))
                        {
                            blp_3.BillNumber = this.txtBillNoOzviat.Text;
                        }
                        if (!string.IsNullOrEmpty(this.txtBillOzviatAmount.Text))
                        {
                            blp_3.Amount = Public.ToInt(this.txtBillOzviatAmount.Text);
                        }
                    }

                    if (blp_4 == null && !string.IsNullOrEmpty(this.txtBillNoVorodi.Text) && !string.IsNullOrEmpty(this.txtBillVorodiAmount.Text))
                    {
                        blp_4 = new Ajancy.BusinessLicenseInitialPayment { Type = 4, BillNumber = this.txtBillNoVorodi.Text, Amount = Public.ToInt(this.txtBillVorodiAmount.Text) };
                        businessLicense.BusinessLicenseInitialPayments.Add(blp_4);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(this.txtBillNoVorodi.Text))
                        {
                            blp_4.BillNumber = this.txtBillNoVorodi.Text;
                        }
                        if (!string.IsNullOrEmpty(this.txtBillVorodiAmount.Text))
                        {
                            blp_4.Amount = Public.ToInt(this.txtBillVorodiAmount.Text);
                        }
                    }

                    if (blp_5 == null && !string.IsNullOrEmpty(this.txtBillNoEhdaee.Text) && !string.IsNullOrEmpty(this.txtBillEhdaeeAmount.Text))
                    {
                        blp_5 = new Ajancy.BusinessLicenseInitialPayment { Type = 5, BillNumber = this.txtBillNoEhdaee.Text, Amount = Public.ToInt(this.txtBillEhdaeeAmount.Text) };
                        businessLicense.BusinessLicenseInitialPayments.Add(blp_5);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(this.txtBillNoEhdaee.Text))
                        {
                            blp_5.BillNumber = this.txtBillNoEhdaee.Text;
                        }
                        if (!string.IsNullOrEmpty(this.txtBillEhdaeeAmount.Text))
                        {
                            blp_5.Amount = Public.ToInt(this.txtBillEhdaeeAmount.Text);
                        }
                    }

                    #endregion

                    if (this.chkVerification.Checked)
                    {
                        if (!this.txtStartDate.HasDate || !this.txtEndDate.HasDate)
                        {
                            this.lblMessage.Text = "تاریخ صدور و تاریخ انقضا را وارد کنید";
                            return;
                        }
                        if (string.IsNullOrEmpty(this.txtBusinessLicenseNo.Text))
                        {
                            this.lblMessage.Text = "شماره پروانه کسب را وارد کنید";
                            return;
                        }

                        businessLicense.BusinessLicenseNo = this.txtBusinessLicenseNo.Text;
                        businessLicense.MemberShipCode = this.txtMemberShipCode.Text;
                        businessLicense.NationalCardBarCode = this.txtNationalCardBarCode.Text;
                        businessLicense.SerialNo = this.txtSerialNo.Text;
                        businessLicense.CategoryCode = this.txtCategoryCode.Text;
                        businessLicense.ISIC = this.txtISIC.Text;
                        businessLicense.SubmitDate = DateTime.Now;
                        businessLicense.BusinessLicenseRevivals.Add(new Ajancy.BusinessLicenseRevival { StartDate = this.txtStartDate.GeorgianDate.Value, EndDate = this.txtEndDate.GeorgianDate.Value, SubmitDate = DateTime.Now });
                        ajancy.AjancyName = this.txtAjancyName.Text;

                        //foreach (Ajancy.AjancyPartner partner in ajancy.AjancyPartners)
                        //{
                        //    partner.LockOutDate = null;
                        //    partner.UsersInRole.LockOutDate = null;
                        //    if (partner.UsersInRole.User.PassWord == null)
                        //    {
                        //        partner.UsersInRole.User.PassWord = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(partner.UsersInRole.User.Person.NationalCode, "SHA1");
                        //    }
                        //}
                    }

                    db.SubmitChanges();
                    ClearControls();
                    this.lblMessage.Text = Public.SAVEMESSAGE;
                }
            }
        }
    }
Пример #3
0
 partial void DeleteBusinessLicense(BusinessLicense instance);
Пример #4
0
 partial void UpdateBusinessLicense(BusinessLicense instance);
Пример #5
0
 partial void InsertBusinessLicense(BusinessLicense instance);
Пример #6
0
		private void detach_BusinessLicenses(BusinessLicense entity)
		{
			this.SendPropertyChanging();
			entity.Ajancy = null;
		}
Пример #7
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (this.Page.IsValid)
        {
            int personId = 0;
            int ajancyId = 0;
            Ajancy.Person person = new Ajancy.Person();
            Ajancy.UsersInRole usersInRole = null;
            Ajancy.Ajancy ajancy = new Ajancy.Ajancy();
            Ajancy.BusinessLicense businessLicense = new Ajancy.BusinessLicense();
            db = new Ajancy.Kimia_Ajancy(Public.ConnectionString);

            if (this.ViewState["PersonID"] == null) // Add mode
            {
                Ajancy.User user = new Ajancy.User();
                user.UserName = this.txtNationalCode.Text;
                user.PassWord = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtNationalCode.Text.Trim(), "SHA1");
                user.ProvinceID = Public.ToByte(this.drpProvince.SelectedValue);
                user.CityID = Public.ToShort(this.drpCity.SelectedValue);
                user.SubmitDate = DateTime.Now;
                usersInRole = new Ajancy.UsersInRole { RoleID = (short)Public.Role.AjancyManager, MembershipDate = DateTime.Now };
                usersInRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                user.UsersInRoles.Add(usersInRole);
                person.SubmitDate = DateTime.Now;
                person.User = user;
                db.Persons.InsertOnSubmit(person);
            }
            else if (int.TryParse(this.ViewState["PersonID"].ToString(), out personId)) // Edit person mode
            {
                dlo = new DataLoadOptions();
                dlo.LoadWith<Ajancy.Person>(p => p.User);
                dlo.LoadWith<Ajancy.User>(u => u.UsersInRoles);
                db.LoadOptions = dlo;

                person = db.Persons.First<Ajancy.Person>(p => p.PersonID == personId);
                usersInRole = person.User.UsersInRoles.SingleOrDefault<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.AjancyManager);
                if (usersInRole == null)
                {
                    usersInRole = new Ajancy.UsersInRole { RoleID = (short)Public.Role.AjancyManager, MembershipDate = DateTime.Now };
                    person.User.UsersInRoles.Add(usersInRole);
                }

                if (this.ViewState["AjancyID"] == null)
                {
                    usersInRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                }
            }

            if (this.ViewState["AjancyID"] == null)
            {
                if (db.Ajancies.Any<Ajancy.Ajancy>(j => j.CityID == short.Parse(this.drpCity.SelectedValue) &&
                                                                                j.AjancyType != (byte)Public.AjancyType.Academy &&
                                                                                j.AjancyName.Equals(this.txtAjancyName.Text.Trim())))
                {
                    this.lblMessage.Text = string.Format("آژانسی با نام <b>{0}</b> در شهرستان <b>{1}</b> موجود میباشد", ajancy.AjancyName, this.drpCity.SelectedItem.Text);
                    return;
                }

                var buslic = from j in db.Ajancies
                             join bl in db.BusinessLicenses on j.AjancyID equals bl.AjancyID
                             where bl.BusinessLicenseNo == this.txtBusinessLicenseNo.Text.Trim() &&
                                        j.CityID == Public.ToShort(this.drpCity.SelectedValue)
                             select new { j.AjancyID };
                foreach (var item in buslic)
                {
                    this.lblMessage.Text = string.Format("آژانسی با شماره پروانه کسب <b>{0}</b> در شهرستان <b>{1}</b> موجود میباشد", this.txtBusinessLicenseNo.Text, this.drpCity.SelectedItem.Text);
                    return;
                }

                businessLicense.SubmitDate = DateTime.Now;
                ajancy.BusinessLicenses.Add(businessLicense);
            }
            else if (int.TryParse(this.ViewState["AjancyID"].ToString(), out ajancyId)) // Edit ajancy mode
            {
                if (db.Ajancies.Any<Ajancy.Ajancy>(j => j.CityID == int.Parse(this.drpCity.SelectedValue) && j.AjancyID != ajancyId && j.AjancyName.Equals(this.txtAjancyName.Text.Trim())))
                {
                    this.lblMessage.Text = string.Format("آژانسی با نام <b>{0}</b> در شهرستان <b>{1}</b> موجود میباشد", this.txtAjancyName.Text, this.drpCity.SelectedItem.Text);
                    return;
                }

                var buslic = from j in db.Ajancies
                             join bl in db.BusinessLicenses on j.AjancyID equals bl.AjancyID
                             where bl.BusinessLicenseNo == this.txtBusinessLicenseNo.Text.Trim() &&
                                        j.CityID == Public.ToShort(this.drpCity.SelectedValue) &&
                                        j.AjancyID != ajancyId
                             select new { j.AjancyID };
                foreach (var item in buslic)
                {
                    this.lblMessage.Text = string.Format("آژانسی با شماره پروانه کسب <b>{0}</b> در شهرستان <b>{1}</b> موجود میباشد", this.txtBusinessLicenseNo.Text, this.drpCity.SelectedItem.Text);
                    return;
                }

                ajancy = db.Ajancies.FirstOrDefault<Ajancy.Ajancy>(j => j.AjancyID == ajancyId);
                businessLicense = ajancy.BusinessLicenses.First<Ajancy.BusinessLicense>();
            }

            person.NationalCode = this.txtNationalCode.Text.Trim();
            person.FirstName = this.txtFirstName.Text.Trim();
            person.LastName = this.txtLastName.Text.Trim();
            person.Mobile = this.txtMobile.Text.Trim();
            person.Gender = Public.ToByte(this.drpGender.SelectedValue);

            ajancy.SubmitDate = DateTime.Now;
            ajancy.AjancyType = Public.ToByte(this.drpAjancyType.SelectedValue);
            ajancy.AjancyName = this.txtAjancyName.Text.Trim();
            ajancy.CityID = Public.ToShort(this.drpCity.SelectedValue);
            ajancy.BusinessLicenseType = Public.ToByte(this.drpBusinessLicenseType.SelectedValue);
            ajancy.PostalCode = this.txtPlacePostalCode.Text.Trim();
            ajancy.Address = this.txtPlaceAddress.Text.Trim();
            ajancy.Phone = this.txtBusinessPlacePhone.Text.Trim();
            businessLicense.BusinessLicenseNo = this.txtBusinessLicenseNo.Text.Trim();

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