예제 #1
0
    protected void Set_Table_Filtered(string filterUser, string filterCompany)
    {
        GoDine GD = new GoDine();

        DataTable dt;
        DataClassesAlbertDataContext db;

        db = new DataClassesAlbertDataContext();
        dt = new DataTable("CUsers");
        //var companies = db.Companies; // THIS IS A FULL TABLE ACQUISITION FROM DATABASE
        var Cusers = from cu in db.CUsers where cu.UserCode.Contains(filterUser) && cu.Company.Name.Contains(filterCompany) select new {
            CUserID = cu.CUserID,
            UserCode = cu.UserCode,
            CompanyName = cu.Company.Name,
            TotalIn = (GD.Cuser_TotalFromTrans_CuserID(cu.CUserID)).TotalIn,
            TotalInDiscounted = (GD.Cuser_TotalFromTrans_CuserID(cu.CUserID)).TotalInDiscounted,
            Benefit = cu.TotalIn-cu.TotalInDiscounted,
            Forced = cu.Forced,
            Date = cu.Date
        }; // THIS IS A SELECTED TABLE ACQUISITION

        dt.Columns.Add("CuserID", typeof(int));
        dt.Columns.Add("UserCode", typeof(string));
        dt.Columns.Add("Company", typeof(string));
        dt.Columns.Add("$CustomerExpenses", typeof(decimal));
        dt.Columns.Add("$AfterDiscount", typeof(decimal));
        dt.Columns.Add("$BrutBenefit", typeof(decimal));
        dt.Columns.Add("Forced", typeof(bool));
        dt.Columns.Add("CreationDate", typeof(DateTime));

        foreach (var cuser in Cusers)
        {
            DataRow tablerow = dt.NewRow();
            tablerow["CuserID"] = cuser.CUserID;
            tablerow["UserCode"] = cuser.UserCode;
            tablerow["Company"] = cuser.CompanyName;
            tablerow["$CustomerExpenses"] = Math.Round(cuser.TotalIn,2);
            tablerow["$AfterDiscount"] = Math.Round(cuser.TotalInDiscounted,2);
            tablerow["$BrutBenefit"] = cuser.Benefit;
            tablerow["Forced"] = cuser.Forced;
            tablerow["CreationDate"] = cuser.Date;
            dt.Rows.Add(tablerow);
        }

        Session["dt"] = dt;
        GV.DataSource = dt;
        GV.AllowSorting = true;
        GV.AllowPaging = true;
        GV.PageSize = 50;
        //GV.Columns["Money"].ItemStyle.HorizontalAlign = HorizontalAlign.Right;
        GV.DataBind();
    }