locked
data according to region in alert box RRS feed

  • Question

  • User639567535 posted

    I try to convert SQL to LINQ query .. and through LINQ query i try to get data in data2 there is drop-down 2 calendars .. and in that drop-down there is region so when i select region and date then i try to get data in data2 e.g. in UK there is 3 PSB and 7 MV

    SELECT distinct count(VName) as data,
       tabvv.VName,
       tabrv.ID,
       FFID,
       oname,
       regno,
       FROM  tabrv
       join  tabre on tabre .RegionID= tabrv.RegionID
       join tabvv on tabvv.ID=tabrv.ID
       WHERE Region = 'UK' AND
       StartDate >= '2014-02-01 00:00:00.000' AND
       EndDate <= '2014-02-28 23:59:59.000'
       group by
       tabvv.VName,
       tabrv.ID,
       FFID,
       oname,
       regno

    data in database

    data     VName  ID  FFID    oname    regno  
       1        PSB     22  106      ASB     AY-50  
       1        MV      23  102     ASD     AS-18   
       1                24  104     ASFi    TM-82   
       1                25  1072    AED     AU-06   
       1        PSB     26  104     ADF    AZ-23    
       1        MV      27  10      AEF    UB-21    
       1                28  1024    SFS    AE-49    
       1                29  101     QWER   AE-53    
       1                30  109     QWE    AV-63    
       1        MV      31  103    VVBV     AL-94   
       1        MV      32  125    QWEE    AY-36    
       1                33  1292   BGGH    AWF-98
       1                34  1038   WEQWE    WN-81   
       1        MV      35  105    QWEWQ    AQ-98   
       1                36  109    QWE      AWT-88  
       1                37  01     UIO     AX-84    
       1                38  14     GH      AK-18    
       1        MV      39  09     GHJ     XL-13    
       1                40  1025   HFGHL    XW-78   
       1        MV      41  120    HJK     AXY-4    
       1       PSB      42  100    DG     A-18

    In above data when there is vname then 1 is written but in above data there is no Vname in some columns but 1 is mention so how i correct this

     data in alert box (the SQL query which i convert to LINQ)

    [WebMethod]
    public static string GetVo(int ID)
    {


    string
    data2 = "["; try { string fdate = fromdate.Value.Trim().Split('T')[0]; string tdate = todate.Value.Trim().Split('T')[0]; T1 DB = new T1(); var rea = (from rv in DB.tabrv join Reg in DB.tabre on rv.RegionID equals Reg.RegionID join vv in DB.tabvv on rv.ID equals vv.ID where Reg.Region=Convert.ToInt32(regiondrop.SelectedValue) && !(vv.VName == "") && Reg.StartDate == Convert.ToDateTime(fromdate) && Convert.ToDateTime(Reg.EndDate) group vv by vv.VName into g select new { Name = g.Key, cnt = g.Select(t => t.Name).Count() }).ToList(); data2 += rea.ToList().Select(x => "['" + x.Name + "'," + x.cnt + "]") .Aggregate((a, b) => a + "," + b); data2 += "]"; } catch (Exception ex) { throw new Exception(); System.Web.HttpContext currentContext = System.Web.HttpContext.Current; currentContext.Response.Write("<script>alert('" + currentContext.Server.HtmlEncode(ex.ToString()) + "')</script>"); } return data2; }
    }

    when i build above function this shows errors

    Error 6 Operator '&&' cannot be applied to operands of type 'int' and 'bool'

    Error 5 An object reference is required for the non-static field, method, or property 'abc.WebForm1.todate'

    Error 4 An object reference is required for the non-static field, method, or property 'abc.WebForm1.fromdate'

    Error 7 An object reference is required for the non-static field, method, or property 'abc.WebForm1.fromdate'

    now i access drop-down like this

    <script type="text/javascript">
    $('#search_data').click(function () {
        $.ajax({
            type: "POST",
            url: "WebForm1.aspx/GetVo",
            data: JSON.stringify({ ID: $().val('#regiondrop') }),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async: true,
            cache: false,
            success: function (result) {
    
                alert(result.d);
                alert('u');
                //start
                strArray = result.d;
                var myarray = eval(strArray);
    
    
                $('#container').highcharts({
                    chart: {
                        type: 'pie',
                        options3d: {
                            enabled: true,
                            alpha: 45
                        }
                    },
                    title: {
                        text: 'Contents of Highsoft\'s weekly fruit delivery'
                    },
                    subtitle: {
                        text: '3D donut in Highcharts'
                    },
                    plotOptions: {
                        pie: {
                            innerSize: 100,
                            depth: 45
                        }
                    },
                    series: [{
                        name: 'Delivered amount',
                        data: myarray
                    }]
                });
    
                //end
            },
            error: function (error) {
                alert(error);
            }
    
        });
    });
    
    //  });
    
        </script>

    how i access calendar?

    code

    <asp:DropDownList ID="regiondrop" runat="server" AutoPostBack="True" 
     onselectedindexchanged="regiondrop_SelectedIndexChanged">
    </asp:DropDownList>  
    <asp:Label ID="Label1" runat="server" Text="From Date"></asp:Label> 
    <input  ID="fromdate" value="mm/dd/yyyy" runat="server" ClientIDMode="static" />
    <asp:Label ID="Label2" runat="server" Text="To Date"></asp:Label>
    <input  ID="todate" value="mm/dd/yyyy" runat="server" ClientIDMode="static" />
    <input type="button" ID="search_data" runat="server" class="sear_btn"  value="Search Data" OnServerClick="search_data_Click" />

    and i want to data in data2 like this

    [[PSB,'3'],[MV,'7']]

    3 and 7 is beacuse there is 3 PSB in data when i run sql query same for MV is 7

     

     

    Thursday, June 23, 2016 5:45 AM

Answers