Don't like ads? PRO users don't see any ads ;-)
Guest

main.ascx.cs

By: akshey_dixit on May 1st, 2012  |  syntax: C#  |  size: 17.81 KB  |  hits: 39  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data;
  8. using FloatMan.FloatITDEVDataSetTableAdapters;
  9. using System.Data.OleDb;
  10. using System.Configuration;
  11. using Obout.Grid;
  12. using Obout.Interface;
  13. using OboutInc.EasyMenu_Pro;
  14. using Obout.SuperForm;
  15. using OboutInc.Window;
  16. using System.Drawing;
  17.  
  18.  
  19. namespace FloatMan
  20. {
  21.     public partial class Main : System.Web.UI.UserControl
  22.     {
  23.         List<string> TableNames = new List<string>();
  24.  
  25.         DataTable original = new DataTable();
  26.                
  27.         double valueTotal = 0;
  28.  
  29.                
  30.  
  31.  
  32.         protected void Page_Load(object sender, EventArgs e)
  33.         {
  34.            
  35.             #region Filltable Postback
  36.  
  37.             {
  38.                 var a =  UNCAdaptor.GetDataByCurrent();
  39.                 foreach (DataRow dr in a.Rows)
  40.                 {
  41.                     TableNames.Add((string)dr["FloatName"]);
  42.  
  43.                 }
  44.                                                                            
  45.             }
  46.             #endregion
  47.  
  48.             #region Add Edit Column
  49.  
  50.             Column EditCol = new Column();
  51.             EditCol.DataField = "EDIT";
  52.             EditCol.Visible = true;
  53.             EditCol.HeaderText = "";
  54.             EditCol.AllowEdit = true;
  55.             EditCol.AllowDelete = true;
  56.             EditCol.AllowSorting = false;
  57.  
  58.             TestGrid.Columns.Add(EditCol);
  59.             #endregion
  60.         }
  61.                }
  62.        
  63.         protected int ReturnShareValue(string FloatName)
  64.         {
  65.             zzFloatsTableAdapter ShareAdaptor = new zzFloatsTableAdapter();
  66.  
  67.             int a = (int)ShareAdaptor.GetFloatValue(FloatName);
  68.  
  69.  
  70.  
  71.             return a;
  72.         }
  73.  
  74.         protected void starsubmitBtn_Click(object sender, EventArgs e)
  75.         {
  76.  
  77.             #region Control Declaration
  78.             TextBox textb = SuperForm3.Rows[0].FindControl("StarEntry") as TextBox;
  79.  
  80.             Label starIdVal = SuperForm3.Rows[0].FindControl("IDval") as Label;
  81.  
  82.             #endregion
  83.  
  84.  
  85.             #region Get Datatable Filled
  86.             foreach (string tablename in TableNames)
  87.             {
  88.                 original = FillDataTable(tablename, original);
  89.  
  90.  
  91.                 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 ";
  92.                
  93.             }
  94.             #endregion
  95.                                    
  96.             AccessDataSource1.SelectCommand =  AccessDataSource1.SelectCommand.Substring(0, AccessDataSource1.SelectCommand.Length - 10);
  97.            
  98.             if (original.Rows.Count == 0)
  99.             {
  100.                 starIdVal.Visible = true;
  101.                 starIdVal.BackColor = Color.FromArgb(0xE4E4E4);
  102.  
  103.                 #region Disable Grid/SuperForm
  104.                
  105.                 AccessDataSource2.SelectCommand = "";
  106.                 AccessDataSource2.DataBind();
  107.                 SuperForm1.DataBind();
  108.                 TestGrid.DataSource = null;
  109.                 TestGrid.DataBind();
  110.                 #endregion
  111.             }
  112.             else
  113.             {
  114.                 starIdVal.Visible = false;
  115.  
  116.                 #region AccessDatasource and Grid Bind
  117.                 string tableNamesDeets = original.Rows[0][5].ToString();
  118.                 AccessDataSource2.SelectCommand = "SELECT [StarID], [Name], [Designation], [Status], [Broker] FROM [" + tableNamesDeets + "] WHERE [StarID] = '" + textb.Text + "'";
  119.                 AccessDataSource2.DataBind();
  120.                 AccessDataSource1.DataBind();
  121.                 TestGrid.DataSource = AccessDataSource1;
  122.                 TestGrid.DataBind();
  123.                 #endregion
  124.  
  125.  
  126.                 #region Add Edit Column
  127.  
  128.                 Column EditCol = new Column();
  129.                 EditCol.DataField = "EDIT";
  130.                 EditCol.Visible = true;
  131.                 EditCol.HeaderText = "";
  132.                 EditCol.AllowEdit = true;
  133.                 EditCol.AllowDelete = true;
  134.                 EditCol.AllowSorting = false;
  135.  
  136.                 TestGrid.Columns.Add(EditCol);
  137.                 #endregion
  138.                                
  139.                                
  140.                 #region Create Row Edit Template
  141.                 GridRuntimeTemplate RowEditTemplate = new GridRuntimeTemplate();
  142.                 RowEditTemplate.ID = "tplRowEdit";
  143.                 RowEditTemplate.Template = new Obout.Grid.RuntimeTemplate();
  144.                 RowEditTemplate.Template.CreateTemplate += new Obout.Grid.GridRuntimeTemplateEventHandler(CreateRowEditTemplate);
  145.  
  146.                 TestGrid.Templates.Add(RowEditTemplate);
  147.                 #endregion
  148.  
  149.  
  150.                 #region Add Column Names
  151.  
  152.                
  153.                 foreach (Column col in TestGrid.Columns)
  154.                 {
  155.                     if(!(col.DataField.Equals("EDIT")))
  156.                     col.TemplateSettings.RowEditTemplateControlId = "txt" + col.DataField;
  157.                     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"))
  158.                     {
  159.                         col.Visible = true;
  160.                     }
  161.                     else
  162.                         col.Visible = false;              
  163.                 }
  164.                
  165.                
  166.                 #endregion
  167.  
  168.            }
  169.         }
  170.  
  171.         protected DataTable FillGridTable(string _tableName, DataTable origTable)
  172.         {
  173.             using (OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["FloatITDEVConnectionString"].ConnectionString))
  174.             {
  175.                 TextBox textb = SuperForm3.Rows[0].FindControl("StarEntry") as TextBox;
  176.                 conn.Open();
  177.  
  178.                 OleDbCommand SelectCommand = conn.CreateCommand();
  179.  
  180.                 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 + "'))";
  181.                
  182.                 OleDbDataAdapter adapter = new OleDbDataAdapter(SelectCommand);
  183.  
  184.                 adapter.Fill(origTable);
  185.  
  186.                
  187.                 return origTable;
  188.             }
  189.  
  190.  
  191.         }
  192.  
  193.         protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
  194.         {
  195.             if (e.Row.RowType == DataControlRowType.DataRow)
  196.             {
  197.  
  198.                 if (true)
  199.                 {
  200.                     e.Row.Cells[3].Text = "Yes";
  201.                 }
  202.                 else
  203.                 {
  204.                     e.Row.Cells[3].Text = "No";
  205.                 }
  206.             }
  207.         }
  208.  
  209.         protected void TestGrid_RowDataBound(object sender, Obout.Grid.GridRowEventArgs e)
  210.         {
  211.            
  212.  
  213.             if (e.Row.RowType == GridRowType.DataRow)
  214.             {              
  215.  
  216.                 valueTotal +=  Double.Parse(e.Row.Cells[2].Text);
  217.  
  218.             }
  219.             else if (e.Row.RowType == GridRowType.ColumnFooter && e.Row.Cells.Count > 1)
  220.             {
  221.                 e.Row.Cells[2].Text = "Total : $" + valueTotal.ToString();
  222.  
  223.                 valueTotal = 0;
  224.             }
  225.          }
  226.  
  227.  
  228.        public void CreateRowEditTemplate(Object sender, Obout.Grid.GridRuntimeTemplateEventArgs e)
  229.        {
  230.            PlaceHolder oPH1 = new PlaceHolder();
  231.            e.Container.Controls.Add(oPH1);
  232.            oPH1.DataBinding += new EventHandler(DataBindRowEditTemplate);
  233.        }
  234.  
  235.        protected void DataBindRowEditTemplate(Object sender, EventArgs e)
  236.        {
  237.            PlaceHolder oPH1 = sender as PlaceHolder;
  238.            Obout.Grid.TemplateContainer oContainer = oPH1.NamingContainer as Obout.Grid.TemplateContainer;
  239.  
  240.            Table oTable = new Table();
  241.            
  242.  
  243.            TableRow oTr = new TableRow();
  244.  
  245.            TableCell oCell1 = new TableCell();
  246.            TableCell oCell2 = new TableCell();
  247.            TableCell oCell3 = new TableCell();
  248.  
  249.            // Client Information
  250.            Panel oPanelClientInformation = new Panel();
  251.            oPanelClientInformation.Attributes["style"] = "width: 300px; height: 180px";
  252.            oPanelClientInformation.GroupingText = "Client Information";
  253.            Table oTableClientInformation = new Table();
  254.  
  255.            Panel oPanelOrderInformation = new Panel();
  256.            oPanelOrderInformation.Attributes["style"] = "width: 300px; height: 180px";
  257.            oPanelOrderInformation.GroupingText = "Order Information";
  258.            Table oTableOrderInformation = new Table();
  259.  
  260.            Panel oPanelAdditionalInformation = new Panel();
  261.            oPanelAdditionalInformation.Attributes["style"] = "width: 300px; height: 180px";
  262.            oPanelAdditionalInformation.GroupingText = "Additional Information";
  263.            Table oTableAdditionalInformation = new Table();
  264.  
  265.            int countcol = TestGrid.Columns.Count - 1;
  266.  
  267.            foreach(Column co in TestGrid.Columns)
  268.            {
  269.                if (co.DataField != "EDIT" && countcol > 8)
  270.                {
  271.                    oTableClientInformation.Rows.Add(CreateTableRowWithTextbox(co.HeaderText + ":", "txt" + co.HeaderText));
  272.                    countcol--;
  273.                }
  274.                else
  275.                    if (co.DataField != "EDIT" && countcol > 4)
  276.                    {
  277.                        oTableOrderInformation.Rows.Add(CreateTableRowWithTextbox(co.HeaderText + ":", "txt" + co.HeaderText));
  278.                        countcol--;
  279.                    }
  280.                    else
  281.                        if (co.DataField != "EDIT" && countcol > 0)
  282.                        {
  283.                            oTableAdditionalInformation.Rows.Add(CreateTableRowWithTextbox(co.HeaderText + ":", "txt" + co.HeaderText));
  284.                            countcol--;
  285.                        }
  286.            }
  287.  
  288.  
  289.            oPanelClientInformation.Controls.Add(oTableClientInformation);
  290.            oCell1.Controls.Add(oPanelClientInformation);
  291.  
  292.            oPanelOrderInformation.Controls.Add(oTableOrderInformation);
  293.            oCell2.Controls.Add(oPanelOrderInformation);
  294.  
  295.            oPanelAdditionalInformation.Controls.Add(oTableAdditionalInformation);
  296.            oCell3.Controls.Add(oPanelAdditionalInformation);
  297.  
  298.          
  299.            oTr.Cells.Add(oCell1);
  300.            oTr.Cells.Add(oCell2);
  301.            oTr.Cells.Add(oCell3);
  302.            oTable.Rows.Add(oTr);
  303.  
  304.            TableRow oTr2 = new TableRow();
  305.            TableCell oCell2_1 = new TableCell();
  306.            oCell2_1.ColumnSpan = 3;
  307.            oCell2_1.HorizontalAlign = HorizontalAlign.Center;
  308.  
  309.            Button oSaveButton = new Button();
  310.            oSaveButton.CssClass = "tdText";
  311.            oSaveButton.OnClientClick = "TestGrid.save();return false";
  312.            
  313.            oSaveButton.Text = "Save";
  314.  
  315.            Literal oSpacer = new Literal();
  316.            oSpacer.Text = " ";
  317.  
  318.            Button oCancelButton = new Button();
  319.            oCancelButton.CssClass = "tdText";
  320.            oCancelButton.OnClientClick = "TestGrid.cancel();return false";
  321.            oCancelButton.Text = "Cancel";
  322.  
  323.            oCell2_1.Controls.Add(oSaveButton);
  324.            oCell2_1.Controls.Add(oSpacer);
  325.            oCell2_1.Controls.Add(oCancelButton);
  326.            oTr2.Controls.Add(oCell2_1);
  327.  
  328.            oTable.Rows.Add(oTr2);
  329.  
  330.            oPH1.Controls.Add(oTable);
  331.        }
  332.  
  333.        #region Create TextBox
  334.        
  335.        public TableRow CreateTableRowWithTextbox(string sLabelText, string sControlId)
  336.        {
  337.            TableRow oTr = new TableRow();
  338.            TableCell oCell1 = new TableCell();
  339.            TableCell oCell2 = new TableCell();
  340.  
  341.            Label oLabel = new Label();
  342.            oLabel.Text = sLabelText;
  343.            oCell1.Controls.Add(oLabel);
  344.  
  345.            OboutTextBox oTextBox = new OboutTextBox();
  346.            oTextBox.ID = sControlId;
  347.            oTextBox.Width = Unit.Pixel(150);
  348.  
  349.            oCell2.Controls.Add(oTextBox);
  350.  
  351.            oTr.Cells.Add(oCell1);
  352.            oTr.Cells.Add(oCell2);
  353.  
  354.            return oTr;
  355.        }
  356.        #endregion
  357.  
  358.        #region Create CheckBox
  359.  
  360.        public TableRow CreateTableRowWithCheckbox(string sLabelText, string sControlId)
  361.        {
  362.            TableRow oTr = new TableRow();
  363.            TableCell oCell1 = new TableCell();
  364.            TableCell oCell2 = new TableCell();
  365.  
  366.            Label oLabel = new Label();
  367.            oLabel.Text = sLabelText;
  368.            oCell1.Controls.Add(oLabel);
  369.  
  370.            CheckBox oCheckBox = new CheckBox();
  371.            oCheckBox.ID = sControlId;
  372.            oCell2.Controls.Add(oCheckBox);
  373.  
  374.            oTr.Cells.Add(oCell1);
  375.            oTr.Cells.Add(oCell2);
  376.  
  377.            return oTr;
  378.        }
  379.        #endregion
  380.  
  381.        #region Create Empty Row
  382.        public TableRow CreateEmptyTableRow()
  383.        {
  384.            TableRow oTr = new TableRow();
  385.            TableCell oCell1 = new TableCell();
  386.            oCell1.ColumnSpan = 2;
  387.  
  388.            Literal oLiteral = new Literal();
  389.            oLiteral.Text = "<br />";
  390.  
  391.            oCell1.Controls.Add(oLiteral);
  392.            oTr.Cells.Add(oCell1);
  393.  
  394.            return oTr;
  395.        }
  396.         #endregion
  397.  
  398.        #region Update Client
  399.        void UpdateRecord(object sender, GridRecordEventArgs e)
  400.        {
  401.            //OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/App_Data/FloatITDEV.mdb"));
  402.            //myConn.Open();
  403.  
  404.            //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);
  405.  
  406.  
  407.            //myComm.Parameters.Add("@AllocShares", OleDbType.VarChar).Value = e.Record["AllocShares"];
  408.            //myComm.Parameters.Add("@Flagged", OleDbType.Date).Value = e.Record["Flagged"];
  409.            //myComm.Parameters.Add("@Printed", OleDbType.Date).Value = e.Record["Printed"];
  410.            //myComm.Parameters.Add("@DateStamp", OleDbType.Integer).Value = e.Record["DateStamp"];
  411.            //myComm.Parameters.Add("@ClientDiscussion", OleDbType.VarChar).Value = e.Record["ClientDiscussion"];
  412.            //myComm.Parameters.Add("@Confirmed", OleDbType.Integer).Value = e.Record["Confirmed"];
  413.            //myComm.Parameters.Add("@ConfirmedBy", OleDbType.Integer).Value = e.Record["ConfirmedBy"];
  414.            //myComm.Parameters.Add("@ConfirmedWith", OleDbType.Integer).Value = e.Record["ConfirmedWith"];
  415.            //myComm.Parameters.Add("@FreeText", OleDbType.Integer).Value = e.Record["FreeText"];
  416.            //myComm.Parameters.Add("@ConfirmMedium", OleDbType.Integer).Value = e.Record["ConfirmMedium"];
  417.  
  418.            //myComm.ExecuteNonQuery();
  419.            //myConn.Close();
  420.        }  
  421.        #endregion
  422.  
  423.        #region Insert record
  424.        void InsertRecord(object sender, GridRecordEventArgs e)
  425.        {
  426.  
  427.            //SalutationText.Text = e.Record["StarID"].ToString();
  428.            
  429.            //OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("../App_Data/Northwind.mdb"));
  430.            //myConn.Open();
  431.  
  432.            //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);
  433.  
  434.            //myComm.Parameters.Add("@AllocShares", OleDbType.VarChar).Value = e.Record["AllocShares"];
  435.            //myComm.Parameters.Add("@Value", OleDbType.Boolean).Value = e.Record["Value"];
  436.            //myComm.Parameters.Add("@PaymentMethod", OleDbType.Date).Value = e.Record["PaymentMethod"];
  437.            //myComm.Parameters.Add("@Flagged", OleDbType.Date).Value = e.Record["Flagged"];
  438.            //myComm.Parameters.Add("@Printed", OleDbType.Date).Value = e.Record["Printed"];
  439.            //myComm.Parameters.Add("@DateStamp", OleDbType.Integer).Value = e.Record["DateStamp"];
  440.            //myComm.Parameters.Add("@ClientDiscussion", OleDbType.VarChar).Value = e.Record["ClientDiscussion"];
  441.            //myComm.Parameters.Add("@Confirmed", OleDbType.Integer).Value = e.Record["Confirmed"];
  442.            //myComm.Parameters.Add("@ConfirmedBy", OleDbType.Integer).Value = e.Record["ConfirmedBy"];
  443.            //myComm.Parameters.Add("@ConfirmedWith", OleDbType.Integer).Value = e.Record["ConfirmedWith"];
  444.            //myComm.Parameters.Add("@FreeText", OleDbType.Integer).Value = e.Record["FreeText"];
  445.            //myComm.Parameters.Add("@ConfirmMedium", OleDbType.Integer).Value = e.Record["ConfirmMedium"];
  446.  
  447.            //myComm.ExecuteNonQuery();
  448.            //myConn.Close();
  449.        }
  450.        #endregion
  451.  
  452.      
  453.        void RebindGrid(object sender, EventArgs e)
  454.        {
  455.            TestGrid.DataBind();
  456.        }
  457.                
  458.     }
  459.  
  460.    
  461. }