using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Web.Configuration; public partial class Orders : System.Web.UI.Page { decimal approvedOSTotal = 0; decimal budgetTotal = 0; decimal actualTotal = 0; decimal varianceTotal = 0; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // Get the ProjectID from the QueryString int projectID = Convert.ToInt32(Request.QueryString["ProjectID"]); //Create dummy data DataTable dt = new DataTable(); DataColumn dc = new DataColumn("Name"); dt.Columns.Add(dc); DataRow dr = dt.NewRow(); dr["Name"] = "Ivan"; this.SqlDataSource1.SelectParameters.Add("ProjectId", "1"); //this.SqlDataSource1.SelectParameters["ProjectId"].DefaultValue = Request.QueryString["ProjectId"]; this.SqlDataSource1.SelectParameters["ProjectId"].DefaultValue = projectID.ToString(); this.SqlDataSource1.SelectParameters.Add("BudgetTypeId", "1"); this.SqlDataSource1.SelectParameters["BudgetTypeId"].DefaultValue = Request.QueryString["BudgetTypeId"]; //GridView1.GridLines = GridLines.Vertical; // Get project details for this project from DB dsProjectTableAdapters.tblProjectTableAdapter projectTableAdapter = new dsProjectTableAdapters.tblProjectTableAdapter(); dsProject.tblProjectDataTable dtProject = new dsProject.tblProjectDataTable(); dsProject.tblProjectRow projectRow; dtProject = projectTableAdapter.GetByID(projectID); // We have a single row of data projectRow = (dsProject.tblProjectRow)dtProject.Rows[0]; // Enable/Disable controls based on role and status ReadWriteManager.SetBudgetDetailsPermissions(projectRow.PPStatus, form1); } //Recurses through the controls to show the naming of each individual control that is currently in the gridview // Response.Write(Request.ServerVariables["LOGON_USER"] + "<br>"); // Response.Write("User Authenticated " + User.Identity.IsAuthenticated.ToString() + "<br>"); String[] userNames; String userName; userNames = User.Identity.Name.Split('\\'); ////Response.Write("validateUser " + Membership.ValidateUser(userNames[1], "<br>")); //if (Roles.IsUserInRole(userNames[1], "RoleAdmin")) //{ // GridView1.Visible = true; // DetailsView1.Enabled = true; // GridView1.Enabled = true; // this.form1.Visible = true; //} //else //{ // this.form1.Visible = false; // this.GridView1.Visible = false; //} // This approach allows you to dynamically assign connection string and sp to the SqlDataSource // UI also contains binding in a form this.SqlDataSource1.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["cnPPDB"].ToString(); this.SqlDataSource1.SelectCommandType = SqlDataSourceCommandType.StoredProcedure; this.SqlDataSource1.SelectCommand = "mspBudgetGetByProjectID"; this.SqlDataSource1.UpdateCommandType = SqlDataSourceCommandType.StoredProcedure; this.SqlDataSource1.UpdateCommand = "mspBudgetUpdateByProjectID"; //SqlDataSource2.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["cnPPDB"]; OrderDB odb = new OrderDB(); } protected void btnSearch_Click(object sender, EventArgs e) { //String sqlStr; //sqlStr = "SELECT [ID], [amount],[ZIP], [Description] FROM [tblZIP] where [ZIP] LIKE '%?%'"; //GridView1.DataBind(); //DataSet ds; //String strConnection; ////strConnection = "Data Source=(local);Initial Catalog=pubs;Integrated Security=SSPI;"; //strConnection = "Server=abhalesha;Database=pubs;uid=sa;pwd=password123;";//Trusted_Connection=True;"; //ds = SqlDataHelper.ExecuteDataset(strConnection, CommandType.Text, "select * from titles"); //int i; //i = ds.Tables[0].Rows.Count; //Response.Write(i.ToString()); } protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e) { if (e.Exception != null) { Response.Write("An error occured while entering this record. Please verify you have entered data in the correct format."); e.ExceptionHandled = true; } GridView1.DataBind(); } protected void DetailsView1_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e) { GridView1.DataBind(); } protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { int index = GridView1.SelectedIndex; int orderID; txtBudgetAccountId.Text = GridView1.DataKeys[index].Values[1].ToString(); txtProjectId.Text = GridView1.DataKeys[index].Values[0].ToString(); } protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { int index = GridView1.SelectedIndex; if (index >= 0) { txtBudgetAccountId.Text = GridView1.DataKeys[index].Values[1].ToString(); txtProjectId.Text = GridView1.DataKeys[index].Values[0].ToString(); } } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { int index = GridView1.SelectedIndex; if (index >= 0) { txtBudgetAccountId.Text = GridView1.DataKeys[index].Values[1].ToString(); txtProjectId.Text = GridView1.DataKeys[index].Values[0].ToString(); } } protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e) { int index = GridView1.SelectedIndex; if (index >= 0) { txtBudgetAccountId.Text = GridView1.DataKeys[index].Values[1].ToString(); txtProjectId.Text = GridView1.DataKeys[index].Values[0].ToString(); } } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { bool b; if (e.Row.RowType == DataControlRowType.DataRow) { try { b = Convert.ToBoolean(DataBinder.Eval(e.Row.DataItem, "ParentWithChildren")); if (b == true) { e.Row.Cells[9].Enabled = false; // e.Row.Cells[0].Text = "url"; } // add to the running total variables if (DataBinder.Eval(e.Row.DataItem, "ApprovedBudget").ToString().Length > 0) approvedOSTotal += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ApprovedBudget")); if(DataBinder.Eval(e.Row.DataItem, "Expected").ToString().Length>0) budgetTotal += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Expected")); if(DataBinder.Eval(e.Row.DataItem, "Actual").ToString().Length > 0) actualTotal += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Actual")); if(DataBinder.Eval(e.Row.DataItem, "Variance").ToString().Length > 0) varianceTotal += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Variance")); // Display integers for HR & Beneficiaries // Able to set to ints, but not editable //if (Convert.ToInt32(Request.QueryString["BudgetTypeID"]) > 2) //{ // DataRowView drv = e.Row.DataItem as DataRowView; // Object ob = drv["ApprovedBudget"]; // if (!Convert.IsDBNull(ob)) // { // Decimal iParsedValue = 0; // if (Decimal.TryParse(ob.ToString(), out iParsedValue)) // { // TableCell cell = e.Row.Cells[5]; // cell.Text = String.Format("{0:F0}", (Object)iParsedValue); // } // } // ob = drv["Expected"]; // if (!Convert.IsDBNull(ob)) // { // Decimal iParsedValue = 0; // if (Decimal.TryParse(ob.ToString(), out iParsedValue)) // { // TableCell cell = e.Row.Cells[6]; // cell.Text = String.Format("{0:F0}", (Object)iParsedValue); // } // } // ob = drv["Actual"]; // if (!Convert.IsDBNull(ob)) // { // Decimal iParsedValue = 0; // if (Decimal.TryParse(ob.ToString(), out iParsedValue)) // { // TableCell cell = e.Row.Cells[7]; // //cell.Text = String.Format("{0:#,###}", new object[] { iParsedValue }); // //cell.Text = String.Format("{0:F2}", new object[] { iParsedValue }); // cell.Text = String.Format("{0:F0}", (Object)iParsedValue); // } // } // ob = drv["Variance"]; // if (!Convert.IsDBNull(ob)) // { // Decimal iParsedValue = 0; // if (Decimal.TryParse(ob.ToString(), out iParsedValue)) // { // TableCell cell = e.Row.Cells[8]; // cell.Text = String.Format("{0:F0}", (Object)iParsedValue); // } // } //} } catch(Exception ex) { throw (ex); approvedOSTotal = approvedOSTotal; budgetTotal = budgetTotal; actualTotal = actualTotal; varianceTotal = varianceTotal; } if (b == true) { e.Row.Cells[9].Enabled = false; e.Row.Cells[9].Text = ""; e.Row.Cells[10].Enabled = false; e.Row.Cells[10].Text = ""; //e.Row.Cells[3].Text = "anchor"; } // Determine if O&S details should be editable e.Row.Cells[5].Enabled = ReadWriteManager.GetOSBudgetEditPermissions(); }//Determines the type of row it's a footer we will add running totals else if (e.Row.RowType == DataControlRowType.Footer) { //don't show totals for HR & Beneficiaries tabs // Hard coded, so this is bad! if (Convert.ToInt32(Request.QueryString["BudgetTypeID"]) < 3) { e.Row.Cells[3].Text = "Totals:"; // for the Footer, display the running totals e.Row.Cells[5].Text = approvedOSTotal.ToString("c"); e.Row.Cells[6].Text = budgetTotal.ToString("c"); e.Row.Cells[7].Text = actualTotal.ToString("c"); e.Row.Cells[8].Text = varianceTotal.ToString("c"); e.Row.Cells[5].HorizontalAlign = e.Row.Cells[6].HorizontalAlign = e.Row.Cells[7].HorizontalAlign = e.Row.Cells[8].HorizontalAlign = HorizontalAlign.Right; e.Row.Font.Bold = true; } } } void RecurseControls(ControlCollection ctls) { foreach (Control ctl in ctls) { if (!ctl.HasControls()) Label1.Text += ctl.ClientID + " " + ctl.GetType().Name + "<br />"; else RecurseControls(ctl.Controls); } } protected void GridView1_RowCommand1(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "EmptyInsert") { //handle insert here TextBox tbEmptyInsert = GridView1.Controls[0].Controls[0].FindControl("tbEmptyInsert") as TextBox; Label1.Text = string.Format("You would have inserted the name : <b>{0}</b> from the emptydatatemplate",tbEmptyInsert.Text); } if (e.CommandName == "Insert") { //handle insert here TextBox tbInsert = GridView1.FooterRow.FindControl("tbInsert") as TextBox; Label1.Text = string.Format("You would have inserted the name : <b>{0}</b> from the footerrow", tbInsert.Text); } } }