Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
below are the formulae., to use in the code
Criteria:

% Down Time : (down time / 8*date diff)*100

Average % Down Time by no of complaints : Sum of % down time / no of complaints

Average % Down Time by no of System under AMC : (Sum of Down time for 8hrs / 4000*90*8) * 100

% of complaints taken more than 3 days:(No of complaints More Than 2 days/Total No of complaints)*100

C#
public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        string assign = Session["assignee"].ToString();
        string sda = Session["sdate"].ToString();
        string eda = Session["edate"].ToString();
        string gd = Session["gdt"].ToString();
        string ld = Session["ldt"].ToString();

        # region sqlconnection
        //SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["kaseyaConnectionString3"].ConnectionString);
         //string select = "select str((SUM([percent])/count([percent])),7,2) from Datediff$ where [Assignee] = '" + assign + "' AND [Creation_date] >='" + sda + "' AND [Creation_date] <= '" + eda + "'  and [Calculated(on time)] >= '" + gd + "' AND [Calculated(on time)] <= '" + ld + "' ";
         SqlCommand cmd = new SqlCommand();
         cmd.Connection = con;
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = select;
         con.Open();
         Label1.Text = cmd.ExecuteScalar().ToString();
         con.Close();

         string select2 = "select str(((SUM([Calculated(on time)])/(4000*90*8))*100),7,2) from Datediff$ where [Assignee] = '" + assign + "' AND [Creation_date] >='" + sda + "' AND [Creation_date] <= '" + eda + "'  and [Calculated(on time)] >= '" + gd + "' AND [Calculated(on time)] <= '" + ld + "' ";
         SqlCommand cmd2 = new SqlCommand();
         cmd2.Connection = con;
         cmd2.CommandType = CommandType.Text;
         cmd2.CommandText = select2;
         con.Open();
         Label2.Text = cmd2.ExecuteScalar().ToString();
         con.Close();


         string select3 = "select max([Calculated(on time)]) from Datediff$  where [Assignee] = '" + assign + "' AND [Creation_date] >='" + sda + "' AND [Creation_date] <= '" + eda + "' and [Calculated(on time)] >= '" + gd + "' AND [Calculated(on time)] <= '" + ld + "' ";
         SqlCommand cmd3 = new SqlCommand();
         cmd3.Connection = con;
         cmd3.CommandType = CommandType.Text;
         cmd3.CommandText = select3;
         con.Open();
         Label3.Text = cmd3.ExecuteScalar().ToString();
         con.Close();


         string select4 = "select min([Calculated(on time)]) from Datediff$  where [Assignee] = '" + assign + "' AND [Creation_date] >='" + sda + "' AND [Creation_date] <= '" + eda + "'  and [Calculated(on time)] >= '" + gd + "' AND [Calculated(on time)] <= '" + ld + "' ";
         SqlCommand cmd4 = new SqlCommand();
         cmd4.Connection = con;
         cmd4.CommandType = CommandType.Text;
         cmd4.CommandText = select4;
         con.Open();
         Label4.Text = cmd4.ExecuteScalar().ToString();
         con.Close();


         string select5 = "select min([percent]) from Datediff$   where [Assignee] = '" + assign + "' AND [Creation_date] >='" + sda + "' AND [Creation_date] <= '" + eda + "' AND [Calculated(on time)] >= '" + gd + "' AND [Calculated(on time)] <= '" + ld + "' ";
        // string select5 = "select str(((cast(c.a as float)/cast(d.b as float))*100),7,2)  from  (select COUNT(Time_diff) a  from datediff$ n where n.Time_diff>72 and [Assignee] = '" + assign + "' AND [Creation_date] >='" + sda + "' AND [Creation_date] <= '" + eda + "' and [Calculated(on time)] >= '" + gd + "' AND [Calculated(on time)] <= '" + ld + "') c,(select COUNT(Time_diff) b from datediff$ where [Assignee] = '" + assign + "' AND [Creation_date] >='" + sda + "' AND [Creation_date] <= '" + eda + "'  and [Calculated(on time)] >= '" + gd + "' AND [Calculated(on time)] <= '" + ld + "') d";

        //SqlCommand cmd5 = new SqlCommand();
        // cmd5.Connection = con;
        // cmd5.CommandType = CommandType.Text;
        // cmd5.CommandText = select5;
        // con.Open();
        // Label5.Text = cmd5.ExecuteScalar().ToString();
        // con.Close();
        #endregion
        OleDbConnection con = new OleDbConnection("provider=microsoft.jet.oledb.4.0;Data source=E:\\downtime2\\App_Data\\datediff$.mdb");
        //str((SUM([percent])/count([percent])),7,2)

        string str = "select str((SUM([Calculated(on time)])/count([Calculated(on time)])),7,2) from datediff$ where Assignee = '" + assign + "' and [Creation_date] >='" + sda + "' and [Creation_date] <= '" + eda + "'  and [Calculated(on time)] >= '" + gd + "' and [Calculated(on time)] <= '" + ld + "' ";
      //string str =  "select * from datediff$ where Assignee = '" + assign + "'";
      //  string str = "select sum([id1])/count([id1]) from calculation where id1 between'" + sda + "' and '" + eda + "'";
        OleDbCommand cmd = new OleDbCommand();
        cmd.Connection = con;
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = str;
        con.Open();
        //OleDbDataReader dr = cmd.ExecuteReader();
       Label1.Text = cmd.ExecuteScalar().ToString();
       //cmd.ExecuteNonQuery().ToString();
        //Label1.Text = assign;
        con.Close();

        string select2 = "select str(((SUM([Calculated(on time)])/(4000*90*8))*100),7,2) from datediff$ where [Assignee] = '" + assign + "' AND [Creation_date] >='" + sda + "' AND [Creation_date] <= '" + eda + "'  and [Calculated(on time)] >= '" + gd + "' AND [Calculated(on time)] <= '" + ld + "' ";
        OleDbCommand cmd2 = new OleDbCommand();
        cmd2.Connection = con;
        cmd2.CommandType = CommandType.Text;
        cmd2.CommandText = select2;
        con.Open();
        Label2.Text = cmd2.ExecuteScalar().ToString();
        con.Close();


        string select3 = "select max([Calculated(on time)]) from datediff$  where [Assignee] = '" + assign + "' AND [Creation_date] >='" + sda + "' AND [Creation_date] <= '" + eda + "' and [Calculated(on time)] >= '" + gd + "' AND [Calculated(on time)] <= '" + ld + "' ";
        OleDbCommand cmd3 = new OleDbCommand();
        cmd3.Connection = con;
        cmd3.CommandType = CommandType.Text;
        cmd3.CommandText = select3;
        con.Open();
        Label3.Text = cmd3.ExecuteScalar().ToString();
        con.Close();


        string select4 = "select min([Calculated(on time)]) from datediff$  where [Assignee] = '" + assign + "' AND [Creation_date] >='" + sda + "' AND [Creation_date] <= '" + eda + "'  and [Calculated(on time)] >= '" + gd + "' AND [Calculated(on time)] <= '" + ld + "' ";
        OleDbCommand cmd4 = new OleDbCommand();
        cmd4.Connection = con;
        cmd4.CommandType = CommandType.Text;
        cmd4.CommandText = select4;
        con.Open();
        Label4.Text = cmd4.ExecuteScalar().ToString();
        con.Close();


        // string select5 = "select min([percent]) from Datediff$   where [Assignee] = '" + assign + "' AND [Creation_date] >='" + sda + "' AND [Creation_date] <= '" + eda + "' AND [Calculated(on time)] >= '" + gd + "' AND [Calculated(on time)] <= '" + ld + "' ";
        string select5 = "select str(((cast(c.a as float)/cast(d.b as float))*100),7,2)  from  (select COUNT(Time_diff) a  from datediff$ n where n.Time_diff>72 and [Assignee] = '" + assign + "' AND [Creation_date] >='" + sda + "' AND [Creation_date] <= '" + eda + "' and [Calculated(on time)] >= '" + gd + "' AND [Calculated(on time)] <= '" + ld + "') c,(select COUNT(Time_diff) b from datediff$ where [Assignee] = '" + assign + "' AND [Creation_date] >='" + sda + "' AND [Creation_date] <= '" + eda + "'  and [Calculated(on time)] >= '" + gd + "' AND [Calculated(on time)] <= '" + ld + "') d";
        OleDbCommand cmd5 = new OleDbCommand();
        cmd5.Connection = con;
        cmd5.CommandType = CommandType.Text;
        cmd5.CommandText = select5;
        con.Open();
        Label5.Text = cmd5.ExecuteScalar().ToString();
        con.Close();
    }
}
Posted
Updated 8-Oct-13 21:19pm
v2
Comments
Ron Beyer 9-Oct-13 0:33am    
What you posted has nothing to do with your error or formula (everything is commented out). Can you update the question with the actual code and point out exactly what error you are getting and on what line you are getting it on? Its impossible for us to reproduce your error, read your mind, or see your computer.
Member 10322487 9-Oct-13 0:35am    
error is coming at line 70 to 85.
Member 10322487 9-Oct-13 0:36am    
error is coming at sql clause i.e.,79 to 85 line
Ron Beyer 9-Oct-13 0:43am    
How do we know what those line numbers are?
Richard MacCutchan 9-Oct-13 3:22am    
What are the error messages and where do they occur? You would also be well advised to read http://bobby-tables.com/.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900