protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SupplySystem.SupplySystem db = new SupplySystem.SupplySystem(Public.ConnectionString); int repositoryId = 0; int stuffTypeId = 0; if (int.TryParse(Request.QueryString["rId"], out repositoryId)) { this.grdStuffs.DataSource = (from st in db.REP_Stuffs join repGd in db.REP_RepositoryStuffs on st.StuffID equals repGd.StuffID where repGd.RepositoryID == repositoryId select new { st.StuffID, st.StuffName }).ToList(); } else if (int.TryParse(Request.QueryString["st"], out stuffTypeId)) { this.grdStuffs.DataSource = (from st in db.REP_Stuffs where st.StuffTypeID == stuffTypeId select new { st.StuffID, st.StuffName }).ToList(); } else { this.grdStuffs.DataSource = db.REP_Stuffs.Select(st => new { st.StuffID, st.StuffName }).ToList(); } this.grdStuffs.DataBind(); } }
protected void btnSave_Click(object sender, EventArgs e) { if (Page.IsValid) { try { SupplySystem.User user = new SupplySystem.User { UserName = this.txtUserName.Text, PassWord = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtPassword.Text, "SHA1"), FirstName = this.txtName.Text, LastName = this.txtFamily.Text, Gender = (byte)this.drpGender.SelectedIndex, Phone = this.txtPhone.Text }; user.UsersInRoles.Add(new SupplySystem.UsersInRole { RoleID = Public.ToShort(this.drpRoles.SelectedValue), SubmitDate = DateTime.Now }); SupplySystem.SupplySystem db = new SupplySystem.SupplySystem(Public.ConnectionString); db.Users.InsertOnSubmit(user); db.SubmitChanges(); Response.Redirect("~/Default.aspx"); } catch (Exception ex) { if (ex.Message.Contains("IX_Users")) { this.lblMessage.Text = "نام کاربری تکراری میباشد!"; } } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SupplySystem.SupplySystem db = new SupplySystem.SupplySystem(Public.ConnectionString); this.grdProvinces.DataSource = db.Provinces; this.grdProvinces.DataBind(); } }
public string GetGood(string id, string mode) { db = new SupplySystem.SupplySystem(Public.ConnectionString); SupplySystem.REP_Stuff stuff = db.REP_Stuffs.SingleOrDefault<SupplySystem.REP_Stuff>(st => st.StuffID == Public.ToInt(id) && st.StuffTypeID == Public.ToByte(mode)); if (stuff != null) { return string.Concat(stuff.StuffName, "|", stuff.StuffID); } else { return null; } }
public string GetProvince(string code) { db = new SupplySystem.SupplySystem(Public.ConnectionString); var province = from p in db.Provinces where p.ProvinceID == Public.ToByte(code) select new { p.Name }; foreach (var item in province) { return item.Name; } return null; }
public string GetArea(string code) { db = new SupplySystem.SupplySystem(Public.ConnectionString); var area = from ar in db.Areas where ar.AreaCode == Public.ToInt(code) select new { ar.AreaName }; foreach (var item in area) { return item.AreaName; } return null; }
public string GetCity(string pCode, string cCode) { db = new SupplySystem.SupplySystem(Public.ConnectionString); var city = from c in db.Cities where c.ProvinceID == Public.ToByte(pCode) && c.CityID == Public.ToShort(cCode) select new { c.Name }; foreach (var item in city) { return item.Name; } return null; }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SupplySystem.SupplySystem db = new SupplySystem.SupplySystem(Public.ConnectionString); var areaManagers = from u in db.Users join ur in db.UsersInRoles on u.UserID equals ur.UserID into grp from g in grp.DefaultIfEmpty() where g.RoleID == (short)Public.Role.AreaManager && g.AreaCode == null select new { u.UserID, u.FirstName, u.LastName, u.UserName }; this.grdUsers.DataSource = areaManagers.ToList(); this.grdUsers.DataBind(); } }
protected void btnEdit_Click(object sender, EventArgs e) { if (this.grdSubLevels.SelectedItems.Count == 1) { db = new SupplySystem.SupplySystem(Public.ConnectionString); var slv = from sl in db.SubLevels where sl.SubLevelID == Public.ToShort(this.grdSubLevels.SelectedKeys[0]) select new { sl.SubLevelID, sl.LevelID, sl.SubLevelName }; foreach (var item in slv) { this.drpLevels.SelectedValue = item.LevelID.ToString(); this.ViewState["SLID"] = item.SubLevelID.ToString(); this.txtSubLevelName.Text = item.SubLevelName; } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { short provinceId = 0; if (short.TryParse(Request.QueryString["pId"], out provinceId)) { SupplySystem.SupplySystem db = new SupplySystem.SupplySystem(Public.ConnectionString); this.grdCities.DataSource = db.Cities.Where<SupplySystem.City>(c => c.ProvinceID == provinceId).OrderBy(ct => ct.Name).ToList<SupplySystem.City>(); this.grdCities.DataBind(); } else { Server.Transfer("~/Error.aspx"); } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SupplySystem.SupplySystem db = new SupplySystem.SupplySystem(Public.ConnectionString); var schools = from sch in db.Schools join slv in db.SchoolLevels on sch.SchoolID equals slv.SchoolID join lv in db.Levels on slv.LevelID equals lv.LevelID join ar in db.Areas on sch.AreaCode equals ar.AreaCode join ct in db.Cities on sch.CityID equals ct.CityID into cty from c in cty.DefaultIfEmpty() where slv.LockOutDate == null orderby sch.SchoolCode select new { sch.SchoolCode, sch.SchoolName, sch.Phone, c.Name, lv.LevelName, ar.AreaName, ar.AreaCode, }; if (System.Web.HttpContext.Current.User.IsInRole("Administrator") && Request.QueryString["ac"] != null) { schools = from q in schools where q.AreaCode == Public.ToInt(Request.QueryString["ac"]) select q; } else if (System.Web.HttpContext.Current.User.IsInRole("AreaManager")) { schools = from q in schools where q.AreaCode == (from u in db.Users join ur in db.UsersInRoles on u.UserID equals ur.UserID where u.UserName.Equals(HttpContext.Current.User.Identity.Name) select ur.AreaCode).SingleOrDefault() select q; } else if (System.Web.HttpContext.Current.User.IsInRole("SchoolManager")) { schools = from q in schools where q.SchoolCode == Public.ToInt(HttpContext.Current.User.Identity.Name) select q; } this.grdSchools.DataSource = schools.ToList(); this.grdSchools.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SupplySystem.SupplySystem db = new SupplySystem.SupplySystem(Public.ConnectionString); var areas = from ar in db.Areas join ur in db.UsersInRoles on ar.AreaCode equals ur.AreaCode join u in db.Users on ur.UserID equals u.UserID orderby ar.AreaCode select new { ar.AreaCode, ar.AreaName, ur.UserInRoleID, User = string.Concat(u.FirstName, " ", u.LastName) }; this.grdAreas.DataSource = areas.ToList(); this.grdAreas.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { byte type = 0; if (!IsPostBack && byte.TryParse(Request.QueryString["type"], out type)) { SupplySystem.SupplySystem db = new SupplySystem.SupplySystem(Public.ConnectionString); var reporitories = from rct in db.REP_Recepts join ar in db.Areas on rct.AreaCode equals ar.AreaCode join rep in db.REP_Repositories on rct.RepositoryID equals rep.RepositoryID where rct.ReceptType == type select new { rct.ReceptID, rct.ReceptCode, rct.ReceptDate, rep.RepositoryName, ar.AreaName }; this.grdRecepts.DataSource = reporitories.ToList(); this.grdRecepts.DataBind(); } }
protected void btnLogin_Click(object sender, System.EventArgs e) { if (Page.IsValid) { DataLoadOptions dlo = new DataLoadOptions(); dlo.LoadWith<SupplySystem.User>(u => u.UsersInRoles); dlo.LoadWith<SupplySystem.UsersInRole>(ur => ur.Role); SupplySystem.SupplySystem db = new SupplySystem.SupplySystem(Public.ConnectionString); db.LoadOptions = dlo; SupplySystem.User user = db.Users.FirstOrDefault<SupplySystem.User>(u => u.UserName == this.txtUserName.Text && u.PassWord == FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtPassword.Text, "SHA1")); if (user != null) // Credentials are valid { user.LastLoginDate = DateTime.Now; db.SubmitChanges(); this.Session["User"] = user; string roles = null; var rolesList = user.UsersInRoles.Select(ur => new { ur.Role.RoleName }); foreach (var item in rolesList) { roles += string.Concat(item.RoleName, ","); } FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(2, this.txtUserName.Text, DateTime.Now, DateTime.Now.AddMinutes(30), false, roles.Remove(roles.Length - 1, 1)); Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authTicket))); FormsAuthentication.GetRedirectUrl(this.txtUserName.Text, false); int msgCount = (from msg in db.Messages join umg in db.MessageUsers on msg.MessageID equals umg.MessageID where umg.UserInRoleID == user.UsersInRoles[0].UserInRoleID && !umg.Read select new { msg.MessageID }).Count(); Response.Redirect(msgCount == 0 ? "~/Default.aspx" : "~/user/Message.aspx"); } else { this.lblMessage.Text = "نام کاربری یا گذرواژه نادرست میباشد"; } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SupplySystem.SupplySystem db = new SupplySystem.SupplySystem(Public.ConnectionString); if (Request.QueryString["trv"] != null) { JavaScriptSerializer serializer = new JavaScriptSerializer(); string treeJSON = null; switch (Request.QueryString["trv"]) { case "0": // managers mode if (HttpContext.Current.User.IsInRole("AreaManager")) // Just sees the administrator { treeJSON = serializer.Serialize(new { key = "2539", title = "مدیر سیستم", icon = "manager.png" }); Response.Clear(); Response.Write(treeJSON); Response.End(); } else if (HttpContext.Current.User.IsInRole("SchoolManager")) // Just sees hisown areamanager { var areaManager = from ar in db.Areas join ur in db.UsersInRoles on ar.AreaCode equals ur.AreaCode where ar.AreaCode == (from s in db.Schools where s.SchoolCode.ToString().Equals(HttpContext.Current.User.Identity.Name) select s.AreaCode).FirstOrDefault() select new { key = ur.UserInRoleID, title = ar.AreaName }; foreach (var item in areaManager) { treeJSON = serializer.Serialize(new { key = item.key, title = string.Format("مدیر منطقه {0}", item.title), icon = "manager.png" }); } Response.Clear(); Response.Write(treeJSON); Response.End(); } var areaManagers = from ar in db.Areas join ur in db.UsersInRoles on ar.AreaCode equals ur.AreaCode orderby ar.AreaName select new { ar.AreaCode, key = ur.UserInRoleID, title = ar.AreaName, icon = "manager.png" }; if (HttpContext.Current.User.IsInRole("SchoolManager")) // Just sees hisown areamanager { areaManagers = from q in areaManagers where q.AreaCode == (from s in db.Schools where s.AreaCode.ToString().Equals(HttpContext.Current.User.Identity.Name) select s.AreaCode).SingleOrDefault() select q; } treeJSON = serializer.Serialize(from q in areaManagers select new { q.key, q.title, q.icon }); break; case "1": // School managers mode if (System.Web.HttpContext.Current.User.IsInRole("SchoolManager")) { Response.Clear(); Response.Write(null); Response.End(); } var schoolManagers = from ar in db.Areas join ur in db.UsersInRoles on ar.AreaCode equals ur.AreaCode orderby ar.AreaName select new { key = ar.AreaCode, title = ar.AreaName, icon = "area.png", children = (from s in db.Schools join ur2 in db.UsersInRoles on s.SchoolID equals ur2.SchoolID where s.AreaCode == ar.AreaCode orderby s.SchoolName select new { key = ur2.UserInRoleID, title = s.SchoolName, icon = "school.png" }) }; if (HttpContext.Current.User.IsInRole("AreaManager")) { schoolManagers = from q in schoolManagers where q.key == (from u in db.Users join ur in db.UsersInRoles on u.UserID equals ur.UserID where u.UserName.Equals(HttpContext.Current.User.Identity.Name) select ur.AreaCode).SingleOrDefault() select q; } treeJSON = serializer.Serialize(schoolManagers); break; } Response.Clear(); Response.Write(treeJSON); Response.End(); } else if (Request.HttpMethod == "POST" && Request.Params["sbj"] != null && Request.Params["bdy"] != null && Request.Params["ids"] != null) { if (System.Web.HttpContext.Current.User.IsInRole("Guest")) { return; } string[] userInRoles = Request.Params["ids"].Split(','); if (userInRoles.Length > 0) { SupplySystem.Message message = new SupplySystem.Message(); message.Subject = Request.Params["sbj"].Trim(); message.Body = Request.Params["bdy"]; message.UserInRoleID = ((SupplySystem.User)this.Session["User"]).UsersInRoles.First<SupplySystem.UsersInRole>().UserInRoleID; message.SubmitDate = DateTime.Now; foreach (string item in userInRoles) { message.MessageUsers.Add(new SupplySystem.MessageUser { UserInRoleID = int.Parse(item) }); } db.Messages.InsertOnSubmit(message); db.SubmitChanges(); Response.Clear(); Response.Write('1'); Response.End(); } } } }
protected void txtSchoolCode_TextChanged(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.txtSchoolCode.Text)) { db = new SupplySystem.SupplySystem(Public.ConnectionString); DataLoadOptions dlo = new DataLoadOptions(); dlo.LoadWith<SupplySystem.School>(s => s.SchoolLevels); dlo.LoadWith<SupplySystem.SchoolLevel>(slv => slv.SchoolSubLevels); db.LoadOptions = dlo; var school = from s in db.Schools join slv in db.SchoolLevels on s.SchoolID equals slv.SchoolID join lv in db.Levels on slv.LevelID equals lv.LevelID join k in db.SchoolKinds on s.SchoolKindID equals k.SchoolKindID join a in db.Areas on s.AreaCode equals a.AreaCode join c in db.Cities on s.CityID equals c.CityID into cty from ct in cty.DefaultIfEmpty() where s.SchoolCode == Public.ToInt(this.txtSchoolCode.Text) && slv.LockOutDate == null select new { s.SchoolID, s.SchoolCode, s.SchoolName, s.Phone, s.SchoolKindID, s.Village, s.Street, s.Line, s.Pelak, s.PostalCode, s.Gender, s.EmployeesCount_Fixed, s.EmployeesCount_Changable, s.ManagerID, s.AssistanceID, s.AreaCode, s.CityID, CityName = ct.Name, lv.LevelID, lv.LevelName, a.AreaName, k.SchoolKindName }; if (System.Web.HttpContext.Current.User.IsInRole("AreaManager")) { var area = from u in db.Users join ur in db.UsersInRoles on u.UserID equals ur.UserID where u.UserName.Equals(HttpContext.Current.User.Identity.Name) select new { ur.AreaCode }; foreach (var item in area) { school = from q in school where q.AreaCode == item.AreaCode select q; } } else if (System.Web.HttpContext.Current.User.IsInRole("SchoolManager")) { school = from q in school where q.SchoolCode == Public.ToInt(HttpContext.Current.User.Identity.Name) select q; } this.hdnSchoolID.Value = null; foreach (var sch in school) { this.hdnSchoolID.Value = sch.SchoolID.ToString(); this.txtSchoolName.Text = sch.SchoolName; this.drpSchoolLevel.SelectedValue = sch.LevelID.ToString(); this.drpSchoolLevel.Enabled = false; this.drpSchoolKind.SelectedValue = sch.SchoolKindID.ToString(); this.drpGender.SelectedIndex = sch.Gender; this.drpGender.Enabled = false; this.txtAreaName.Text = sch.AreaName; this.txtAreaCode.Text = sch.AreaCode.ToString(); this.txtCityCode.Text = sch.CityID.ToString(); this.txtCityName.Text = sch.CityName; this.txtVillage.Text = sch.Village; this.txtStreet.Text = sch.Street; this.txtAlly.Text = sch.Line; this.txtPelak.Text = sch.Pelak; this.txtPostCode.Text = sch.PostalCode; this.txtPhone.Text = sch.Phone; this.txtFixed.Text = sch.EmployeesCount_Fixed.ToString(); this.txtChangable.Text = sch.EmployeesCount_Changable.ToString(); this.txtManagerName.Text = sch.ManagerID.ToString(); this.txtAssistanceName.Text = sch.AssistanceID.ToString(); var subLevels = from slv in db.SchoolLevels join ssl in db.SchoolSubLevels on slv.SchoolLevelID equals ssl.SchoolLevelID join sl in db.SubLevels on ssl.SubLevelID equals sl.SubLevelID where slv.SchoolID == sch.SchoolID && slv.LockOutDate == null && !sl.SubLevelName.Equals("Employees") select new { sl.SubLevelName, ssl.SubLevelID, ssl.BoysCount, ssl.GirlsCount }; this.grdSubLevels.DataSource = subLevels.ToList(); this.grdSubLevels.DataBind(); this.btnSave.Visible = false; this.btnEdit.Visible = !System.Web.HttpContext.Current.User.IsInRole("Guest"); } if (string.IsNullOrEmpty(this.hdnSchoolID.Value)) // SchoolCode is not valid { this.txtSchoolName.Focus(); this.drpSchoolLevel.Enabled = true; this.drpGender.Enabled = true; CleanCotrols(); } } }
public static void LoadCycleMonths(DropDownList drp, int cycleId) { SupplySystem.SupplySystem db = new SupplySystem.SupplySystem(Public.ConnectionString); SupplySystem.Cycle cycle = db.Cycles.FirstOrDefault<SupplySystem.Cycle>(c => c.CycleID == cycleId); if (cycle != null) { int[] startDate = Persia.Calendar.ConvertToPersian(cycle.StartDate).ArrayType; int[] endDate = Persia.Calendar.ConvertToPersian(cycle.EndDate).ArrayType; if (startDate[0] == endDate[0]) // Both dates are in the same year { for (int i = startDate[1]; i <= endDate[1]; i++) { drp.Items.Add(new ListItem(string.Format("{0} {1}", MonthName(i), startDate[0]), string.Concat(startDate[0], "|", i))); } } else { ArrayList months = MonthsInStartYear(startDate[1], startDate[0], endDate[1], endDate[0]); string[] month = null; for (int i = 1; i <= months.Count; i++) { month = months[i - 1].ToString().Split(','); drp.Items.Add(new ListItem(string.Format("{0} {1}", month[1], month[2]), month[0])); } } drp.DataBind(); drp.Items.Insert(0, new ListItem("-- همه ماهها --", "0")); } }
protected void btnSave_Click(object sender, EventArgs e) { if (Page.IsValid) { SupplySystem.SupplySystem db = new SupplySystem.SupplySystem(Public.ConnectionString); SupplySystem.User user = null; if (HttpContext.Current.User.IsInRole("Administrator")) { user = db.Users.FirstOrDefault<SupplySystem.User>(u => u.UserName.Equals(this.txtUserName.Text)); if (user != null) { user.PassWord = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtNewPassword.Text, "SHA1"); db.SubmitChanges(); this.lblMessage.Text = "ویرایش گذرواژه انجام گردید"; } else { this.lblMessage.Text = "نام کاربری نادرست میباشد"; } } else if (HttpContext.Current.User.IsInRole("AreaManager")) { bool isUserNameValid = false; if (HttpContext.Current.User.Identity.Name == this.txtUserName.Text) // he wants to change his own password { user = db.Users.FirstOrDefault<SupplySystem.User>(u => u.UserName.Equals(this.txtUserName.Text)); if (user != null) { user.PassWord = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtNewPassword.Text, "SHA1"); db.SubmitChanges(); this.lblMessage.Text = "ویرایش گذرواژه انجام گردید"; } isUserNameValid = true; } else { user = (from u in db.Users join ur in db.UsersInRoles on u.UserID equals ur.UserID where u.UserName.Equals(this.txtUserName.Text) && ur.AreaCode.GetValueOrDefault() == Public.ToInt(HttpContext.Current.User.Identity.Name) select u).SingleOrDefault<SupplySystem.User>(); if (user != null) { user.PassWord = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtNewPassword.Text, "SHA1"); db.SubmitChanges(); isUserNameValid = true; } } if (!isUserNameValid) { this.lblMessage.Text = "نام کاربری نادرست میباشد"; } else { this.lblMessage.Text = "ویرایش گذرواژه انجام گردید"; } } else if (HttpContext.Current.User.IsInRole("SchoolManager")) { user = db.Users.FirstOrDefault<SupplySystem.User>(u => u.UserName.Equals(this.txtUserName.Text) && u.PassWord.Equals(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtPassword.Text, "SHA1"))); if (user != null) { user.PassWord = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtNewPassword.Text, "SHA1"); db.SubmitChanges(); this.lblMessage.Text = "ویرایش گذرواژه انجام گردید"; } else { this.lblMessage.Text = "نام کاربری نادرست میباشد"; } } //this.txtUserName.Text = null; this.txtPassword.Text = null; this.txtNewPassword.Text = null; this.txtRePassword.Text = null; } }
public string GetSchool(string sCode, string aCode) { db = new SupplySystem.SupplySystem(Public.ConnectionString); var school = db.Schools.Where(s => s.SchoolCode == Public.ToInt(sCode) && s.AreaCode == Public.ToInt(aCode)).Select(s => new { s.SchoolName }); foreach (var item in school) { return item.SchoolName; } return null; }