public bool BuildNull() { string template = ManageTemplate.GetTemplate("Null.ico"); template = template.Replace("***NameSpace***", Session.NamespaceDataLayer); if (ManageTemplate.WriteTemplate(Session.Folder, template, "Null", null)) { return(true); } else { return(false); } }
public bool BuildTemplate(DataTable dt, Provider provider) { string tableName = dt.Rows[0]["Table"].ToString().Trim(); KeyColumn key = new KeyColumn(); key.Name = dt.Rows[0]["Name"].ToString(); key.NetType = dt.Rows[0]["Type"].ToString(); key.Sequence = 1; key.Type = dt.Rows[0]["Type"].ToString(); key.Size = int.Parse(dt.Rows[0]["Length"].ToString()); Dictionary <string, KeyColumn> keys = new Dictionary <string, KeyColumn>(); keys.Add(key.Name, key); Session.Keys = keys; string keyType = "int"; string isAutomaticKey = "false"; string typeKey = string.Empty; if (Session.Keys.Count == 0) { return(false); } string privateField = string.Empty; if (Session.Framework == Framework.net20) { privateField = GetPrivateField(dt); } string publicField = GetPublicField(dt); string mapping = GetMapping(dt); string parameters = string.Empty; // GetParameters(dt, tableName); string parametersList = string.Empty; string parametersListInsert = string.Empty; string parametersListUpdate = string.Empty; string parametersListDelete = string.Empty; string parametersListClone = string.Empty; string declarationParametersKeys = string.Empty; string parameterKeys = string.Empty; string listParameterKeys = string.Empty; string isNullKeys = string.Empty; string parametersKeysWithOutType = string.Empty; string queryInsert = string.Empty; string queryUpdate = string.Empty; string queryDelete = string.Empty; string fieldBoolean = string.Empty; string queryByUpdVer = string.Empty; string structureField = string.Empty; string isSingleKey = "true"; if (Session.Keys.Count > 1) { isSingleKey = "false"; } string template = string.Empty; template = ManageTemplate.GetTemplate("CrudTemplateAutoTask.ico"); //parametersListInsert = GetParametersList(dt, tableName, false); //parametersListUpdate = GetParametersList(dt, tableName, false); //parametersListDelete = GetParametersList(dt, tableName, true); GetParametersListAll(dt, ref parametersListInsert, ref parametersListDelete, ref parametersListClone, ref parameters, provider); parametersListUpdate = parametersListInsert; SetAllKeys(ref declarationParametersKeys, ref listParameterKeys, ref parametersKeysWithOutType, ref isNullKeys, ref parameterKeys); structureField = GetStructure(dt); fieldBoolean = CustomBoolean.GetList(); //declarationParametersKeys = SetDeclarationKeys(); //parameterKeys = GetParametersDictionaryList(Session.Keys, tableName); //listParameterKeys = SetParametersKeys(); //isNullKeys = SetNullKeysCondtition(); template = template.Replace("#Version#", Session.Version); template = template.Replace("#Date#", System.DateTime.Now.ToString("dd/MM/yyyy")); template = template.Replace("#Owner#", Session.Owner); template = template.Replace("***NameSpace***", Session.NamespaceDataLayer); template = template.Replace("***ClassName***", tableName); template = template.Replace("***StructureField***", structureField); template = template.Replace("***PrivateField***", privateField); template = template.Replace("***PublicField***", publicField); template = template.Replace("***MappingDataReader***", mapping); template = template.Replace("***MappingDataTable***", mapping); template = template.Replace("***Parameters***", parameters); template = template.Replace("***KetType***", keyType); template = template.Replace("***isAutomaticKey***", isAutomaticKey); foreach (KeyValuePair <string, KeyColumn> kvp in Session.Keys) { template = template.Replace("***TableKey***", kvp.Key); if (!kvp.Value.NetType.Equals("String")) { template = template.Replace("***TableKeyType***", string.Concat(kvp.Value.NetType, ".Parse")); } else { template = template.Replace("***TableKeyType***", string.Empty); } break; } template = template.Replace("***DeclarationParameterKeys***", declarationParametersKeys); template = template.Replace("***ParameterKeys***", parameterKeys); template = template.Replace("***ListParameterKeys***", listParameterKeys); template = template.Replace("***ParametersListInsert***", parametersListInsert); template = template.Replace("***ParametersListUpdate***", parametersListUpdate); template = template.Replace("***ParametersListDelete***", parametersListDelete); template = template.Replace("***ParametersListClone***", parametersListClone); template = template.Replace("***Collection***", Session.GetCollectionFunction); //template = template.Replace("#GetCollectionSql#", GetViewSql(dt, tableName, true)); //template = template.Replace("#GetCollectionSqlWithOutOrder#", GetViewSql(dt, tableName, false)); template = template.Replace("#GetCollectionByKeys#", "GetCollectionByKeys"); template = template.Replace("***FieldBoolean***", fieldBoolean); template = template.Replace("***IsSingleKey***", isSingleKey); template = template.Replace("***TypeKey***", keyType); if (Session.SuperClass) { string minorField = string.Empty; string tableNameRelationship = string.Empty; DataTable dtRelationship = GetDatatableSqlBase.GetRelationship(tableName); foreach (DataRow drRelationship in dtRelationship.Rows) { if (!tableNameRelationship.Equals(drRelationship["REFDTBNAME"].ToString())) { tableNameRelationship = drRelationship["REFDTBNAME"].ToString(); DataTable dtMinor = GetDatatableSqlBase.GetSchema(drRelationship["REFDTBNAME"].ToString()); minorField = string.Concat(minorField, GetPublicFieldForSuperClass(dtMinor, tableNameRelationship)); } tableNameRelationship = drRelationship["REFDTBNAME"].ToString(); } template = template.Replace("***SuperClass***", minorField); template = template.Replace("***DeclareRelationship***", GetDeclareRelationship(tableName)); template = template.Replace("***DeclareIndex***", GetDeclareIndex(tableName)); } else { template = template.Replace("***SuperClass***", string.Empty); template = template.Replace("***DeclareRelationship***", string.Empty); template = template.Replace("***DeclareIndex***", string.Empty); } //GetSql(dt, tableName, ref queryInsert, ref queryUpdate, ref queryDelete); //template = template.Replace("#GetByCodeSql#", GetByCodeSql(dt, tableName)); //template = template.Replace("#GetByCodeSqlUpdVer#", GetByCodeSqlUpdVer(dt, tableName)); template = template.Replace("***SWITCHCUSTOMFIELDS***", GetSwitchCustomFields(dt)); template = template.Replace("***FIELDENUM***", GetFieldEnum(dt)); template = template.Replace("***InsertSql***", queryInsert); template = template.Replace("#UpdateSql#", queryUpdate); template = template.Replace("#DeleteSql#", queryDelete); template = template.Replace("***Insert***", string.Format(Session.InsertFunction, tableName)); template = template.Replace("#InsertKey#", "InsertKey"); template = template.Replace("***Update***", string.Format(Session.UpdateFunction, tableName)); template = template.Replace("***Delete***", string.Format(Session.DeleteFunction, tableName)); template = template.Replace("***Read***", string.Format(Session.ReadFunction, tableName)); template = template.Replace("***GetCollection***", string.Format(Session.GetCollectionFunction, tableName)); template = template.Replace("***GetByCode***", string.Format(Session.GetByCodeFunction, tableName)); template = template.Replace("***IsUnknown***", Session.IsUnknown); template = template.Replace("***IsUnknownCondtition***", isNullKeys); template = template.Replace("***CheckExist***", string.Empty); bool isValid = false; if (!(ManageTemplate.WriteTemplate(Session.Folder, template, string.Concat(tableName, ""), null))) { return(false); } //{ // #region Class Plus // //if (Session.CreateCustomClass) // //{ // // template = ManageTemplate.GetTemplate("CrudTemplatePlusSqlBase.ico"); // // template = template.Replace("#Version#", Session.Version); // // template = template.Replace("#Date#", System.DateTime.Now.ToString("dd/MM/yyyy")); // // template = template.Replace("***NameSpace***", Session.Namespace); // // template = template.Replace("***ClassName***", tableName); // // template = template.Replace("***Collection***", Session.GetCollectionFunction); // // template = template.Replace("***Insert***", string.Format(Session.InsertFunction, tableName)); // // template = template.Replace("#InsertKey#", "InsertKey"); // // template = template.Replace("***Update***", string.Format(Session.UpdateFunction, tableName)); // // template = template.Replace("***Delete***", string.Format(Session.DeleteFunction, tableName)); // // template = template.Replace("***Read***", string.Format(Session.ReadFunction, tableName)); // // template = template.Replace("***GetCollection***", string.Format(Session.GetCollectionFunction, tableName)); // // template = template.Replace("#GetCollectionByKeys#", "GetCollectionByKeys"); // // template = template.Replace("***GetByCode***", string.Format(Session.GetByCodeFunction, tableName)); // // template = template.Replace("***IsUnknown***", Session.IsUnknown); // // template = template.Replace("***DeclarationParameterKeys***", declarationParametersKeys); // // template = template.Replace("***DeclarationParameterKeysWithOutType***", parametersKeysWithOutType); // // if (!ManageTemplate.WriteTemplate(Session.Folder, template, tableName, null)) return false; // //} // //template = ManageTemplate.GetTemplate("Interface.ico"); // //template = template.Replace("#Version#", Session.Version); // //template = template.Replace("#Date#", System.DateTime.Now.ToString("dd/MM/yyyy")); // //template = template.Replace("***NameSpace***", Session.Namespace); // //template = template.Replace("***ClassName***", tableName); // //if (ManageTemplate.WriteTemplate(Session.Folder, template, string.Concat("I", tableName), null)) return true; // //else return false; // #endregion // return false; //} return(true); }
public bool BuildControlsPage(string nameSpace, ArrayList tables, string pathfile, SqlConnection connection) { bool result = false; foreach (DataTable dt in tables) { string getData = string.Empty; string setData = string.Empty; string templatePopulateList = string.Empty; string tableName = dt.Rows[0]["Table"].ToString().Trim(); if (getData.Equals(string.Empty)) { if (Session.Modality == Modality.Professional) { if (getData.Equals(string.Empty)) { getData = string.Concat("\t\titem = Manager", tableName, ".GetByKeyuni(Key);\n"); } } if (Session.Modality == Modality.Easy) { //if (getData.Equals(string.Empty)) getData = "\t\titem = item.GetByKeyuni(Key);\n"; } } string template = "<table>"; foreach (DataRow dr in dt.Rows) { if ((!dr["Name"].Equals(Session.TableKey) && (!dr["Name"].Equals("Keyuni")) && (!dr["Name"].Equals("Timespan")))) { string templateControl = string.Empty; string tableLink = string.Empty; #region GerValue string name = dr["Name"].ToString(); string type = dr["Type"].ToString(); string dbType = dr["DbType"].ToString(); int length = (int)dr["Length"]; bool nullable = (bool)dr["Nullable"]; bool isSearch = false; int searchPosition = 0; bool isDetail = false; int detailPosition = 0; string descriptionName = string.Empty; GetDatatableSqlServer.GetPlusInformation(tableName, name, ref descriptionName, ref isSearch, ref searchPosition, ref isDetail, ref detailPosition); if (descriptionName.Equals(string.Empty)) { descriptionName = name; } #endregion switch (type) { case "decimal": case "int": if (type.Equals("int")) { tableLink = GetInfoFieldSqlServer.IsForeignKeySimple(tableName, name); } if (!tableLink.Equals(string.Empty)) { templateControl = GetLabel(templateControl, name, descriptionName); templateControl = string.Concat(templateControl, ManageTemplate.GetTemplate("WebTemplate//dropdownlist.ico")); templateControl = templateControl.Replace("***Name***", name); getData = string.Concat(getData, WriteGetDataControl(name, type, WebControl.DropDownList)); setData = string.Concat(setData, WriteSetDataControl(name, type, WebControl.DropDownList, nullable)); string nameTable = name.Replace("Code", string.Empty); string populateList = ManageTemplate.GetTemplate("WebTemplate//populateList.ico"); populateList = populateList.Replace("***Name***", nameTable); templatePopulateList = string.Concat(templatePopulateList, populateList); break; } else { templateControl = GetLabel(templateControl, name, descriptionName); templateControl = string.Concat(templateControl, ManageTemplate.GetTemplate("WebTemplate//textbox.ico")); templateControl = templateControl.Replace("***Name***", name); templateControl = templateControl.Replace("#Length#", length.ToString()); templateControl = templateControl.Replace("#SkinId#", GetSkinByLength(length)); getData = string.Concat(getData, WriteGetDataControl(name, type, WebControl.TextBox)); setData = string.Concat(setData, WriteSetDataControl(name, type, WebControl.TextBox, nullable)); } break; case "string": templateControl = GetLabel(templateControl, name, descriptionName); templateControl = string.Concat(templateControl, ManageTemplate.GetTemplate("WebTemplate//textbox.ico")); templateControl = templateControl.Replace("***Name***", name); templateControl = templateControl.Replace("#Length#", length.ToString()); templateControl = templateControl.Replace("#SkinId#", GetSkinByLength(length)); getData = string.Concat(getData, WriteGetDataControl(name, type, WebControl.TextBox)); setData = string.Concat(setData, WriteSetDataControl(name, type, WebControl.TextBox, nullable)); break; case "System.DateTime": templateControl = GetLabel(templateControl, name, descriptionName); templateControl = string.Concat(templateControl, ManageTemplate.GetTemplate("WebTemplate//calendar.ico")); templateControl = templateControl.Replace("***Name***", name); templateControl = templateControl.Replace("#SkinId#", GetSkinByLength(length)); getData = string.Concat(getData, WriteGetDataControl(name, type, WebControl.Calendar)); setData = string.Concat(setData, WriteSetDataControl(name, type, WebControl.Calendar, nullable)); break; } if ((!nullable)) { string templateRequiredFieldValidator = string.Empty; templateRequiredFieldValidator = string.Concat(ManageTemplate.GetTemplate("WebTemplate//requiredFieldValidator.ico")); templateRequiredFieldValidator = templateRequiredFieldValidator.Replace("***Name***", name); templateControl = string.Concat(templateControl, " ", templateRequiredFieldValidator); } if (!templateControl.Equals(string.Empty)) { templateControl = CloseRow(templateControl); } template = string.Concat(template, templateControl); } } template = string.Concat(template, "</table>"); if (ManageTemplate.WriteTemplate(string.Concat(pathfile, "WebControls//"), template, tableName, ".aspx")) { result = true; } else { result = false; } #region GerData string templateGetData = string.Concat(ManageTemplate.GetTemplate("WebTemplate//getData.ico")); templateGetData = templateGetData.Replace("***Body***", getData); string templateSetData = string.Concat(ManageTemplate.GetTemplate("WebTemplate//setData.ico")); templateSetData = templateSetData.Replace("***Body***", setData); string finallyTemplate = string.Concat(templateGetData, "\n\n", templateSetData); bool pageEasy = true; if (pageEasy) { string templateHtml = string.Concat(ManageTemplate.GetTemplate("WebForm//pageListDetail.aspx")); templateHtml = templateHtml.Replace("***Name***", tableName); templateHtml = templateHtml.Replace("#WebControls#", template); if (ManageTemplate.WriteTemplate(string.Concat(pathfile, "WebControls//Page//"), templateHtml, tableName, "ListDetail.aspx")) { result = true; } string templateCode = string.Concat(ManageTemplate.GetTemplate("WebForm//pageListDetail.aspx.ico")); templateCode = templateCode.Replace("***Name***", tableName); templateCode = templateCode.Replace("#GetData#", getData); templateCode = templateCode.Replace("#SetData#", setData); templateCode = templateCode.Replace("#PopulateList#", templatePopulateList); if (ManageTemplate.WriteTemplate(string.Concat(pathfile, "WebControls//Page//"), templateCode, tableName, "ListDetail.aspx.ico")) { result = true; } } else { string templateHtml = string.Concat(ManageTemplate.GetTemplate("WebForm//pageDetail.aspx")); templateHtml = templateHtml.Replace("***Name***", tableName); templateHtml = templateHtml.Replace("#WebControls#", template); if (ManageTemplate.WriteTemplate(string.Concat(pathfile, "WebControls//Page//"), templateHtml, tableName, "Detail.aspx")) { result = true; } string templateCode = string.Concat(ManageTemplate.GetTemplate("WebForm//pageDetail.aspx.ico")); templateCode = templateCode.Replace("***Name***", tableName); templateCode = templateCode.Replace("#GetData#", getData); templateCode = templateCode.Replace("#SetData#", setData); templateCode = templateCode.Replace("#PopulateList#", templatePopulateList); if (ManageTemplate.WriteTemplate(string.Concat(pathfile, "WebControls//Page//"), templateCode, tableName, "Detail.aspx.ico")) { result = true; } } #endregion } return(true); }