Esempio n. 1
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            SupplySystem.Area area = null;

            if (this.ViewState["Mode"] == null) // Add mode
            {
                if (string.IsNullOrEmpty(this.hdnUserID.Value))
                {
                    this.lblMessage.Text = "مدیر منطقه را انتخاب کنید";
                    return;
                }

                DataLoadOptions dlo = new DataLoadOptions();
                dlo.LoadWith<SupplySystem.User>(u => u.UsersInRoles);
                db.LoadOptions = dlo;

                area = new SupplySystem.Area
                {
                    AreaCode = Public.ToInt(this.txtAreaCode.Text),
                    AreaName = this.txtAreaName.Text,
                    ProvinceID = Public.ToByte(ConfigurationManager.AppSettings["DefaultProvinceId"])
                };

                SupplySystem.User user = db.Users.First<SupplySystem.User>(u => u.UserID == Public.ToInt(this.hdnUserID.Value));
                user.UsersInRoles.First<SupplySystem.UsersInRole>().AreaCode = area.AreaCode;
                db.Areas.InsertOnSubmit(area);
            }
            else if (this.ViewState["Mode"].ToString() == "edit") // Edit mode
            {
                area = db.Areas.First<SupplySystem.Area>(ar => ar.AreaCode == Public.ToInt(this.txtAreaCode.Text));
                area.AreaName = this.txtAreaName.Text;
                area.UsersInRoles.First<SupplySystem.UsersInRole>().AreaCode = area.AreaCode;
            }

            db.SubmitChanges();
            this.grdAreas.DataSource = db.Areas.Where<SupplySystem.Area>(ar => ar.ProvinceID == Public.ToByte(ConfigurationManager.AppSettings["DefaultProvinceId"])).Select(ar => new { ar.AreaCode, ar.AreaName }).OrderBy(ar => ar.AreaCode).ToList();
            this.grdAreas.DataBind();
            this.lblMessage.Text = Public.SUCCESSMESSAGE;
            ClearControls();
        }
    }
Esempio n. 2
0
		private void detach_Areas(Area entity)
		{
			this.SendPropertyChanging();
			entity.Province = null;
		}
Esempio n. 3
0
		private void attach_Areas(Area entity)
		{
			this.SendPropertyChanging();
			entity.Province = this;
		}
Esempio n. 4
0
 partial void DeleteArea(Area instance);
Esempio n. 5
0
 partial void UpdateArea(Area instance);
Esempio n. 6
0
 partial void InsertArea(Area instance);