The table contains all the branches information (Name, Address, Country, ID, ect).
When the user goes to the main form of this application, he/she sees a GridView with all the branches' tasks. When he/she clicks edit, a Drop Down List is bind to the Branches table where the group of the user is equal to the group assigned in the Branches Table.
For Example:
var GridBind =
from x in MainQueryjoin cb_s in db.CommentBase_Status on
x.CommentStatusID equals cb_s.StatusIDjoin b in db.Branches on
x.BranchID equals b.dimensionorderby x.EntryDate ascending
where x.CommentType == CommentType && x.CommentStatusID == CommentValue
select new
{
FormId = x.FormID,
branch_group = x.BranchGroupID,
BranchId = branches.BRANCHNAME,
CommentString = x.CommentString,
EntryDate = x.EntryDate
};
My application Data layer is implemented with LINQ, so I decided to add these values when the Drop Down List was being bound, for example:
Well, then to do Let Outer Join in the main query of my application I can do the following:
var GridBind =
                from x in MainQuery
                join cb_s in db.CommentBase_Status on x.CommentStatusID equals cb_s.StatusID
                orderby x.EntryDate ascending
                where x.CommentType == CommentType && x.CommentStatusID == CommentValue
                from branches in db.Branches.Where(b => b.dimension == x.BranchID).DefaultIfEmpty()
                select new
                {
                    FormId = x.FormID,
                    branch_group = x.BranchGroupID,
                    BranchId = (branches.BRANCHNAME == null)? "All" :branches.BRANCHNAME,
                    StatusName = cb_s.StatusName,
                    CommentString = x.CommentString,
                    EntryDate = x.EntryDate
                };
            try
            {
                GridObject.DataSource = GridBind;
                GridObject.DataBind();
                ret = true;
            }
            catch (Exception ex)
            {
                ex.ToString();
                ret = false;
            }
List<Branches> branches = new List<Branches>();
                var ddlBranchesList =
                    from br in db.Branches
                    where br.active == true && br.BRANCHGROUP == id
                    orderby br.dimension descending
                    select br;
                branches = ddlBranchesList.ToList<Branches>();
                branches.Add(new Branches() { BRANCHNAME = "All", dimension = 1 });
                branches.Add(new Branches() { BRANCHNAME = "Select One", dimension = 0 });
                branches.Reverse();
                ddl.DataSource = branches;
                ddl.DataTextField = "BRANCHNAME";
                ddl.DataValueField = "dimension";
 
The format is a little weird. If you have any questions about the code contact me.
ReplyDelete