Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data;
- using FloatMan.FloatITDEVDataSetTableAdapters;
- using System.Data.OleDb;
- using System.Configuration;
- using Obout.Grid;
- using Obout.Interface;
- using OboutInc.EasyMenu_Pro;
- using Obout.SuperForm;
- using OboutInc.Window;
- using System.Drawing;
- namespace FloatMan
- {
- public partial class Main : System.Web.UI.UserControl
- {
- List<string> TableNames = new List<string>();
- DataTable original = new DataTable();
- double valueTotal = 0;
- protected void Page_Load(object sender, EventArgs e)
- {
- #region Filltable Postback
- {
- var a = UNCAdaptor.GetDataByCurrent();
- foreach (DataRow dr in a.Rows)
- {
- TableNames.Add((string)dr["FloatName"]);
- }
- }
- #endregion
- #region Add Edit Column
- Column EditCol = new Column();
- EditCol.DataField = "EDIT";
- EditCol.Visible = true;
- EditCol.HeaderText = "";
- EditCol.AllowEdit = true;
- EditCol.AllowDelete = true;
- EditCol.AllowSorting = false;
- TestGrid.Columns.Add(EditCol);
- #endregion
- }
- }
- protected int ReturnShareValue(string FloatName)
- {
- zzFloatsTableAdapter ShareAdaptor = new zzFloatsTableAdapter();
- int a = (int)ShareAdaptor.GetFloatValue(FloatName);
- return a;
- }
- protected void starsubmitBtn_Click(object sender, EventArgs e)
- {
- #region Control Declaration
- TextBox textb = SuperForm3.Rows[0].FindControl("StarEntry") as TextBox;
- Label starIdVal = SuperForm3.Rows[0].FindControl("IDval") as Label;
- #endregion
- #region Get Datatable Filled
- foreach (string tablename in TableNames)
- {
- original = FillDataTable(tablename, original);
- AccessDataSource1.SelectCommand += "SELECT zzFloats.FloatName,[" + tablename + "].AllocShares, zzFloats.ShareValue * [" + tablename + "].AllocShares AS ShareValue, [" + tablename + "].StarID, [" + tablename + "].Confirmed,[" + tablename + "].NoShares, [" + tablename + "].Contact, [" + tablename + "].Printed, [" + tablename + "].Flagged, [" + tablename + "].DateStamp, [" + tablename + "].ConfirmedBy, [" + tablename + "].ConfirmedWith, [" + tablename + "].ConfirmMedium FROM [" + tablename + "], zzFloats WHERE (((zzFloats.FloatName)='" + tablename + "') AND (([" + tablename + "].StarID)='" + textb.Text + "')) UNION ALL ";
- }
- #endregion
- AccessDataSource1.SelectCommand = AccessDataSource1.SelectCommand.Substring(0, AccessDataSource1.SelectCommand.Length - 10);
- if (original.Rows.Count == 0)
- {
- starIdVal.Visible = true;
- starIdVal.BackColor = Color.FromArgb(0xE4E4E4);
- #region Disable Grid/SuperForm
- AccessDataSource2.SelectCommand = "";
- AccessDataSource2.DataBind();
- SuperForm1.DataBind();
- TestGrid.DataSource = null;
- TestGrid.DataBind();
- #endregion
- }
- else
- {
- starIdVal.Visible = false;
- #region AccessDatasource and Grid Bind
- string tableNamesDeets = original.Rows[0][5].ToString();
- AccessDataSource2.SelectCommand = "SELECT [StarID], [Name], [Designation], [Status], [Broker] FROM [" + tableNamesDeets + "] WHERE [StarID] = '" + textb.Text + "'";
- AccessDataSource2.DataBind();
- AccessDataSource1.DataBind();
- TestGrid.DataSource = AccessDataSource1;
- TestGrid.DataBind();
- #endregion
- #region Add Edit Column
- Column EditCol = new Column();
- EditCol.DataField = "EDIT";
- EditCol.Visible = true;
- EditCol.HeaderText = "";
- EditCol.AllowEdit = true;
- EditCol.AllowDelete = true;
- EditCol.AllowSorting = false;
- TestGrid.Columns.Add(EditCol);
- #endregion
- #region Create Row Edit Template
- GridRuntimeTemplate RowEditTemplate = new GridRuntimeTemplate();
- RowEditTemplate.ID = "tplRowEdit";
- RowEditTemplate.Template = new Obout.Grid.RuntimeTemplate();
- RowEditTemplate.Template.CreateTemplate += new Obout.Grid.GridRuntimeTemplateEventHandler(CreateRowEditTemplate);
- TestGrid.Templates.Add(RowEditTemplate);
- #endregion
- #region Add Column Names
- foreach (Column col in TestGrid.Columns)
- {
- if(!(col.DataField.Equals("EDIT")))
- col.TemplateSettings.RowEditTemplateControlId = "txt" + col.DataField;
- if (col.DataField.Equals("FloatName") || col.DataField.Equals("AllocShares") || col.DataField.Equals("ShareValue") || col.DataField.Equals("StarID") || col.DataField.Equals("Confirmed") || col.DataField.Equals("EDIT"))
- {
- col.Visible = true;
- }
- else
- col.Visible = false;
- }
- #endregion
- }
- }
- protected DataTable FillGridTable(string _tableName, DataTable origTable)
- {
- using (OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["FloatITDEVConnectionString"].ConnectionString))
- {
- TextBox textb = SuperForm3.Rows[0].FindControl("StarEntry") as TextBox;
- conn.Open();
- OleDbCommand SelectCommand = conn.CreateCommand();
- SelectCommand.CommandText = "SELECT zzFloats.FloatName,[" + _tableName + "].AllocShares, zzFloats.ShareValue * [" + _tableName + "].AllocShares AS ShareValue, [" + _tableName + "].StarID, [" + _tableName + "].Confirmed FROM [" + _tableName + "], zzFloats WHERE (((zzFloats.FloatName)='" + _tableName + "') AND (([" + _tableName + "].StarID)='" + textb.Text + "'))";
- OleDbDataAdapter adapter = new OleDbDataAdapter(SelectCommand);
- adapter.Fill(origTable);
- return origTable;
- }
- }
- protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- if (true)
- {
- e.Row.Cells[3].Text = "Yes";
- }
- else
- {
- e.Row.Cells[3].Text = "No";
- }
- }
- }
- protected void TestGrid_RowDataBound(object sender, Obout.Grid.GridRowEventArgs e)
- {
- if (e.Row.RowType == GridRowType.DataRow)
- {
- valueTotal += Double.Parse(e.Row.Cells[2].Text);
- }
- else if (e.Row.RowType == GridRowType.ColumnFooter && e.Row.Cells.Count > 1)
- {
- e.Row.Cells[2].Text = "Total : $" + valueTotal.ToString();
- valueTotal = 0;
- }
- }
- public void CreateRowEditTemplate(Object sender, Obout.Grid.GridRuntimeTemplateEventArgs e)
- {
- PlaceHolder oPH1 = new PlaceHolder();
- e.Container.Controls.Add(oPH1);
- oPH1.DataBinding += new EventHandler(DataBindRowEditTemplate);
- }
- protected void DataBindRowEditTemplate(Object sender, EventArgs e)
- {
- PlaceHolder oPH1 = sender as PlaceHolder;
- Obout.Grid.TemplateContainer oContainer = oPH1.NamingContainer as Obout.Grid.TemplateContainer;
- Table oTable = new Table();
- TableRow oTr = new TableRow();
- TableCell oCell1 = new TableCell();
- TableCell oCell2 = new TableCell();
- TableCell oCell3 = new TableCell();
- // Client Information
- Panel oPanelClientInformation = new Panel();
- oPanelClientInformation.Attributes["style"] = "width: 300px; height: 180px";
- oPanelClientInformation.GroupingText = "Client Information";
- Table oTableClientInformation = new Table();
- Panel oPanelOrderInformation = new Panel();
- oPanelOrderInformation.Attributes["style"] = "width: 300px; height: 180px";
- oPanelOrderInformation.GroupingText = "Order Information";
- Table oTableOrderInformation = new Table();
- Panel oPanelAdditionalInformation = new Panel();
- oPanelAdditionalInformation.Attributes["style"] = "width: 300px; height: 180px";
- oPanelAdditionalInformation.GroupingText = "Additional Information";
- Table oTableAdditionalInformation = new Table();
- int countcol = TestGrid.Columns.Count - 1;
- foreach(Column co in TestGrid.Columns)
- {
- if (co.DataField != "EDIT" && countcol > 8)
- {
- oTableClientInformation.Rows.Add(CreateTableRowWithTextbox(co.HeaderText + ":", "txt" + co.HeaderText));
- countcol--;
- }
- else
- if (co.DataField != "EDIT" && countcol > 4)
- {
- oTableOrderInformation.Rows.Add(CreateTableRowWithTextbox(co.HeaderText + ":", "txt" + co.HeaderText));
- countcol--;
- }
- else
- if (co.DataField != "EDIT" && countcol > 0)
- {
- oTableAdditionalInformation.Rows.Add(CreateTableRowWithTextbox(co.HeaderText + ":", "txt" + co.HeaderText));
- countcol--;
- }
- }
- oPanelClientInformation.Controls.Add(oTableClientInformation);
- oCell1.Controls.Add(oPanelClientInformation);
- oPanelOrderInformation.Controls.Add(oTableOrderInformation);
- oCell2.Controls.Add(oPanelOrderInformation);
- oPanelAdditionalInformation.Controls.Add(oTableAdditionalInformation);
- oCell3.Controls.Add(oPanelAdditionalInformation);
- oTr.Cells.Add(oCell1);
- oTr.Cells.Add(oCell2);
- oTr.Cells.Add(oCell3);
- oTable.Rows.Add(oTr);
- TableRow oTr2 = new TableRow();
- TableCell oCell2_1 = new TableCell();
- oCell2_1.ColumnSpan = 3;
- oCell2_1.HorizontalAlign = HorizontalAlign.Center;
- Button oSaveButton = new Button();
- oSaveButton.CssClass = "tdText";
- oSaveButton.OnClientClick = "TestGrid.save();return false";
- oSaveButton.Text = "Save";
- Literal oSpacer = new Literal();
- oSpacer.Text = " ";
- Button oCancelButton = new Button();
- oCancelButton.CssClass = "tdText";
- oCancelButton.OnClientClick = "TestGrid.cancel();return false";
- oCancelButton.Text = "Cancel";
- oCell2_1.Controls.Add(oSaveButton);
- oCell2_1.Controls.Add(oSpacer);
- oCell2_1.Controls.Add(oCancelButton);
- oTr2.Controls.Add(oCell2_1);
- oTable.Rows.Add(oTr2);
- oPH1.Controls.Add(oTable);
- }
- #region Create TextBox
- public TableRow CreateTableRowWithTextbox(string sLabelText, string sControlId)
- {
- TableRow oTr = new TableRow();
- TableCell oCell1 = new TableCell();
- TableCell oCell2 = new TableCell();
- Label oLabel = new Label();
- oLabel.Text = sLabelText;
- oCell1.Controls.Add(oLabel);
- OboutTextBox oTextBox = new OboutTextBox();
- oTextBox.ID = sControlId;
- oTextBox.Width = Unit.Pixel(150);
- oCell2.Controls.Add(oTextBox);
- oTr.Cells.Add(oCell1);
- oTr.Cells.Add(oCell2);
- return oTr;
- }
- #endregion
- #region Create CheckBox
- public TableRow CreateTableRowWithCheckbox(string sLabelText, string sControlId)
- {
- TableRow oTr = new TableRow();
- TableCell oCell1 = new TableCell();
- TableCell oCell2 = new TableCell();
- Label oLabel = new Label();
- oLabel.Text = sLabelText;
- oCell1.Controls.Add(oLabel);
- CheckBox oCheckBox = new CheckBox();
- oCheckBox.ID = sControlId;
- oCell2.Controls.Add(oCheckBox);
- oTr.Cells.Add(oCell1);
- oTr.Cells.Add(oCell2);
- return oTr;
- }
- #endregion
- #region Create Empty Row
- public TableRow CreateEmptyTableRow()
- {
- TableRow oTr = new TableRow();
- TableCell oCell1 = new TableCell();
- oCell1.ColumnSpan = 2;
- Literal oLiteral = new Literal();
- oLiteral.Text = "<br />";
- oCell1.Controls.Add(oLiteral);
- oTr.Cells.Add(oCell1);
- return oTr;
- }
- #endregion
- #region Update Client
- void UpdateRecord(object sender, GridRecordEventArgs e)
- {
- //OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/App_Data/FloatITDEV.mdb"));
- //myConn.Open();
- //OleDbCommand myComm = new OleDbCommand("UPDATE Orders SET AllocShares = @AllocShares, Flagged=@Flagged, Printed=@Printed, DateStamp=@DateStamp, ClientDiscussion=@ClientDiscussion, Confirmed=@Confirmed, ConfirmedBy=@ConfirmedBy, ConfirmedWith=@ConfirmedWith, FreeText=@FreeText, ConfirmMedium=@ConfirmMedium WHERE StarID = @StarID", myConn);
- //myComm.Parameters.Add("@AllocShares", OleDbType.VarChar).Value = e.Record["AllocShares"];
- //myComm.Parameters.Add("@Flagged", OleDbType.Date).Value = e.Record["Flagged"];
- //myComm.Parameters.Add("@Printed", OleDbType.Date).Value = e.Record["Printed"];
- //myComm.Parameters.Add("@DateStamp", OleDbType.Integer).Value = e.Record["DateStamp"];
- //myComm.Parameters.Add("@ClientDiscussion", OleDbType.VarChar).Value = e.Record["ClientDiscussion"];
- //myComm.Parameters.Add("@Confirmed", OleDbType.Integer).Value = e.Record["Confirmed"];
- //myComm.Parameters.Add("@ConfirmedBy", OleDbType.Integer).Value = e.Record["ConfirmedBy"];
- //myComm.Parameters.Add("@ConfirmedWith", OleDbType.Integer).Value = e.Record["ConfirmedWith"];
- //myComm.Parameters.Add("@FreeText", OleDbType.Integer).Value = e.Record["FreeText"];
- //myComm.Parameters.Add("@ConfirmMedium", OleDbType.Integer).Value = e.Record["ConfirmMedium"];
- //myComm.ExecuteNonQuery();
- //myConn.Close();
- }
- #endregion
- #region Insert record
- void InsertRecord(object sender, GridRecordEventArgs e)
- {
- //SalutationText.Text = e.Record["StarID"].ToString();
- //OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("../App_Data/Northwind.mdb"));
- //myConn.Open();
- //OleDbCommand myComm = new OleDbCommand("INSERT INTO Orders (ShipName, ShipAddress, ShipCity, ShipRegion, ShipPostalCode, ShipCountry, Sent, OrderDate, RequiredDate, ShippedDate, ShipVia, AdditionalInformation) VALUES(@ShipName, @ShipAddress, @ShipCity, @ShipRegion, @ShipPostalCode, @ShipCountry, @Sent, @OrderDate, @RequiredDate, @ShippedDate, @ShipVia, @AdditionalInformation)", myConn);
- //myComm.Parameters.Add("@AllocShares", OleDbType.VarChar).Value = e.Record["AllocShares"];
- //myComm.Parameters.Add("@Value", OleDbType.Boolean).Value = e.Record["Value"];
- //myComm.Parameters.Add("@PaymentMethod", OleDbType.Date).Value = e.Record["PaymentMethod"];
- //myComm.Parameters.Add("@Flagged", OleDbType.Date).Value = e.Record["Flagged"];
- //myComm.Parameters.Add("@Printed", OleDbType.Date).Value = e.Record["Printed"];
- //myComm.Parameters.Add("@DateStamp", OleDbType.Integer).Value = e.Record["DateStamp"];
- //myComm.Parameters.Add("@ClientDiscussion", OleDbType.VarChar).Value = e.Record["ClientDiscussion"];
- //myComm.Parameters.Add("@Confirmed", OleDbType.Integer).Value = e.Record["Confirmed"];
- //myComm.Parameters.Add("@ConfirmedBy", OleDbType.Integer).Value = e.Record["ConfirmedBy"];
- //myComm.Parameters.Add("@ConfirmedWith", OleDbType.Integer).Value = e.Record["ConfirmedWith"];
- //myComm.Parameters.Add("@FreeText", OleDbType.Integer).Value = e.Record["FreeText"];
- //myComm.Parameters.Add("@ConfirmMedium", OleDbType.Integer).Value = e.Record["ConfirmMedium"];
- //myComm.ExecuteNonQuery();
- //myConn.Close();
- }
- #endregion
- void RebindGrid(object sender, EventArgs e)
- {
- TestGrid.DataBind();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment