protected void WriteEmptyTemplate(DataRow[] pRows, string pIndnt) { _ColsStream.WriteLine(pIndnt + "<EmptyDataTemplate>"); string _FieldName = string.Empty; OleDbType _thisType = OleDbType.Empty; int i = 0; foreach (DataRow _row in pRows) { if (i == 0) { // do nothing } else { _FieldName = _row["COLUMN_NAME"].ToString(); _thisType = GetOleDBType(_row["DATA_TYPE"].ToString()); _ColsStream.Write(pIndnt + " " + _FieldName + ": "); if (_thisType.Equals(OleDbType.Boolean)) { _ColsStream.WriteLine("<asp:CheckBox ID=\"" + _FieldName + "CheckBox\" runat=\"server\" Text=\"Yes\" />"); } else { _ColsStream.WriteLine("<asp:TextBox ID=\"" + _FieldName + "TextBox\" runat=\"server\" Width=\"10em\" />"); } } //else i++; } // foreach _ColsStream.WriteLine(pIndnt + "</EmptyDataTemplate>"); }
protected void WriteTemplateFields(DataRow[] pRows, string pIndnt) { _ColsStream.WriteLine(pIndnt + "<asp:TemplateField ShowHeader=\"False\">"); _ColsStream.WriteLine(pIndnt + " <EditItemTemplate>"); _ColsStream.WriteLine(pIndnt + " <asp:Button ID=\"UpdateButton\" runat=\"server\" CausesValidation=\"True\" CommandName=\"Update\" Text=\"Update\" />"); _ColsStream.WriteLine(pIndnt + " <asp:Button ID=\"CancelButton\" runat=\"server\" CausesValidation=\"False\" CommandName=\"Cancel\" Text=\"Cancel\" />"); _ColsStream.WriteLine(pIndnt + " </EditItemTemplate>"); _ColsStream.WriteLine(pIndnt + " <ItemTemplate>"); _ColsStream.WriteLine(pIndnt + " <asp:Button ID=\"EditButton\" runat=\"server\" CausesValidation=\"False\" CommandName=\"Edit\" Text=\"Edit\" />"); _ColsStream.WriteLine(pIndnt + " <asp:Button ID=\"DeleteButton\" runat=\"server\" CausesValidation=\"False\" CommandName=\"Delete\" Text=\"Delete\" />"); _ColsStream.WriteLine(pIndnt + " </ItemTemplate>"); _ColsStream.WriteLine(pIndnt + " <FooterTemplate>"); _ColsStream.WriteLine(pIndnt + " <asp:Button ID=\"AddButton\" runat=\"server\" CausesValidation=\"False\" CommandName=\"Add\" Text=\"Add\" />"); _ColsStream.WriteLine(pIndnt + " </FooterTemplate>"); _ColsStream.WriteLine(pIndnt + "</asp:TemplateField>"); string _FieldName = string.Empty; OleDbType _thisType = OleDbType.Empty; int i = 0; foreach (DataRow _row in pRows) { if (i == 0) { // do nothing } else { _FieldName = _row["COLUMN_NAME"].ToString(); _thisType = GetOleDBType(_row["DATA_TYPE"].ToString()); if (_thisType.Equals(OleDbType.Boolean)) { WriteCheckBoxTemplate(_FieldName, pIndnt); } else { WriteTextBoxTemplate(_FieldName, pIndnt); } } //else i++; } // foreach // now add id field string _IdFieldName = pRows[0]["COLUMN_NAME"].ToString(); _ColsStream.WriteLine(pIndnt + "<asp:TemplateField ConvertEmptyStringToNull=\"False\" "); _ColsStream.WriteLine(pIndnt + " HeaderText=\"" + _IdFieldName + "\" SortExpression=\"" + _IdFieldName + "\">"); _ColsStream.WriteLine(pIndnt + " <EditItemTemplate>"); _ColsStream.WriteLine(pIndnt + " <asp:Literal ID=\"" + _IdFieldName + "Literal\" runat=\"server\" Text='<%# Bind(\"" + _IdFieldName + "\") %>' />"); _ColsStream.WriteLine(pIndnt + " </EditItemTemplate>"); _ColsStream.WriteLine(pIndnt + " <ItemTemplate>"); _ColsStream.WriteLine(pIndnt + " <asp:Literal ID=\"" + _IdFieldName + "Literal\" runat=\"server\" Text='<%# Bind(\"" + _IdFieldName + "\") %>' />"); _ColsStream.WriteLine(pIndnt + " </ItemTemplate>"); _ColsStream.WriteLine(pIndnt + " <FooterTemplate>"); _ColsStream.WriteLine(pIndnt + " <asp:Literal ID=\"" + _IdFieldName + "Literal\" runat=\"server\" Text='<%# Bind(\"" + _IdFieldName + "\") %>' />"); _ColsStream.WriteLine(pIndnt + " </FooterTemplate>"); _ColsStream.WriteLine(pIndnt + "</asp:TemplateField>"); }
protected void WriteRowLogic(DataRow[] pRows, string pFormName, string pIndnt) { OleDbType _thisType = OleDbType.Empty; int _origIndntLen = pIndnt.Length; string _FieldName = pRows[1]["COLUMN_NAME"].ToString(); _ColsStream.WriteLine(pIndnt + "TextBox _" + _FieldName + "TextBox = (TextBox)_row.FindControl(\"" + _FieldName + "TextBox\");"); _ColsStream.WriteLine(pIndnt + "if ((_" + _FieldName + "TextBox != null) && (!String.IsNullOrEmpty(_" + _FieldName + "TextBox.Text)))"); _ColsStream.WriteLine(pIndnt + "{"); pIndnt += " "; _ColsStream.WriteLine(pIndnt + "control." + pFormName + "Tbl _" + pFormName + " = new control." + pFormName + "Tbl();"); _FieldName = pRows[0]["COLUMN_NAME"].ToString(); _ColsStream.WriteLine(pIndnt + "Literal _" + _FieldName + "Literal = (Literal)_row.FindControl(\"" + _FieldName + "Literal\");"); _ColsStream.WriteLine(pIndnt + "_" + pFormName + "." + _FieldName + " = (_" + _FieldName + "Literal != null) ? Convert.ToInt32(_" + _FieldName + "Literal.Text) : 0;"); _ColsStream.WriteLine(pIndnt + "if (e.CommandName.Equals(\"Delete\"))"); _ColsStream.WriteLine(pIndnt + "{"); _ColsStream.WriteLine(pIndnt + " _" + pFormName + ".Delete(_" + pFormName + "." + _FieldName + ");"); _ColsStream.WriteLine(pIndnt + "}"); _ColsStream.WriteLine(pIndnt + "else"); _ColsStream.WriteLine(pIndnt + "{"); pIndnt += " "; for (int i = 2; i < pRows.Length; i++) { _FieldName = pRows[i]["COLUMN_NAME"].ToString(); _thisType = GetOleDBType(pRows[i]["DATA_TYPE"].ToString()); if (_thisType.Equals(OleDbType.Boolean)) { _ColsStream.WriteLine(pIndnt + "CheckBox _" + _FieldName + " = (CheckBox)_row.FindControl(\"" + _FieldName + "CheckBox\");"); } else { _ColsStream.WriteLine(pIndnt + "TextBox _" + _FieldName + "TextBox = (TextBox)_row.FindControl(\"" + _FieldName + "TextBox\");"); } i++; } int j = 0; foreach (DataRow _row in pRows) { _FieldName = _row["COLUMN_NAME"].ToString(); if (j == 0) { // done already } else { _thisType = GetOleDBType(_row["DATA_TYPE"].ToString()); if (_thisType.Equals(OleDbType.Boolean)) { _ColsStream.WriteLine(pIndnt + "_" + pFormName + "." + _FieldName + " = (_" + _FieldName + "CheckBox != null) ? _" + _FieldName + "CheckBox.Checked : false;"); } else { _ColsStream.WriteLine(pIndnt + "_" + pFormName + "." + _FieldName + " = (_" + _FieldName + "TextBox != null) ? _" + _FieldName + "TextBox.Text : string.Empty"); } } } _FieldName = pRows[0]["COLUMN_NAME"].ToString(); // id field set it to this since we reuse this _ColsStream.WriteLine(pIndnt + "if (e.CommandName.Equals(\"Add\") || e.CommandName.Equals(\"Insert\"))"); _ColsStream.WriteLine(pIndnt + "{"); _ColsStream.WriteLine(pIndnt + " _" + pFormName + ".Insert(_" + pFormName + ");"); _ColsStream.WriteLine(pIndnt + "}"); _ColsStream.WriteLine(pIndnt + "else if (e.CommandName.Equals(\"Update\"))"); _ColsStream.WriteLine(pIndnt + "{"); _ColsStream.WriteLine(pIndnt + " _" + pFormName + ".Update(_" + pFormName + ", _" + pFormName + "." + _FieldName + ");"); _ColsStream.WriteLine(pIndnt + "}"); _ColsStream.WriteLine(pIndnt.Remove(1, 2) + "}"); pIndnt = pIndnt.Remove(1, pIndnt.Length - _origIndntLen); // take indent back to the beginning _ColsStream.WriteLine(pIndnt + "}"); }