Beispiel #1
0
        partial void OnValidate(System.Data.Linq.ChangeAction action)
        {
            if (action == System.Data.Linq.ChangeAction.Insert ||
                action == System.Data.Linq.ChangeAction.Update)
            {
                if (string.IsNullOrEmpty(this.Name) ||
                    string.IsNullOrEmpty(this.Name.Trim()))
                {
                    throw new Exception("Nhập danh mục");
                }

                RedBloodDataContext db = new RedBloodDataContext();

                int count = (from cats in db.Geos
                             where cats.ID != this.ID && object.Equals(cats.ParentID, this.ParentID) &&
                             cats.Name.Trim() == this.Name.Trim()
                             select cats).Count();

                if (count > 0)
                {
                    throw new Exception("Trùng tên");
                }

                GeoBLL.SetFullname(this);
            }
        }
Beispiel #2
0
    public List <Org> SearchByGeo(string searchStr)
    {
        RedBloodDataContext db = new RedBloodDataContext();

        searchStr = searchStr.Trim();

        if (string.IsNullOrEmpty(searchStr))
        {
            return((from c in db.Orgs
                    select c).ToList());
        }
        else
        {
            Geo g = GeoBLL.GetByFullname(searchStr);
            if (g == null)
            {
                return(new List <Org>());
            }

            if (g.Level == 1)
            {
                return(db.Orgs.Where(r => r.GeoID1 == g.ID).ToList());
            }
            if (g.Level == 2)
            {
                return(db.Orgs.Where(r => r.GeoID2 == g.ID && r.GeoID1 == g.ParentGeo.ID).ToList());
            }
            if (g.Level == 3)
            {
                return(db.Orgs.Where(r => r.GeoID3 == g.ID && r.GeoID2 == g.ParentGeo.ID && r.GeoID1 == g.ParentGeo.ParentGeo.ID).ToList());
            }
            return(new List <Org>());
        }
    }
Beispiel #3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!string.IsNullOrEmpty(Request["ProvinceID"]))
            {
                ProvinceID = Request["ProvinceID"].ToGuid();
            }

            if (!string.IsNullOrEmpty(Request["From"]))
            {
                ucDateRange.FromDate = Request["From"].ToString().ToShortDate();
            }

            if (!string.IsNullOrEmpty(Request["To"]))
            {
                ucDateRange.ToDate = Request["To"].ToString().ToShortDate();
            }

            Geo g = GeoBLL.Get(ProvinceID, 1);

            lblProvince.Text = g.Fullname;

            GridView1.DataBind();
        }
    }
Beispiel #4
0
    private static Guid?ImportPeople(RedBloodDataContext db, People outerP)
    {
        //Importing people
        if (outerP == null || db == null)
        {
            return(null);
        }

        People innerP = PeopleBLL.GetByID(outerP.ID);

        if (innerP == null)
        {
            People newP = new People();

            newP.Name    = outerP.Name;
            newP.DOB     = outerP.DOB;
            newP.DOBYear = outerP.DOBYear;
            newP.CMND    = outerP.CMND;
            newP.SexID   = outerP.SexID;

            GeoBLL.Insert(
                outerP.ResidentGeo1 != null ? outerP.ResidentGeo1.Name : ""
                , outerP.ResidentGeo2 != null ? outerP.ResidentGeo2.Name : ""
                , outerP.ResidentGeo3 != null ? outerP.ResidentGeo3.Name : "");

            newP.ResidentAddress = outerP.ResidentAddress;
            newP.SetResidentGeo3(outerP.FullResidentalGeo);

            if (outerP.EnableMailingAddress.HasValue &&
                outerP.EnableMailingAddress.Value)
            {
                GeoBLL.Insert(
                    outerP.MailingGeo1 != null ? outerP.MailingGeo1.Name : ""
                    , outerP.MailingGeo2 != null ? outerP.MailingGeo2.Name : ""
                    , outerP.MailingGeo3 != null ? outerP.MailingGeo3.Name : "");

                newP.MailingAddress = outerP.MailingAddress;
                newP.SetMailingGeo3(outerP.FullMaillingGeo);

                newP.EnableMailingAddress = outerP.EnableMailingAddress;
            }

            newP.Job   = outerP.Job;
            newP.Email = outerP.Email;
            newP.Phone = outerP.Phone;
            newP.Note  = outerP.Note;

            db.Peoples.InsertOnSubmit(newP);
            db.SubmitChanges();

            return(newP.ID);
        }
        else
        {
            return(innerP.ID);
        }
    }
Beispiel #5
0
    protected void btnLevel1New_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(txtLevel1.Text.Trim()))
        {
            return;
        }

        GeoBLL.Insert(txtLevel1.Text.Trim(), 1, null);

        txtLevel1.Text = "";

        GridView1.DataBind();
    }
Beispiel #6
0
    protected void btnLevel3New_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(txtLevel3.Text.Trim()))
        {
            return;
        }

        if (GridView2.SelectedValue == null)
        {
            return;
        }

        GeoBLL.Insert(txtLevel3.Text.Trim(), 3, (Guid)GridView2.SelectedValue);

        txtLevel3.Text = "";

        GridView3.DataBind();
    }
Beispiel #7
0
    public static void Set3LevelByFullname(string fullname, Func <Guid?, Guid?, Guid?, int> setGeoFunc)
    {
        if (string.IsNullOrEmpty(fullname) ||
            string.IsNullOrEmpty(fullname.Trim()))
        {
            throw new Exception("Nhập đơn vị hành chính.");
        }
        else
        {
            Geo g = GeoBLL.GetByFullname(fullname);
            if (g == null)
            {
                throw new Exception("Nhập sai đơn vị hành chính.");
            }
            else
            {
                Guid?geo1ID = null;
                Guid?geo2ID = null;
                Guid?geo3ID = null;

                if (g.Level == 1)
                {
                    geo1ID = g.ID;
                }

                if (g.Level == 2)
                {
                    geo2ID = g.ID;
                    geo1ID = g.ParentGeo.ID;
                }

                if (g.Level == 3)
                {
                    geo3ID = g.ID;
                    geo2ID = g.ParentGeo.ID;
                    geo1ID = g.ParentGeo.ParentGeo.ID;
                }

                setGeoFunc(geo1ID, geo2ID, geo3ID);
            }
        }
    }
Beispiel #8
0
 public void SetMailingGeo3(string value)
 {
     GeoBLL.Set3LevelByFullname(value, SetMailingGeo3);
 }
Beispiel #9
0
 public void SetResidentGeo3(string value)
 {
     GeoBLL.Set3LevelByFullname(value, SetResidentGeo3);
 }