protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int ajancyComplaintId = 0; if (int.TryParse(Request.QueryString["id"], out ajancyComplaintId) && Request.QueryString["txt"] != null) { db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); Ajancy.AjancyComplaint complaint = db.AjancyComplaints.FirstOrDefault<Ajancy.AjancyComplaint>(jc => jc.AjancyComplaintID == ajancyComplaintId); complaint.Reply = Request.QueryString["txt"].Length > 200 ? Request.QueryString["txt"].Substring(0, 200) : Request.QueryString["txt"]; complaint.ReplyDate = DateTime.Now; db.SubmitChanges(); DisposeContext(); Response.Clear(); Response.Write("1"); Response.End(); } else if (int.TryParse(Request.QueryString["id"], out ajancyComplaintId) && Request.QueryString["txt"] == null) { db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); Ajancy.AjancyComplaint complaint = db.AjancyComplaints.FirstOrDefault<Ajancy.AjancyComplaint>(jc => jc.AjancyComplaintID == ajancyComplaintId); DisposeContext(); Response.Clear(); Response.Write(complaint == null ? null : complaint.Reply); Response.End(); } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int personId = 0; if (Request.QueryString["id"] != null && int.TryParse(TamperProofString.QueryStringDecode(Request.QueryString["id"]), out personId)) { Ajancy.Kimia_Ajancy db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); DataLoadOptions dlo = new DataLoadOptions(); dlo.LoadWith<Ajancy.Person>(p => p.DrivingLicenses); 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.PlateNumber); dlo.LoadWith<Ajancy.CarPlateNumber>(cpn => cpn.Car); dlo.LoadWith<Ajancy.Car>(c => c.FuelCards); dlo.LoadWith<Ajancy.Car>(c => c.CarType); db.LoadOptions = dlo; SetPerson(db.Persons.FirstOrDefault<Ajancy.Person>(p => p.PersonID == personId)); db.Dispose(); } else { Response.Redirect("~/Default.aspx"); } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int commentId = 0; if (Request.QueryString["mode"] != null) { switch (Request.QueryString["mode"]) { case "0": // Delete mode if (int.TryParse(Request.QueryString["id"], out commentId)) { db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); db.Comments.DeleteOnSubmit(db.Comments.First<Ajancy.Comment>(c => c.CommentID == commentId)); db.SubmitChanges(); DisposeContext(); Response.Clear(); Response.Write("1"); Response.End(); } break; } } } }
protected void fluDocument_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e) { if (this.fluDocument.HasFile) { if (this.fluDocument.PostedFile.ContentType.Equals("image/pjpeg") || this.fluDocument.PostedFile.ContentType.Equals("image/x-png")) { byte[] fileByte = this.fluDocument.FileBytes; Binary binaryObj = new Binary(fileByte); Ajancy.Kimia_Ajancy db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); Ajancy.Doument doc = db.Douments.FirstOrDefault<Ajancy.Doument>(d => d.PersonID == Public.ActiveUserRole.User.PersonID && d.DocumentType == 1); if (doc == null) { doc = new Ajancy.Doument { DocumentType = Public.ToByte(this.drpType.SelectedValue), PersonID = Public.ActiveUserRole.User.PersonID, Picture = binaryObj, SubmitDate = DateTime.Now }; db.Douments.InsertOnSubmit(doc); } else { doc.Picture = binaryObj; } db.SubmitChanges(); db.Dispose(); } } }
protected void btnSave_Click(object sender, EventArgs e) { int personId = 0; if (this.Page.IsValid && int.TryParse(TamperProofString.QueryStringDecode(Request.QueryString["id"]), out personId)) { DataLoadOptions dlo = new DataLoadOptions(); dlo.LoadWith<Ajancy.Person>(p => p.User); db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); db.LoadOptions = dlo; Ajancy.Person person = db.Persons.First<Ajancy.Person>(p => p.PersonID == personId); if (person.NationalCode != this.txtNationalCode.Text.Trim()) // Nationalcode is changed { person.NationalCode = this.txtNationalCode.Text; person.User.UserName = this.txtNationalCode.Text; } person.User.ProvinceID = Public.ToByte(this.drpProvince.SelectedValue); person.User.CityID = Public.ToShort(this.drpCity.SelectedValue); 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; 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(); try { db.SubmitChanges(); DisposeContext(); Response.Redirect("~/Message.aspx?mode=17"); } catch (Exception ex) { if (ex.Message.Contains("duplicate key")) { this.lblMessage.Text = "کد ملی تکراری میباشد"; } } } }
protected void btnChangePassword_Click(object sender, EventArgs e) { if (this.Page.IsValid) { db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); db.Users.First<Ajancy.User>(u => u.UserID == Public.ToInt(this.ViewState["UserID"])).PassWord = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtPassword.Text, "SHA1"); db.SubmitChanges(); this.btnBack_Click(sender, e); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Ajancy.Kimia_Ajancy db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); this.drpAjancies.DataSource = db.Ajancies.Where(aj => aj.AjancyType == (byte)Public.AjancyType.TaxiAjancy && aj.AjancyName != null).OrderBy(j => j.AjancyName).Select(aj => new { aj.AjancyID, aj.AjancyName }); this.drpAjancies.DataBind(); this.drpAjancies.Items.Insert(0, "- همه آژانس ها -"); this.drpCarType.DataSource = db.CarTypes; this.drpCarType.DataBind(); this.drpCarType.Items.Insert(0, "- همه موارد -"); db.Dispose(); } }
protected void btnSearch_Click(object sender, EventArgs e) { db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); var query = from jd in db.AjancyDrivers join c in db.AjancyComplaints on jd.AjancyDriverID equals c.AjancyDriverID join dcc in db.DriverCertificationCars on jd.DriverCertificationCarID equals dcc.DriverCertificationCarID join dc in db.DriverCertifications on dcc.DriverCertificationID equals dc.DriverCertificationID join p in db.Persons on dc.PersonID equals p.PersonID join j in db.Ajancies on jd.AjancyID equals j.AjancyID where j.AjancyID == Public.ActiveAjancy.AjancyID && (c.RoleID == (byte)(Public.Role.AjancyManager) || c.RoleID == (byte)(Public.Role.AjancySupervisor)) select new { p.FirstName, p.LastName, p.NationalCode, Gender = p.Gender == 0 ? "مرد" : "زن", dc.DriverCertificationNo, c.AjancyComplaintID, c.RoleID, c.SubmitDate, c.Comment, c.ReplyDate, j.AjancyName }; if (this.drpReplyMode.SelectedIndex == 0) { query = from q in query where q.ReplyDate != null select q; } else { query = from q in query where q.ReplyDate == null select q; } if (this.txtDateFrom.HasDate && this.txtDateTo.HasDate) { query = from q in query where q.SubmitDate >= this.txtDateFrom.GeorgianDate && q.SubmitDate <= this.txtDateTo.GeorgianDate select q; } this.lstComplaints.DataSource = query; this.lstComplaints.DataBind(); }
protected void drpProvince_SelectedIndexChanged(object sender, EventArgs e) { if (this.drpProvince.SelectedIndex > 0) { Ajancy.Kimia_Ajancy db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); this.drpCity.DataSource = db.Cities.Where<Ajancy.City>(c => c.ProvinceID == Public.ToByte(this.drpProvince.SelectedValue)).Select(c => new { c.CityID, c.Name }); this.drpCity.DataBind(); } else { this.drpCity.Items.Clear(); } this.drpCity.Items.Insert(0, "- انتخاب کنید -"); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int fcsId; if (int.TryParse(Request.QueryString["fcsId"], out fcsId)) { db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); db.FuelCardSubstitutions.DeleteOnSubmit(db.FuelCardSubstitutions.First<Ajancy.FuelCardSubstitution>(fcs => fcs.FuelCardSubstituteID == fcsId)); db.SubmitChanges(); DisposeContext(); Response.Clear(); Response.Write("1"); Response.End(); } Ajancy.User user = Public.ActiveUserRole.User; this.drpProvince.SelectedValue = user.ProvinceID.ToString(); this.drpProvince_SelectedIndexChanged(sender, e); this.drpCity.SelectedValue = user.CityID.ToString(); switch ((Public.Role)Public.ActiveUserRole.RoleID) { case Public.Role.Admin: this.drpProvince.Enabled = true; this.drpCity.Enabled = true; this.drpAjancyType.Enabled = true; break; case Public.Role.CityManager: this.drpAjancyType.SelectedIndex = 0; break; case Public.Role.ProvinceManager: this.drpCity.Enabled = true; this.drpAjancyType.SelectedIndex = 0; break; case Public.Role.AcademyCity: this.drpAjancyType.SelectedIndex = 2; break; case Public.Role.AcademyProvince: this.drpCity.Enabled = true; this.drpAjancyType.SelectedIndex = 2; break; } } }
private void LoadAjancies() { if (this.drpAjancyType.SelectedIndex > 0) { this.drpAjancies.Items.Clear(); db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); this.drpAjancies.DataSource = db.Ajancies.Where(aj => aj.AjancyType == Public.ToByte(this.drpAjancyType.SelectedValue)).Select(aj => new { aj.AjancyID, aj.AjancyName }); this.drpAjancies.DataBind(); this.drpAjancies.Items.Insert(0, new System.Web.UI.WebControls.ListItem("- انتخاب کنید -", "0")); } else { this.drpAjancies.Items.Clear(); this.drpAjancies.Items.Insert(0, new System.Web.UI.WebControls.ListItem("- انتخاب کنید -", "0")); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int ajancyComplaintId = 0; if (int.TryParse(Request.QueryString["id"], out ajancyComplaintId)) { db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); Ajancy.AjancyComplaint complaint = db.AjancyComplaints.FirstOrDefault<Ajancy.AjancyComplaint>(jc => jc.AjancyComplaintID == ajancyComplaintId); DisposeContext(); Response.Clear(); Response.Write(complaint == null ? null : complaint.Reply); Response.End(); } } }
protected void btnSave_Click(object sender, EventArgs e) { if (this.Page.IsValid && this.ViewState["UserID"] != null) { byte selectedRoleId = byte.Parse(this.drpRoles.SelectedValue); ListItem item = null; db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); Ajancy.User user = db.Users.First<Ajancy.User>(u => u.UserID == Public.ToInt(this.ViewState["UserID"])); Ajancy.UsersInRole userRole = new Ajancy.UsersInRole { RoleID = selectedRoleId, MembershipDate = DateTime.Now }; ; user.UsersInRoles.Add(userRole); switch ((Public.Role)selectedRoleId) { case Public.Role.AjancyManager: case Public.Role.AjancySupervisor: case Public.Role.AjancySecretary: case Public.Role.AjancyPartner: Ajancy.AjancyPartner partner = new Ajancy.AjancyPartner { SubmitDate = DateTime.Now }; userRole.AjancyPartners.Add(partner); db.SubmitChanges(); item = new ListItem(string.Format("{0} {1}", Public.GetRoleName(userRole.RoleID), "---"), string.Format("{0}|{1}", userRole.UserRoleID, partner.AjancyPartnerID)); break; case Public.Role.ProvinceManager: case Public.Role.AcademyProvince: db.SubmitChanges(); item = new ListItem(string.Format("{0} {1}", Public.GetRoleName(selectedRoleId), user.City.Province.Name), string.Format("{0}|0", userRole.UserRoleID)); break; case Public.Role.CityManager: case Public.Role.AcademyCity: db.SubmitChanges(); item = new ListItem(string.Format("{0} {1}", Public.GetRoleName(selectedRoleId), user.City.Name), string.Format("{0}|0", userRole.UserRoleID)); break; default: db.SubmitChanges(); item = new ListItem(Public.GetRoleName(selectedRoleId), string.Format("{0}|0", userRole.UserRoleID)); break; } item.Selected = true; this.lstRoles.Items.Add(item); this.drpRoles.Items.Remove(this.drpRoles.SelectedItem); this.lblMessage.Text = "ثبت سمت انجام گردید"; } }
protected void btnSave_Click(object sender, EventArgs e) { if (this.Page.IsValid) { int carId = Public.ToInt(this.drpCars.SelectedValue); db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); db.FuelCards.First<Ajancy.FuelCard>(fc => fc.CarID == carId && fc.DiscardDate == null).DiscardDate = DateTime.Now; db.FuelCards.InsertOnSubmit(new Ajancy.FuelCard { CarID = carId , CardType = Public.ToByte(this.drpFuelCardType.SelectedValue) , PAN = this.txtFuelCardPAN.Text.Trim() , SubmitDate = DateTime.Now }); try { db.SubmitChanges(); DisposeContext(); this.drpCars_SelectedIndexChanged(sender, e); this.lblMessage.Text = Public.SAVEMESSAGE; this.drpFuelCardType.SelectedIndex = 0; this.txtFuelCardPAN.Text = null; } catch (Exception ex) { if (ex.Message.Contains("UNIQUE KEY")) { this.lblMessage.Text = "شماره PAN کارت سوخت قبلا برای خودرو دیگری ثبت شده"; } else { throw ex; } } } }
protected void lstRoles_SelectedIndexChanged(object sender, EventArgs e) { db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); foreach (ListItem item in this.lstRoles.Items) { string[] roleParts = item.Value.Split('|'); if (roleParts[1] == "0") { Ajancy.UsersInRole userRole = db.UsersInRoles.First<Ajancy.UsersInRole>(ur => ur.UserRoleID == Public.ToInt(roleParts[0])); if (item.Selected && userRole.LockOutDate.HasValue) // unlock this role { userRole.LockOutDate = null; db.SubmitChanges(); break; } else if (!item.Selected && !userRole.LockOutDate.HasValue) // lock this role { userRole.LockOutDate = DateTime.Now; db.SubmitChanges(); break; } } else if (roleParts.Length == 2) // Ajancy partners { Ajancy.AjancyPartner partner = db.AjancyPartners.First<Ajancy.AjancyPartner>(jp => jp.AjancyPartnerID == Public.ToInt(roleParts[1])); if (item.Selected && partner.LockOutDate.HasValue) // unlock this role { partner.LockOutDate = null; db.SubmitChanges(); break; } else if (!item.Selected && !partner.LockOutDate.HasValue) // lock this role { partner.LockOutDate = DateTime.Now; db.SubmitChanges(); break; } } } }
protected void btnSave_Click(object sender, EventArgs e) { if (this.Page.IsValid) { Ajancy.Kimia_Ajancy db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); Ajancy.User user = db.Users.FirstOrDefault<Ajancy.User>(u => u.UserName == HttpContext.Current.User.Identity.Name && u.PassWord == FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtOldPassword.Text, "SHA1")); if (user != null) { user.PassWord = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtNewPassword.Text, "SHA1"); db.SubmitChanges(); db.Dispose(); this.lblMessage.Text = "ویرایش گذرواژه انجام گردید"; } else { this.lblMessage.Text = "گذرواژه نادرست میباشد"; } } this.txtOldPassword.Text = null; this.txtNewPassword.Text = null; this.txtRePassword.Text = null; }
protected void btnSave_Click(object sender, EventArgs e) { if (Page.IsValid && this.ViewState["AjancyDriverID"] != null) { string[] vals = this.ViewState["AjancyDriverID"].ToString().Split('|'); if (vals[1] == this.drpAjancies.SelectedValue) // No new ajancy is selected { return; } db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); Ajancy.AjancyDriver ajancyDriver = db.AjancyDrivers.First<Ajancy.AjancyDriver>(jd => jd.AjancyDriverID == Public.ToInt(vals[0])); ajancyDriver.LockOutDate = DateTime.Now; db.AjancyDrivers.InsertOnSubmit(new Ajancy.AjancyDriver { AjancyID = Public.ToInt(this.drpAjancies.SelectedValue), DriverCertificationCarID = ajancyDriver.DriverCertificationCarID, MembershipDate = DateTime.Now }); db.SubmitChanges(); this.lblMessage.Text = Public.SAVEMESSAGE; this.ViewState["AjancyDriverID"] = null; this.txtNationalCode.Text = null; this.drpAjancies.Items.Clear(); this.drpAjancies.Enabled = false; this.btnSave.Enabled = false; } }
protected void btnSave_Click(object sender, EventArgs e) { if (Page.IsValid) { Ajancy.Comment comment = new Ajancy.Comment(); comment.DriverFirstName = this.txtDriverFirstName.Text; comment.DriverLastName = this.txtDriverLastName.Text; comment.FirstName = this.txtFirstName.Text; comment.LastName = this.txtLastName.Text; comment.Phone = this.txtPhone.Text; comment.Email = this.txtEmail.Text; comment.AjancyID = Public.ToInt(this.drpAjancies.SelectedValue); comment.Subject = Public.ToByte(this.drpSubject.SelectedValue); comment.ProblemDate = new DateTime(this.txtProblemDate.GeorgianDate.Value.Year, this.txtProblemDate.GeorgianDate.Value.Month, this.txtProblemDate.GeorgianDate.Value.Day, this.txtTime.Time.Hours, this.txtTime.Time.Minutes, 0); comment.CommentText = this.txtComment.Text; comment.SubmitDate = DateTime.Now; db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); if (!string.IsNullOrEmpty(this.txtCarPlateNumber_1.Text) && !string.IsNullOrEmpty(this.txtCarPlateNumber_2.Text) && !string.IsNullOrEmpty(this.txtCarPlateNumber_3.Text)) { Ajancy.PlateNumber plateNumber = db.PlateNumbers.FirstOrDefault<Ajancy.PlateNumber>(pn => pn.TwoDigits == this.txtCarPlateNumber_1.Text && pn.Alphabet == this.drpCarPlateNumber.SelectedValue && pn.ThreeDigits == this.txtCarPlateNumber_3.Text && pn.RegionIdentifier == this.txtCarPlateNumber_3.Text); if (plateNumber == null) { this.lblMessage.Text = "کابر گرامی شماره پلاک مورد نظر شما متعلق به رانندگان این اتحادیه نمیباشد در صورت اطمینان از درست بودن شماره پلاک در قسمت توضیحات آنرا بنویسید"; return; } comment.PlateNumberID = plateNumber.PlateNumberID; } db.Comments.InsertOnSubmit(comment); db.SubmitChanges(); Response.Redirect("~/Default.aspx"); } }
private void FillGrid() { db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); var query = from c in db.Comments join j in db.Ajancies on c.AjancyID equals j.AjancyID select new { j.AjancyName, c.CommentID, c.Subject, c.DriverFirstName, c.DriverLastName, c.FirstName, c.LastName, c.Phone, c.PlateNumber, c.ProblemDate, c.Email, c.CommentText, c.SubmitDate }; if (this.txtDateFrom.HasDate) { query = from q in query where q.SubmitDate >= this.txtDateFrom.GeorgianDate select q; } if (this.txtDateFrom.HasDate && this.txtDateTo.HasDate) { query = from q in query where q.SubmitDate <= this.txtDateTo.GeorgianDate select q; } this.lstComplaints.DataSource = query; this.lstComplaints.DataBind(); }
protected void drpCars_SelectedIndexChanged(object sender, EventArgs e) { if (this.drpCars.SelectedIndex > 0) { db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); var fcList = db.FuelCards.Where(fc => fc.CarID == Public.ToInt(this.drpCars.SelectedValue)).Select(fc => new { fc.CardType, fc.PAN, fc.DiscardDate }); string _html = "<table id='list'>"; _html += "<tr>"; _html += "<th style='width: 20px;'></th>"; _html += "<th>PAN</th>"; _html += "<th>نوع کارت سوخت</th>"; _html += "<th></th>"; _html += "</tr>"; string color = "#ffffff"; byte counter = 1; foreach (var item in fcList) { _html += string.Format("<tr style='background-color: {0};'><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td></tr>", color, counter, item.PAN, Public.GetFuelCardTypeName((Public.FuelCardType)item.CardType), item.DiscardDate == null ? "فعال" : "غیرفعال"); if (counter % 2 == 1) // change color for alternative row { color = "#f8faff"; } else { color = "#ffffff"; } counter++; } _html += "</table>"; this.dvFCcontainer.InnerHtml = _html; } else { this.dvFCcontainer.InnerHtml = null; } }
protected void btnSave_Click(object sender, EventArgs e) { if (this.Page.IsValid && this.ViewState["DCID"] != null) { DataLoadOptions dlo = new DataLoadOptions(); dlo.LoadWith<Ajancy.PlateNumber>(pl => pl.CarPlateNumbers); dlo.LoadWith<Ajancy.CarPlateNumber>(cpn => cpn.DriverCertificationCars); db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); db.LoadOptions = dlo; 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; } int driverCertificationId = Public.ToInt(this.ViewState["DCID"]); Ajancy.DriverCertification driverCertification = db.DriverCertifications.First<Ajancy.DriverCertification>(dc => dc.DriverCertificationID == driverCertificationId); Ajancy.DriverCertificationCar lastDCC = driverCertification.DriverCertificationCars.Last<Ajancy.DriverCertificationCar>(); Ajancy.ZonePlateNumber pln = db.ZonePlateNumbers.FirstOrDefault<Ajancy.ZonePlateNumber>(pl => pl.CityID == Public.ToShort(this.drpCarPlateNumberCity.SelectedValue) && pl.Number == this.txtCarPlateNumber_5.Text.Trim()); if (pln != null && pln.ZonePlateNumberID != lastDCC.CarPlateNumber.ZonePlateNumberID) { foreach (Ajancy.CarPlateNumber cpn in pln.CarPlateNumbers) { foreach (Ajancy.DriverCertificationCar dcc in cpn.DriverCertificationCars) { if (dcc.LockOutDate == null) { this.lblMessage.Text = "شماره پلاک وارد شده متعلق به شخص دیگری میباشد"; return; } } } } Ajancy.Car car = new Ajancy.Car { CarTypeID = Public.ToShort(this.drpCarType.SelectedValue), FuelType = Public.ToByte(this.drpFuelType.SelectedValue), Model = this.txtCarModel.Text, VIN = this.txtCarVIN.Text.Trim().ToUpper() }; car.FuelCards.Add(new Ajancy.FuelCard { CardType = (byte)Public.FuelCardType.Ajancy, PAN = this.txtFuelCardPAN.Text.Trim(), SubmitDate = DateTime.Now }); Ajancy.CarPlateNumber carPlateNumber = new Ajancy.CarPlateNumber { OwnerPersonID = driverCertification.PersonID, Car = car, ZonePlateNumber = pln != null ? pln : new Ajancy.ZonePlateNumber { CityID = Public.ToShort(this.drpCarPlateNumberCity.SelectedValue), Number = this.txtCarPlateNumber_5.Text.Trim() } }; if (lastDCC.LockOutDate == null) { lastDCC.LockOutDate = DateTime.Now; lastDCC.AjancyDrivers.Last<Ajancy.AjancyDriver>().LockOutDate = DateTime.Now; lastDCC.CarPlateNumber.Car.FuelCards.Last<Ajancy.FuelCard>().DiscardDate = DateTime.Now; } Ajancy.DriverCertificationCar 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); db.SubmitChanges(); this.lblMessage.Text = Public.SAVEMESSAGE; this.ClearControls(false); this.LoadDriverCars(driverCertificationId, db); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int personId = 0; if (int.TryParse(TamperProofString.QueryStringDecode(Request.QueryString["id"]), out personId)) // Edit mode { switch (Public.ActiveUserRole.RoleID) { case (short)Public.Role.Admin: this.drpProvince.Enabled = true; this.drpCity.Enabled = true; break; case (short)Public.Role.ProvinceManager: this.drpCity.Enabled = true; break; } DataLoadOptions dlo = new DataLoadOptions(); dlo.LoadWith<Ajancy.Person>(p => p.User); db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); db.LoadOptions = dlo; SetPerson(db.Persons.FirstOrDefault<Ajancy.Person>(p => p.PersonID == personId)); } else { DisposeContext(); Response.Redirect("~/Management/UsersList.aspx"); } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); if (Request.QueryString["mode"] != null) { int ajancyDriverId = 0; switch (Request.QueryString["mode"]) { case "0": // Complaint if (int.TryParse(Request.QueryString["jdId"], out ajancyDriverId) && Request.QueryString["text"] != null) { db.AjancyComplaints.InsertOnSubmit(new Ajancy.AjancyComplaint { AjancyDriverID = ajancyDriverId, RoleID = Public.ActiveUserRole.RoleID, Comment = Request.QueryString["text"].Length > 200 ? Request.QueryString["text"].Substring(0, 200) : Request.QueryString["text"], SubmitDate = DateTime.Now }); db.SubmitChanges(); DisposeContext(); Response.Clear(); Response.Write("1"); Response.End(); } break; case "1": // CNG if (int.TryParse(Request.QueryString["jdId"], out ajancyDriverId) && Request.QueryString["text"] != null) { db.CNG_ConsumptionRequests.InsertOnSubmit(new Ajancy.CNG_ConsumptionRequest { AjancyDriverID = ajancyDriverId, Comment = string.IsNullOrEmpty(Request.QueryString["text"]) ? null : Request.QueryString["text"].Length > 200 ? Request.QueryString["text"].Substring(0, 200) : Request.QueryString["text"], SubmitDate = DateTime.Now }); db.SubmitChanges(); DisposeContext(); Response.Clear(); Response.Write("1"); Response.End(); } break; //case "2": // ajancyCardType // if (int.TryParse(Request.QueryString["jdId"], out ajancyDriverId) && Request.QueryString["text"] != null) // { // db.AjancyFuelCardTypeRequests.InsertOnSubmit(new Ajancy.AjancyFuelCardTypeRequest { AjancyDriverID = ajancyDriverId, Comment = string.IsNullOrEmpty(Request.QueryString["text"]) ? null : Request.QueryString["text"].Length > 200 ? Request.QueryString["text"].Substring(0, 200) : Request.QueryString["text"], SubmitDate = DateTime.Now }); // db.SubmitChanges(); // Response.Clear(); // Response.Write("1"); // Response.End(); // } // break; case "3": // Insurance if (int.TryParse(Request.QueryString["jdId"], out ajancyDriverId) && Request.QueryString["text"] != null) { db.DriverInsuranceRequests.InsertOnSubmit(new Ajancy.DriverInsuranceRequest { AjancyDriverID = ajancyDriverId, Comment = string.IsNullOrEmpty(Request.QueryString["text"]) ? null : Request.QueryString["text"].Length > 200 ? Request.QueryString["text"].Substring(0, 200) : Request.QueryString["text"], SubmitDate = DateTime.Now }); db.SubmitChanges(); DisposeContext(); Response.Clear(); Response.Write("1"); Response.End(); } break; case "4": // End Membership if (int.TryParse(Request.QueryString["jdId"], out ajancyDriverId) && Request.QueryString["text"] != null) { db.DriverEndMembershipRequests.InsertOnSubmit(new Ajancy.DriverEndMembershipRequest { AjancyDriverID = ajancyDriverId, RoleID = Public.ActiveUserRole.RoleID, Comment = Request.QueryString["text"].Length > 200 ? Request.QueryString["text"].Substring(0, 200) : Request.QueryString["text"], SubmitDate = DateTime.Now, Confirmed = false }); db.SubmitChanges(); DisposeContext(); Response.Clear(); Response.Write("1"); Response.End(); } break; } } this.drpCarType.DataSource = db.CarTypes; this.drpCarType.DataBind(); this.drpCarType.Items.Insert(0, "- همه موارد -"); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Public.ActiveUserRole.RoleID == (short)Public.Role.AjancyManager && Public.ActiveAjancy.AjancyID == 0) { DisposeContext(); Response.Redirect("~/Message.aspx?mode=8"); } else if ((Public.ActiveUserRole.RoleID == (short)Public.Role.Admin || Public.ActiveUserRole.RoleID == (short)Public.Role.CityManager || Public.ActiveUserRole.RoleID == (short)Public.Role.ProvinceManager) && Request.QueryString["id"] == null) { DisposeContext(); Response.Redirect("~/Default.aspx"); } int personId = 0; db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); this.drpCarType.DataSource = db.CarTypes.OrderBy(ct => ct.TypeName); this.drpCarType.DataBind(); this.drpCarType.Items.Insert(0, new System.Web.UI.WebControls.ListItem("- انتخاب کنید -", "0")); if (Request.QueryString["id"] != null && int.TryParse(TamperProofString.QueryStringDecode(Request.QueryString["id"]), out personId)) { dlo = new DataLoadOptions(); dlo.LoadWith<Ajancy.Person>(p => p.DrivingLicenses); 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.PlateNumber); dlo.LoadWith<Ajancy.CarPlateNumber>(cpn => cpn.Car); dlo.LoadWith<Ajancy.Car>(c => c.FuelCards); dlo.LoadWith<Ajancy.Car>(c => c.CarType); db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); db.LoadOptions = dlo; SetPerson(db.Persons.FirstOrDefault<Ajancy.Person>(p => p.PersonID == personId)); this.txtNationalCode.ReadOnly = true; } //this.drpFormerCarType.DataSource = cars; //this.drpFormerCarType.DataBind(); //this.drpFormerCarType.Items.Insert(0, new System.Web.UI.WebControls.ListItem("- انتخاب کنید -", "0")); } }
protected void txtNationalCode_TextChanged(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.txtNationalCode.Text)) { db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); DataLoadOptions dlo = new DataLoadOptions(); dlo.LoadWith<Ajancy.Person>(p => p.DriverCertifications); db.LoadOptions = dlo; Ajancy.Person person = db.Persons.FirstOrDefault<Ajancy.Person>(p => p.NationalCode == this.txtNationalCode.Text.Trim()); if (person != null) { if (person.DriverCertifications.Any<Ajancy.DriverCertification>(dc => dc.CertificationType == Public.ActiveAjancy.AjancyType)) { // This person already has DriverCertification DisposeContext(); Response.Redirect("~/Message.aspx?mode=5", true); } } SetPerson(person); } this.txtFirstName.Focus(); }
protected void btnSave_Click(object sender, EventArgs e) { if (Page.IsValid) { 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.DrivingLicense drivingLicense = new Ajancy.DrivingLicense(); 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(); Ajancy.Car car_db = null; if (this.ViewState["PersonID"] == null) // New Person { car_db = db.Cars.FirstOrDefault<Ajancy.Car>(c => c.EngineNo == this.txtCarEngineNo.Text.Trim() && c.ChassisNo == this.txtCarChassisNo.Text.Trim()); if (car_db != null) { foreach (var cpn in car_db.CarPlateNumbers) { foreach (var dcc in cpn.DriverCertificationCars) { if (dcc.LockOutDate == null) { this.lblMessage.Text = "خودرو مورد نظر با این شماره موتور و شماره شاسی متعلق به شخص دیگری میباشد"; return; } } } car = car_db; } else { db.Cars.InsertOnSubmit(car); } 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) { foreach (Ajancy.CarPlateNumber cpn in pln.CarPlateNumbers) { foreach (var dcc in cpn.DriverCertificationCars) { if (dcc.LockOutDate == null) { this.lblMessage.Text = "شماره پلاک وارد شده متعلق به شخص دیگری میباشد"; return; } } } } Ajancy.User user = new Ajancy.User(); user.UserName = this.txtNationalCode.Text.Trim(); user.ProvinceID = Public.ActiveUserRole.User.ProvinceID; user.CityID = Public.ActiveUserRole.User.CityID; 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.CertificationType = (byte)Public.AjancyType.TaxiAjancy; driverCertification.SubmitDate = DateTime.Now; carPlateNumber = new Ajancy.CarPlateNumber { Car = car, PlateNumber = plateNumber, Person = person }; driverCertificationCar = new Ajancy.DriverCertificationCar { CarPlateNumber = carPlateNumber, SubmitDate = DateTime.Now }; driverCertification.DriverCertificationCars.Add(driverCertificationCar); person.DrivingLicenses.Add(drivingLicense); person.DriverCertifications.Add(driverCertification); fuelCard.SubmitDate = DateTime.Now; car.FuelCards.Add(fuelCard); db.CarPlateNumbers.InsertOnSubmit(carPlateNumber); db.AjancyDrivers.InsertOnSubmit(new Ajancy.AjancyDriver { AjancyID = Public.ActiveAjancy.AjancyID, DriverCertificationCar = driverCertificationCar, MembershipDate = DateTime.Now }); 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>(); carPlateNumber = driverCertificationCar.CarPlateNumber; plateNumber = carPlateNumber.PlateNumber; car = carPlateNumber.Car; //fuelCard = car.FuelCards.First<Ajancy.FuelCard>(fc => fc.DiscardDate == null); fuelCard = car.FuelCards.Last<Ajancy.FuelCard>(); drivingLicense = person.DrivingLicenses.LastOrDefault<Ajancy.DrivingLicense>(); if (drivingLicense == null) { drivingLicense = new Ajancy.DrivingLicense(); person.DrivingLicenses.Add(drivingLicense); } car_db = db.Cars.FirstOrDefault<Ajancy.Car>(c => c.EngineNo == this.txtCarEngineNo.Text.Trim() && c.ChassisNo == this.txtCarChassisNo.Text.Trim() && c.CarID != carPlateNumber.Car.CarID); if (car_db != null) { foreach (var cpn in car_db.CarPlateNumbers) { foreach (var dcc in cpn.DriverCertificationCars) { if (dcc.LockOutDate == null) { this.lblMessage.Text = "خودرو مورد نظر با این شماره موتور و شماره شاسی متعلق به شخص دیگری میباشد"; return; } } } carPlateNumber.Car = car_db; } 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) { foreach (Ajancy.CarPlateNumber cpn in pln.CarPlateNumbers) { foreach (var dcc in cpn.DriverCertificationCars) { if (dcc.LockOutDate == null) { this.lblMessage.Text = "شماره پلاک وارد شده متعلق به شخص دیگری میباشد"; return; } } } } } else // Person is not driver { car_db = db.Cars.FirstOrDefault<Ajancy.Car>(c => c.EngineNo == this.txtCarEngineNo.Text.Trim() && c.ChassisNo == this.txtCarChassisNo.Text.Trim()); if (car_db != null) { foreach (var cpn in car_db.CarPlateNumbers) { foreach (var dcc in cpn.DriverCertificationCars) { if (dcc.LockOutDate == null) { this.lblMessage.Text = "خودرو مورد نظر با این شماره موتور و شماره شاسی متعلق به شخص دیگری میباشد"; return; } } } car = car_db; } else { db.Cars.InsertOnSubmit(car); } 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) { foreach (Ajancy.CarPlateNumber cpn in pln.CarPlateNumbers) { foreach (var dcc in cpn.DriverCertificationCars) { if (dcc.LockOutDate == null) { this.lblMessage.Text = "شماره پلاک وارد شده متعلق به شخص دیگری میباشد"; return; } } } } person.User.UsersInRoles.Add(new Ajancy.UsersInRole { RoleID = (short)Public.Role.TaxiDriver, MembershipDate = DateTime.Now }); driverCertification.CertificationType = (byte)Public.AjancyType.TaxiAjancy; driverCertification.SubmitDate = DateTime.Now; carPlateNumber = new Ajancy.CarPlateNumber { Car = car, PlateNumber = plateNumber, Person = person }; driverCertificationCar = new Ajancy.DriverCertificationCar { CarPlateNumber = carPlateNumber, SubmitDate = DateTime.Now }; driverCertification.DriverCertificationCars.Add(driverCertificationCar); person.DriverCertifications.Add(driverCertification); person.DrivingLicenses.Add(drivingLicense); fuelCard.SubmitDate = DateTime.Now; car.FuelCards.Add(fuelCard); db.CarPlateNumbers.InsertOnSubmit(carPlateNumber); db.AjancyDrivers.InsertOnSubmit(new Ajancy.AjancyDriver { AjancyID = Public.ActiveAjancy.AjancyID, DriverCertificationCar = driverCertificationCar, MembershipDate = DateTime.Now }); } } // --------- setting other values person.SubmitDate = DateTime.Now; 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(); //person.FormerJob = this.txtFormerJob.Text.Trim(); //person.FormerJobType = Public.ToByte(this.drpFormerJobType.SelectedValue); 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(); drivingLicense.DrivingLicenseNo = this.txtDrivingLicenseNo.Text.Trim(); drivingLicense.ExportDate = this.txtDrivingLicenseDate.GeorgianDate.Value; drivingLicense.ExportPlace = this.txtDrivingLicensePlace.Text.Trim(); drivingLicense.Type = Public.ToByte(this.drpDrivingLicenseType.SelectedValue); //if (!string.IsNullOrEmpty(this.txtDriverCertificationNo.Text)) //{ // if (db.DriverCertifications.Any<Ajancy.DriverCertification>(dc => dc.DriverCertificationNo == this.txtDriverCertificationNo.Text)) // { // this.lblMessage.Text = "شماره دفترچه صلاحیت تکراری میباشد"; // return; // } //} driverCertification.DriverCertificationNo = string.IsNullOrEmpty(this.txtDriverCertificationNo.Text) ? null : this.txtDriverCertificationNo.Text.Trim(); car.CarTypeID = Public.ToByte(this.drpCarType.SelectedValue); car.Model = this.txtCarModel.Text.Trim(); car.Color = this.txtCarColor.Text.Trim(); car.EngineNo = this.txtCarEngineNo.Text.Trim(); car.ChassisNo = this.txtCarChassisNo.Text.Trim(); car.GASProvider = Public.ToByte(this.drpGASProvider.SelectedValue); car.FuelType = Public.ToByte(this.drpFuelType.SelectedValue); fuelCard.CardType = Public.ToByte(this.drpFuelCardType.SelectedValue); fuelCard.PAN = this.txtFuelCardPAN.Text.Trim(); car.VIN = this.txtCarVIN.Text.Trim().ToUpper(); // Sets the owner of the car Ajancy.Person ownerPer = 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)) { 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(); person.CarPlateNumbers.Remove(carPlateNumber); ownerPer.CarPlateNumbers.Add(carPlateNumber); } else if (carPlateNumber.OwnerPersonID > 0 && carPlateNumber.OwnerPersonID != person.PersonID) // Set the driver as owner again { carPlateNumber.Person = person; } #endregion try { db.SubmitChanges(); if (Request.QueryString["id"] == null) { DisposeContext(); Response.Redirect("~/Message.aspx?mode=12"); } else // edit mode { DisposeContext(); Response.Redirect("~/Message.aspx?mode=7"); } } catch (Exception ex) { if (ex.Message.Contains("DrivingLicenseNo")) { this.lblMessage.Text = "شماره گواهینامه رانندگی تکراری میباشد"; } else { throw ex; } } } }
protected void btnExcel_Click(object sender, EventArgs e) { Ajancy.Kimia_Ajancy db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); var query = from j in db.Ajancies join bl in db.BusinessLicenses on j.AjancyID equals bl.AjancyID join jp in db.AjancyPartners on j.AjancyID equals jp.AjancyID join ur in db.UsersInRoles on jp.UserRoleID equals ur.UserRoleID join u in db.Users on ur.UserID equals u.UserID join p in db.Persons on u.PersonID equals p.PersonID join ct in db.Cities on j.CityID equals ct.CityID join pv in db.Provinces on ct.ProvinceID equals pv.ProvinceID where jp.LockOutDate == null && j.AjancyType == Public.ToByte(this.drpAjancyType.SelectedValue) && bl.LockOutDate == null orderby pv.Name, ct.Name, j.AjancyName select new { ct.ProvinceID, ct.CityID, Province = pv.Name, City = ct.Name, j.AjancyName, j.Phone, j.PostalCode, j.Address, bl.BusinessLicenseNo, j.BusinessLicenseType, p.NationalCode, p.FirstName, p.LastName, p.Mobile }; if (this.drpProvince.SelectedIndex > 0 && this.drpCity.SelectedIndex == 0) // Just province { query = from q in query where q.ProvinceID == Public.ToByte(this.drpProvince.SelectedValue) select q; } if (this.drpProvince.SelectedIndex > 0 && this.drpCity.SelectedIndex > 0) // province and city { query = from q in query where q.CityID == Public.ToShort(this.drpCity.SelectedValue) select q; } if (!string.IsNullOrEmpty(this.txtAjancyName.Text)) { query = from q in query where q.AjancyName.Contains(this.txtAjancyName.Text.Trim()) select q; } DataTable dtObj = new DataTable(); dtObj.Columns.Add(new DataColumn("FirstName", typeof(string))); dtObj.Columns.Add(new DataColumn("LastName", typeof(string))); dtObj.Columns.Add(new DataColumn("NationalCode", typeof(string))); dtObj.Columns.Add(new DataColumn("Mobile", typeof(string))); dtObj.Columns.Add(new DataColumn("AjancyName", typeof(string))); dtObj.Columns.Add(new DataColumn("BusinessLicenseNo", typeof(string))); dtObj.Columns.Add(new DataColumn("BusinessLicenseType", typeof(string))); dtObj.Columns.Add(new DataColumn("Address", typeof(string))); dtObj.Columns.Add(new DataColumn("PostalCode", typeof(string))); dtObj.Columns.Add(new DataColumn("Phone", typeof(string))); dtObj.Columns.Add(new DataColumn("Province", typeof(string))); dtObj.Columns.Add(new DataColumn("City", typeof(string))); foreach (var item in query) { DataRow row = dtObj.NewRow(); row[0] = item.FirstName; row[1] = item.LastName; row[2] = item.NationalCode; row[3] = item.Mobile; row[4] = item.AjancyName; row[5] = item.BusinessLicenseNo; row[6] = item.BusinessLicenseType == 0 ? "عادی" : "ویژه ایثارگران و جانبازان و شهدا"; row[7] = item.Address; row[8] = item.PostalCode; row[9] = item.Phone; row[10] = item.Province; row[11] = item.City; dtObj.Rows.Add(row); } db.Dispose(); dtObj.TableName = "dt"; Stimulsoft.Report.StiReport report = new Stimulsoft.Report.StiReport(); report.RegData(dtObj); report.Load(HttpContext.Current.Server.MapPath("~/App_Data/Report/mrt/ajancy_list.mrt")); report.Render(); Public.ExportInfo(3, report); report.Dispose(); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Ajancy.Kimia_Ajancy db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); if (Request.QueryString["mode"] != null) { JavaScriptSerializer serializer = new JavaScriptSerializer(); string treeJSON = null; switch (Request.QueryString["mode"]) { case "0": // Province managers var provinceManagers = from prv in db.Provinces join u in db.Users on prv.ProvinceID equals u.ProvinceID join ur in db.UsersInRoles on u.UserID equals ur.UserID where ur.RoleID == (byte)Public.Role.ProvinceManager select new { key = ur.UserRoleID, title = prv.Name, icon = "city.png", selected = ur.LockOutDate == null }; treeJSON = serializer.Serialize(provinceManagers); break; case "1": // City managers var cityManagers = from prv in db.Provinces select new { key = 0, title = prv.Name, icon = "province.png", //selected = false, children = (from cty in db.Cities join u in db.Users on cty.CityID equals u.CityID join ur in db.UsersInRoles on u.UserID equals ur.UserID where ur.RoleID == (byte)Public.Role.CityManager && cty.ProvinceID == prv.ProvinceID orderby prv.Name, cty.Name select new { key = ur.UserRoleID, title = cty.Name, icon = "city.png", selected = ur.LockOutDate == null }) }; treeJSON = serializer.Serialize(cityManagers.Where(q => q.children.Any())); break; case "2": // Academy province managers var academyProvinceManagers = from prv in db.Provinces join u in db.Users on prv.ProvinceID equals u.ProvinceID join ur in db.UsersInRoles on u.UserID equals ur.UserID where ur.RoleID == (byte)Public.Role.AcademyProvince select new { key = ur.UserRoleID, title = prv.Name, icon = "city.png", selected = ur.LockOutDate == null }; treeJSON = serializer.Serialize(academyProvinceManagers); break; case "3": // City managers var academyCityManagers = from prv in db.Provinces select new { key = 0, title = prv.Name, icon = "province.png", //selected = false, children = (from cty in db.Cities join u in db.Users on cty.CityID equals u.CityID join ur in db.UsersInRoles on u.UserID equals ur.UserID where ur.RoleID == (byte)Public.Role.AcademyCity && cty.ProvinceID == prv.ProvinceID orderby prv.Name, cty.Name select new { key = ur.UserRoleID, title = cty.Name, icon = "city.png", selected = ur.LockOutDate == null }) }; treeJSON = serializer.Serialize(academyCityManagers.Where(q => q.children.Any())); break; } db.Dispose(); Response.Clear(); Response.Write(treeJSON); Response.End(); } else if (Request.HttpMethod == "POST" && Request.Params["keys"] != null && Request.Params["status"] != null) // Save changes { string[] userRoleIds = Request.Params["keys"].Split(','); if (bool.Parse(Request.Params["status"])) { foreach (string userRoleId in userRoleIds) { db.UsersInRoles.First<Ajancy.UsersInRole>( role => role.UserRoleID == int.Parse(userRoleId)).LockOutDate = null; } } else { foreach (string userRoleId in userRoleIds) { db.UsersInRoles.First<Ajancy.UsersInRole>( role => role.UserRoleID == int.Parse(userRoleId)).LockOutDate = DateTime.Now; } } db.SubmitChanges(); db.Dispose(); Response.Clear(); Response.Write('1'); Response.End(); } } }
private void LoadAjancies(bool loadItems) { this.drpAjancies.Items.Clear(); if (loadItems) { db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); var ajancyList = from j in db.Ajancies join bl in db.BusinessLicenses on j.AjancyID equals bl.AjancyID join ct in db.Cities on j.CityID equals ct.CityID where j.AjancyType == (byte)Public.AjancyType.TaxiAjancy && ct.ProvinceID == Public.ActiveUserRole.User.ProvinceID && ct.CityID == Public.ToShort(this.drpCity.SelectedValue) && bl.LockOutDate == null orderby j.AjancyName select new { j.AjancyID, j.AjancyName }; this.drpAjancies.DataSource = ajancyList; this.drpAjancies.DataBind(); } this.drpAjancies.Items.Insert(0, "- انتخاب کنید -"); }
protected void btnSearch_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.txtNationalCode.Text)) { db = new Ajancy.Kimia_Ajancy(Public.ConnectionString); var driver = (from p in db.Persons join dc in db.DriverCertifications on p.PersonID equals dc.PersonID join u in db.Users on p.PersonID equals u.PersonID where p.NationalCode == this.txtNationalCode.Text.Trim() && dc.CertificationType == (byte)Public.AjancyType.TaxiAjancy select new { p.FirstName, p.LastName, p.BirthCertificateNo, p.Father, u.ProvinceID, u.CityID, dc.DriverCertificationID }).FirstOrDefault(); if (driver != null) { if (Public.ActiveUserRole.RoleID == (short)Public.Role.ProvinceManager && driver.ProvinceID != Public.ActiveUserRole.User.ProvinceID) // Is ProvinceManager { DisposeContext(); Response.Redirect("~/Message.aspx?mode=27"); // This is a driver of an other province } else if (Public.ActiveUserRole.RoleID == (short)Public.Role.CityManager && driver.CityID != Public.ActiveUserRole.User.CityID) { DisposeContext(); Response.Redirect("~/Message.aspx?mode=26"); // This is a driver of an other city } this.LoadDriverCars(driver.DriverCertificationID, db); this.ViewState["DCID"] = driver.DriverCertificationID; this.lblFirstName.Text = driver.FirstName; this.lblLastName.Text = driver.LastName; this.lblFather.Text = driver.Father; this.lblBirthCertificateNo.Text = driver.BirthCertificateNo; this.btnSave.Enabled = true; if (this.drpCarType.Items.Count == 0) { this.drpCarType.DataSource = db.CarTypes.OrderBy(ct => ct.TypeName); this.drpCarType.DataBind(); this.drpCarType.Items.Insert(0, new System.Web.UI.WebControls.ListItem("- انتخاب کنید -", "0")); } return; } } this.ClearControls(true); this.btnSave.Enabled = false; }