public frmGenerateReactModel() { InitializeComponent(); className = string.Empty; this.rdOrigin.Checked = true; _syntaxType = ModelSyntaxType.Original; }
private void rdCamelCase_Click(object sender, EventArgs e) { this._syntaxType = ModelSyntaxType.CamelCase; }
private void rdOrigin_Click(object sender, EventArgs e) { this._syntaxType = ModelSyntaxType.Original; }
public string CreateReactJsModel(List <Column> columns, string modelName, ModelSyntaxType synTaxType = ModelSyntaxType.Original) { string filepath = ThisApp.AppSetting.ReactJsModelFolder; m_strBuilder = new StringBuilder(); //m_templateContent = Utility.ReadFile(filepath); //if (string.IsNullOrWhiteSpace(m_templateContent)) // return string.Empty; string className = string.Empty; if (m_DbType == DatabaseType.SQL && string.IsNullOrEmpty(modelName)) { className = m_table.CustomName; } else { className = modelName; } m_strBuilder.Append($"export interface I{className}"); m_strBuilder.Append(Environment.NewLine); m_strBuilder.Append("{"); m_strBuilder.Append(Environment.NewLine); string name = string.Empty; string type = string.Empty; foreach (Column col in columns) { if (synTaxType == ModelSyntaxType.CamelCase) { col.Name = col.Name.ToCamelCase(); } if (Array.IndexOf(NumberDataType, col.Datatype.ToString().ToLower()) > -1) { if (col.IsArray) { name += $"\t {col.Name}: number[]," + Environment.NewLine; } else { name += $"\t {col.Name}: number," + Environment.NewLine; } } else if (Array.IndexOf(StringDataType, col.Datatype.ToString().ToLower()) > -1) { if (col.IsArray) { name += $"\t {col.Name}: string[]," + Environment.NewLine; } else { name += $"\t {col.Name}: string," + Environment.NewLine; } } else if (Array.IndexOf(BoolDataType, col.Datatype.ToString().ToLower()) > -1) { name += $"\t {col.Name}: boolean," + Environment.NewLine; } else if (Array.IndexOf(DateTimeType, col.Datatype.ToString().ToLower()) > -1) { name += $"\t {col.Name}: Date," + Environment.NewLine; } else { if (col.IsArray) { name += $"\t {col.Name}: {col.Datatype}[]," + Environment.NewLine; } else { name += $"\t {col.Name}: {col.Datatype}," + Environment.NewLine; } } } m_strBuilder.Append(name); m_strBuilder.Append(Environment.NewLine); m_strBuilder.Append("}"); m_strBuilder.Append(Environment.NewLine); m_strBuilder.Append(TheText.AppendNewHere); //m_templateContent = m_templateContent.Replace(TheText.AppendNewHere, m_strBuilder.ToString()); m_templateContent = m_strBuilder.ToString(); if (ThisApp.AppSetting.AutoCreateFile == true) { //if (File.Exists(filepath)) //{ // if (ThisApp.currentSession.OverWriteReactModel) // { // Utility.WriteToFile(filepath, m_templateContent); // } //} //else //{ Utility.WriteToFile($"{filepath}\\I{className}.tsx", m_templateContent); //} } return(m_templateContent); }