// private string CreateClearControlsMethod() { // StringBuilder method = new StringBuilder(); method.Append("\n\tprivate void " + global.ClearControlsMethod); method.Append("\n\t{"); string datatype; foreach (SQLDMO.Column column in Fields) { if (ID == null || column.Name != ID.Name || !Globals.CheckIsAddedBySql(ID)) { if (allParameters != null && !allParameters.Contains(column.Name)) { continue; } datatype = Globals.GetAliasDataType(column.Datatype); if (datatype == "bool") { method.Append("\n\t\tcb" + Globals.GetProgramatlyName(column.Name) + ".Checked=false;"); } else if (Globals.GetSqlDataType(column.Datatype) == SqlDbType.NText) { method.Append("\n\t\tfck" + Globals.GetProgramatlyName(column.Name) + ".Value=\"\";"); } else if (datatype != "byte[]" && datatype != "Object" && datatype != "Guid") { TableConstraint cnstr = SqlProvider.obj.GetParentColumn(column.Name); if (cnstr == null) { //dateTime if (Globals.GetSqlDataType(column.Datatype) == SqlDbType.DateTime) { method.Append("\n\t\ttxt" + Globals.GetProgramatlyName(column.Name) + ".Value=\"\";"); } //datetime else { method.Append("\n\t\ttxt" + Globals.GetProgramatlyName(column.Name) + ".Text=\"\";"); } } else { method.Append("\n\t\tddl" + Globals.GetProgramatlyName(cnstr.ParentTable) + ".SelectedIndex=-1;"); method.Append("\n\t\tddl" + Globals.GetProgramatlyName(cnstr.ParentTable) + ".DataBind();"); } } } } method.Append("\n\t}"); return(method.ToString()); }
// public void GenerateSupLoadMethods() { string datatype; foreach (SQLDMO.Column column in Fields) { if (ID == null || column.Name != ID.Name || !Globals.CheckIsAddedBySql(ID)) { datatype = Globals.GetAliasDataType(column.Datatype); if (datatype != "bool" && datatype != "byte[]" && datatype != "Object" && datatype != "Guid") { TableConstraint cnstr = SqlProvider.obj.GetParentColumn(column.Name); if (cnstr != null) { CreateSupLoadMethod(cnstr); } } } } }
//---------------------------------- #region Old and Unused code /// <summary> /// Generates code for an UPDATE or INSERT Stored Procedure /// </summary> /// <param name="sptypeGenerate">The type of SP to generate, INSERT or UPDATE</param> /// <param name="Fields">A ColumnCollection collection</param> /// <returns>The SP code</returns> private void Generate(StoredProcedureTypes sptypeGenerate, SqlProvider dmoMain) { try { StringBuilder sGeneratedCode = new StringBuilder(); StringBuilder sParamDeclaration = new StringBuilder(); StringBuilder sBody = new StringBuilder(); StringBuilder sINSERTValues = new StringBuilder(); string finnal = ""; // Setup SP code, begining is the same no matter the type sGeneratedCode.AppendFormat("CREATE PROCEDURE {0}.[{1}_{2}]", new string[] { SqlProvider.obj.DatabaseOwner, Globals.GetProgramatlyName(Table), sptypeGenerate.ToString() }); sGeneratedCode.Append(Environment.NewLine); // Setup body code, different for UPDATE and INSERT switch (sptypeGenerate) { case StoredProcedureTypes.Create: sBody.AppendFormat("INSERT INTO [{0}] (", Table); sBody.Append(Environment.NewLine); sINSERTValues.Append("VALUES ("); sINSERTValues.Append(Environment.NewLine); break; case StoredProcedureTypes.Update: sBody.AppendFormat("UPDATE [{0}]", Table); sBody.Append(Environment.NewLine); sBody.Append("SET"); sBody.Append(Environment.NewLine); break; case StoredProcedureTypes.GetAll: sBody.AppendFormat("Select * From [{0}] ", Table); sBody.Append(Environment.NewLine); break; case StoredProcedureTypes.GetOneByID: sBody.AppendFormat("Select * From [{0}] ", Table); sBody.Append(Environment.NewLine); break; case StoredProcedureTypes.Delete: sBody.AppendFormat("Delete * From [{0}] ", Table); sBody.Append(Environment.NewLine); break; } #region Add Parametars if (sptypeGenerate == StoredProcedureTypes.GetAll) { sGeneratedCode.Append("AS"); sGeneratedCode.Append(Environment.NewLine); sGeneratedCode.Append(sBody.Remove(sBody.Length - 3, 3)); } else if (sptypeGenerate != StoredProcedureTypes.GetOneByID || sptypeGenerate != StoredProcedureTypes.Delete) { //The finanal of procedure if (ID != null) { sParamDeclaration.AppendFormat(" @{0} {1}", new string[] { Globals.GetProgramatlyName(ID.Name), ID.Datatype }); finnal = "Where [" + ID.Name + "] =@" + Globals.GetProgramatlyName(ID.Name); } } else { foreach (Column colCurrent in Fields) { if (ID != null && colCurrent.Name == ID.Name) { sParamDeclaration.AppendFormat(" @{0} {1}", new string[] { Globals.GetProgramatlyName(colCurrent.Name), colCurrent.Datatype }); } if (ID != null && colCurrent.Name == ID.Name && Globals.CheckIsAddedBySql(colCurrent) && sptypeGenerate == StoredProcedureTypes.Create) { sParamDeclaration.AppendFormat(" out"); } // Only binary, char, nchar, nvarchar, varbinary and varchar may have their length declared if ( colCurrent.Datatype == "binary" || colCurrent.Datatype == "char" || colCurrent.Datatype == "nchar" || colCurrent.Datatype == "nvarchar" || colCurrent.Datatype == "varbinary" || colCurrent.Datatype == "varchar") { sParamDeclaration.AppendFormat("({0})", colCurrent.Length); } sParamDeclaration.Append(","); sParamDeclaration.Append(Environment.NewLine); // Body construction, different for INSERT and UPDATE switch (sptypeGenerate) { case StoredProcedureTypes.Create: //not Added BySQL if (ID == null && colCurrent.Name != ID.Name || !Globals.CheckIsAddedBySql(colCurrent)) { sINSERTValues.AppendFormat(" @{0},", Globals.GetProgramatlyName(colCurrent.Name)); sINSERTValues.Append(Environment.NewLine); sBody.AppendFormat(" [{0}],", colCurrent.Name); sBody.Append(Environment.NewLine); } break; case StoredProcedureTypes.Update: if (ID == null && colCurrent.Name != ID.Name) { sBody.AppendFormat(" [{0}] = @{1},", new string[] { colCurrent.Name, Globals.GetProgramatlyName(colCurrent.Name) }); sBody.Append(Environment.NewLine); } break; case StoredProcedureTypes.GetOneByID: // sBody.AppendFormat("Where {0} = @{0},", new string[]{colCurrent.Name, }); sBody.Append(Environment.NewLine); break; } } //The finanal of procedure if (ID != null) { if (sptypeGenerate == StoredProcedureTypes.Create && Globals.CheckIsAddedBySql(ID)) { finnal = "Set @" + Globals.GetProgramatlyName(ID.Name) + " = @@Identity"; } else if (sptypeGenerate == StoredProcedureTypes.Update) { finnal = "Where [" + ID.Name + "] =@" + Globals.GetProgramatlyName(ID.Name); } } #endregion // Now stitch the body parts together into the SP whole sGeneratedCode.Append(sParamDeclaration.Remove(sParamDeclaration.Length - 3, 3)); sGeneratedCode.Append(Environment.NewLine); sGeneratedCode.Append("AS"); sGeneratedCode.Append(Environment.NewLine); sGeneratedCode.Append(sBody.Remove(sBody.Length - 3, 3)); if (sptypeGenerate == StoredProcedureTypes.Create) { sGeneratedCode.Append(")"); sGeneratedCode.Append(Environment.NewLine); sGeneratedCode.Append(sINSERTValues.Remove(sINSERTValues.Length - 3, 3)); sGeneratedCode.Append(")"); } } sGeneratedCode.Append(Environment.NewLine); sGeneratedCode.Append(finnal); WriteStoredProcedure(sGeneratedCode.ToString()); } catch (Exception ex) { MessageBox.Show("My Generated Code Exception:" + ex.Message); } }
//--------------------------------- /// <summary> /// Generates code for INSERT Stored Procedure /// </summary> /// <param name="sptypeGenerate">The type of SP to generate, INSERT</param> /// <param name="Fields">A ColumnCollection collection</param> /// <returns>The SP code</returns> private void GenerateInsertProcedure() { try { StringBuilder sGeneratedCode = new StringBuilder(); StringBuilder sParamDeclaration = new StringBuilder(); StringBuilder sBody = new StringBuilder(); StringBuilder sINSERTValues = new StringBuilder(); string finnal = ""; // Setup SP code, begining is the same no matter the type sGeneratedCode.AppendFormat("CREATE PROCEDURE {0}.[{1}_{2}]", new string[] { SqlProvider.obj.DatabaseOwner, Globals.GetProgramatlyName(Table), StoredProcedureTypes.Create.ToString() }); sGeneratedCode.Append(Environment.NewLine); // Setup body code, different for UPDATE and INSERT sBody.AppendFormat("INSERT INTO [{0}] (", Table); sBody.Append(Environment.NewLine); sINSERTValues.Append("VALUES ("); sINSERTValues.Append(Environment.NewLine); #region Add Parametars foreach (Column colCurrent in Fields) { sParamDeclaration.AppendFormat(" @{0} {1}", new string[] { Globals.GetProgramatlyName(colCurrent.Name), colCurrent.Datatype }); if (ID != null && colCurrent.Name == ID.Name && Globals.CheckIsAddedBySql(colCurrent)) { sParamDeclaration.AppendFormat(" out"); } // Only binary, char, nchar, nvarchar, varbinary and varchar may have their length declared if ( colCurrent.Datatype == "binary" || colCurrent.Datatype == "char" || colCurrent.Datatype == "nchar" || colCurrent.Datatype == "nvarchar" || colCurrent.Datatype == "varbinary" || colCurrent.Datatype == "varchar") { sParamDeclaration.AppendFormat("({0})", colCurrent.Length); } sParamDeclaration.Append(","); sParamDeclaration.Append(Environment.NewLine); // Body construction //not Added BySQL if (ID == null || colCurrent.Name != ID.Name || !Globals.CheckIsAddedBySql(colCurrent)) { sINSERTValues.AppendFormat(" @{0},", Globals.GetProgramatlyName(colCurrent.Name)); sINSERTValues.Append(Environment.NewLine); sBody.AppendFormat(" [{0}],", colCurrent.Name); sBody.Append(Environment.NewLine); } } if (ID != null && Globals.CheckIsAddedBySql(ID)) { finnal = "Set @" + Globals.GetProgramatlyName(ID.Name) + " = @@Identity"; } #endregion // Now stitch the body parts together into the SP whole sGeneratedCode.Append(sParamDeclaration.Remove(sParamDeclaration.Length - 3, 3)); sGeneratedCode.Append(Environment.NewLine); sGeneratedCode.Append("AS"); sGeneratedCode.Append(Environment.NewLine); sGeneratedCode.Append(sBody.Remove(sBody.Length - 3, 3)); sGeneratedCode.Append(")"); sGeneratedCode.Append(Environment.NewLine); sGeneratedCode.Append(sINSERTValues.Remove(sINSERTValues.Length - 3, 3)); sGeneratedCode.Append(")"); // sGeneratedCode.Append(Environment.NewLine); sGeneratedCode.Append(finnal); WriteStoredProcedure(sGeneratedCode.ToString()); } catch (Exception ex) { MessageBox.Show("My Generated Code Exception:" + ex.Message); } }
// private string Create_CreateButtonHandler() { StringBuilder _CreateButtonHandler = new StringBuilder(); _CreateButtonHandler.Append("\n\tprotected void btnCreate_Click(object sender, System.EventArgs e)"); _CreateButtonHandler.Append("\n\t{"); _CreateButtonHandler.Append("\n\t\tif (!Page.IsValid)"); _CreateButtonHandler.Append("\n\t\t{"); _CreateButtonHandler.Append("\n\t\t\treturn;"); _CreateButtonHandler.Append("\n\t\t}"); _CreateButtonHandler.Append("\n\t\t" + global.TableEntityClass + " " + global.EntityClassObject + " = new " + global.TableEntityClass + "();"); string datatype; foreach (SQLDMO.Column column in Fields) { if (allParameters != null && !allParameters.Contains(column.Name)) { continue; } if (ID == null || column.Name != ID.Name || !Globals.CheckIsAddedBySql(ID)) { datatype = Globals.GetAliasDataType(column.Datatype); TableConstraint cnstr = SqlProvider.obj.GetParentColumn(column.Name); if (datatype == "string") { if (Globals.GetSqlDataType(column.Datatype) == SqlDbType.NText) { _CreateButtonHandler.Append("\n\t\t" + global.EntityClassObject + "." + Globals.GetProgramatlyName(column.Name) + " = fck" + Globals.GetProgramatlyName(column.Name) + ".Value;"); } else { if (cnstr == null) { _CreateButtonHandler.Append("\n\t\t" + global.EntityClassObject + "." + Globals.GetProgramatlyName(column.Name) + " = txt" + Globals.GetProgramatlyName(column.Name) + ".Text;"); } else { _CreateButtonHandler.Append("\n\t\t" + global.EntityClassObject + "." + Globals.GetProgramatlyName(column.Name) + " = ddl" + Globals.GetProgramatlyName(cnstr.ParentTable) + ".SelectedValue;"); } } } //DateTime else if (Globals.GetSqlDataType(column.Datatype) == SqlDbType.DateTime) { _CreateButtonHandler.Append("\n\t\t" + global.EntityClassObject + "." + Globals.GetProgramatlyName(column.Name) + " = Convert.To" + Globals.GetDataType(column.Datatype) + "(txt" + Globals.GetProgramatlyName(column.Name) + ".Value);"); } //DateTime else if (datatype == "bool") { _CreateButtonHandler.Append("\n\t\t" + global.EntityClassObject + "." + Globals.GetProgramatlyName(column.Name) + " = cb" + Globals.GetProgramatlyName(column.Name) + ".Checked;"); } else if (datatype == "Guid") { _CreateButtonHandler.Append("\n\t\t" + global.EntityClassObject + "." + Globals.GetProgramatlyName(column.Name) + " = Guid.NewGuid();"); } else if (datatype != "byte[]" && datatype != "Object") { if (cnstr == null) { _CreateButtonHandler.Append("\n\t\t" + global.EntityClassObject + "." + Globals.GetProgramatlyName(column.Name) + " = Convert.To" + Globals.GetDataType(column.Datatype) + "(txt" + Globals.GetProgramatlyName(column.Name) + ".Text);"); } else { _CreateButtonHandler.Append("\n\t\t" + global.EntityClassObject + "." + Globals.GetProgramatlyName(column.Name) + " = Convert.To" + Globals.GetDataType(column.Datatype) + "(ddl" + Globals.GetProgramatlyName(cnstr.ParentTable) + ".SelectedValue);"); } } } } _CreateButtonHandler.Append("\n\t\tbool result = " + global.TableFactoryClass + "." + MethodType.Create.ToString() + "(" + global.EntityClassObject + ");"); _CreateButtonHandler.Append("\n\t\tif(result)"); _CreateButtonHandler.Append("\n\t\t{"); _CreateButtonHandler.Append("\n\t\t\tlblResult.ForeColor=Color.Blue ;"); _CreateButtonHandler.Append("\n\t\t\tlblResult.Text=\"Êã ÇáÅÖÇÝÉ ÈäÌÇÍ\";"); _CreateButtonHandler.Append("\n\t\t\t" + global.ClearControlsMethod + ";"); _CreateButtonHandler.Append("\n\t\t}"); _CreateButtonHandler.Append("\n\t\telse"); _CreateButtonHandler.Append("\n\t\t{"); _CreateButtonHandler.Append("\n\t\t\tlblResult.ForeColor=Color.Red ;"); _CreateButtonHandler.Append("\n\t\t\tlblResult.Text=\"ÝÔáÊ ÚãáíÉ ÇáÅÖÇÝÉ\";"); _CreateButtonHandler.Append("\n\t\t}"); _CreateButtonHandler.Append("\n\t}"); return(_CreateButtonHandler.ToString()); }
// private string GenerateControls() { StringBuilder controls = new StringBuilder(); controls.Append("\n\t\t\t\t<tr>"); controls.Append("\n\t\t\t\t\t<td class=\"Result\" align=\"center\" colspan=\"2\">"); controls.Append("\n\t\t\t\t\t\t<asp:Label id=\"lblResult\" runat=\"server\"></asp:Label>"); controls.Append("\n\t\t\t\t\t</td>"); controls.Append("\n\t\t\t\t</tr>"); string datatype; foreach (Column column in Fields) { if (allParameters != null && !allParameters.Contains(column.Name)) { continue; } if (ID == null || column.Name != ID.Name || !Globals.CheckIsAddedBySql(ID)) { datatype = Globals.GetAliasDataType(column.Datatype); if (datatype == "bool") { controls.Append("\n\t\t\t\t<tr>"); controls.Append("\n\t\t\t\t\t<td class=\"Title\">" + column.Name + "</td>"); controls.Append("\n\t\t\t\t\t<td class=\"Control\">"); controls.Append("\n\t\t\t\t\t\t<asp:CheckBox id=\"cb" + Globals.GetProgramatlyName(column.Name) + "\" runat=\"server\" ValidationGroup=\"" + ClassName + "\" ></asp:CheckBox>"); controls.Append("\n\t\t\t\t\t</td>"); controls.Append("\n\t\t\t\t</tr>"); } else if (Globals.GetSqlDataType(column.Datatype) == SqlDbType.NText) { controls.Append("\n\t\t\t\t<tr>"); controls.Append("\n\t\t\t\t\t<td class=\"Title\">" + column.Name + "</td>"); controls.Append("\n\t\t\t\t\t<td class=\"Control\">"); //FREETEXTBOX controls.Append("\n\t\t\t\t\t\t<FTB:FREETEXTBOX id=\"ftb" + Globals.GetProgramatlyName(column.Name) + "\" runat=\"server\" TextDirection=\"RightToLeft\" "); controls.Append("\n\t\t\t\t\t\tToolbarLayout=\"Bold,Italic,Underline,Strikethrough,Superscript,Subscript;"); controls.Append("\n\t\t\t\t\t\tJustifyLeft,JustifyRight,JustifyCenter,JustifyFull;"); controls.Append("\n\t\t\t\t\t\tCut,Copy,Paste,Delete,Undo,Redo,Print,Save,ieSpellCheck|"); controls.Append("\n\t\t\t\t\t\tParagraphMenu,FontFacesMenu,FontSizesMenu,FontForeColorsMenu,FontBackColorsMenu,FontForeColorPicker,FontBackColorPicker|StyleMenu,SymbolsMenu,InsertHtmlMenu|InsertRule,InsertDate,InsertTime|WordClean|"); controls.Append("\n\t\t\t\t\t\tCreateLink,Unlink;RemoveFormat,BulletedList,NumberedList,Indent,Outdent;InsertTable,EditTable,InsertTableRowBefore,InsertTableRowAfter,DeleteTableRow,InsertTableColumnBefore,InsertTableColumnAfter,DeleteTableColumn|\""); controls.Append("\n\t\t\t\t\t\tSupportFolder=\"/phyEditorImages/FreeTextBox/\" ButtonSet=\"NotSet\" Width=\"450px\" ButtonWidth=\"21\"></FTB:FREETEXTBOX>"); // //----------- controls.Append("\n\t\t\t\t\t</td>"); controls.Append("\n\t\t\t\t</tr>"); // IshasFreeTextBoxControl = true; } else if (datatype != "byte[]" && datatype != "Object" && datatype != "Guid") { TableConstraint cnstr = SqlProvider.obj.GetParentColumn(column.Name); controls.Append("\n\t\t\t\t<tr>"); controls.Append("\n\t\t\t\t\t<td class=\"Title\">" + column.Name + "</td>"); controls.Append("\n\t\t\t\t\t<td class=\"Control\">"); if (cnstr == null) { controls.Append("\n\t\t\t\t\t\t<asp:TextBox id=\"txt" + Globals.GetProgramatlyName(column.Name) + "\" runat=\"server\" CssClass=\"Control\" MaxLength=\"" + Globals.GetTextBoxMaxLength(column) + "\" ValidationGroup=\"" + ClassName + "\" ></asp:TextBox>"); if (!column.AllowNulls) { controls.Append("\n\t\t\t\t\t\t<asp:RequiredFieldValidator id=\"rfv" + Globals.GetProgramatlyName(column.Name) + "\" runat=\"server\" ErrorMessage=\"*\" ControlToValidate=\"txt" + Globals.GetProgramatlyName(column.Name) + "\" ValidationGroup=\"" + ClassName + "\">ÃÏÎá åÐÇ ÇáÈíÇä</asp:RequiredFieldValidator>"); } } else { controls.Append("\n\t\t\t\t\t\t<asp:DropDownList id=\"ddl" + Globals.GetProgramatlyName(cnstr.ParentTable) + "\" runat=\"server\" CssClass=\"Control\" ValidationGroup=\"" + ClassName + "\" ></asp:DropDownList>"); } controls.Append("\n\t\t\t\t\t</td>"); controls.Append("\n\t\t\t\t</tr>"); } } } controls.Append("\n\t\t\t\t<tr>"); controls.Append("\n\t\t\t\t\t<td class=\"Result\" align=\"center\" colspan=\"2\">"); controls.Append("\n\t\t\t\t\t\t<asp:Button id=\"btnCreate\" runat=\"server\" Width=\"100px\" Text=\"ÅÖÇÝÉ\" CssClass=\"Submit\" OnClick=\"btnCreate_Click\" ValidationGroup=\"" + ClassName + "\"></asp:Button>"); controls.Append("\n\t\t\t\t\t</td>"); controls.Append("\n\t\t\t\t</tr>"); return(controls.ToString()); }