using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Drawing;
|
using System.Text;
|
using System.IO;
|
using System.Windows.Forms;
|
using HotelPms.Share.Windows.Util;
|
using HotelPms.Share.Util;
|
using HotelPms.SourceFactory.Util;
|
using HotelPms.Share.Data;
|
using System.Diagnostics;
|
|
namespace HotelPms.SourceFactory
|
{
|
public partial class BeanCreator : FormBase
|
{
|
private MsSqlNet msSqlNet;
|
|
public BeanCreator()
|
{
|
InitializeComponent();
|
}
|
|
private void BeanCreator_Load(object sender, EventArgs e)
|
{
|
GeneralSub.InitDataGridView(dataGridView1, true);
|
GeneralSub.InitDataGridView(dataGridView2, true);
|
msSqlNet = EnvironmentSetting.Default.CreateDBAccess();
|
dataGridView1.DataSource = msSqlNet.GetTableList();
|
dataGridView2.ReadOnly = false;
|
dataGridView1.ColumnHeadersDefaultCellStyle.SelectionBackColor = SystemColors.Control;
|
dataGridView1.EnableHeadersVisualStyles = false;
|
dataGridView2.ColumnHeadersDefaultCellStyle.SelectionBackColor = SystemColors.Control;
|
dataGridView2.EnableHeadersVisualStyles = false;
|
|
|
foreach (DataGridViewRow row in dataGridView1.Rows)
|
{
|
System.Diagnostics.Debug.WriteLine(row.Cells[0].Value.ToString() + ",");
|
}
|
}
|
|
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
|
{
|
if (dataGridView1.CurrentRow == null) { return; }
|
dataGridView2.DataSource = msSqlNet.GetFieldList(dataGridView1.CurrentRow.Cells[0].Value.ToString());
|
foreach (DataGridViewRow row in dataGridView2.Rows) { row.Cells["colFieldSel"].Value = true; }
|
|
txtTsBeanClassName.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString().Substring(2);
|
txtTsBeanInterfaceName.Text = $"I{dataGridView1.CurrentRow.Cells[0].Value.ToString().Substring(2)}";
|
txtTsAccessClassName.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString().Substring(2) + "Api";
|
|
string baseName = dataGridView1.CurrentRow.Cells[0].Value.ToString().Substring(2);
|
lblBlazorViewModel.Text = $"{baseName}.cs";
|
chkBlazorViewModel.Checked = false;
|
|
lblProtos.Text = $"{baseName.ToLower()}.proto";
|
chkProtos.Checked = false;
|
|
chkStartup.Checked = false;
|
|
lblServices.Text = $"{baseName}Service.cs";
|
chkServices.Checked = false;
|
|
lblClientAccess.Text = $"{baseName}Access.cs";
|
chkClientAccess.Checked = false;
|
lblClientDirectAccess.Text = $"{baseName}Access.cs";
|
chkClientDirectAccess.Checked = false;
|
lblClientMaster.Text = $"{baseName}.cs";
|
chkClientMaster.Checked = false;
|
lblClientTable.Text = $"{baseName}Table.cs";
|
chkClientTable.Checked = false;
|
lblClientUse.Text = $"{baseName}.cs";
|
chkClientUse.Checked = false;
|
}
|
|
public object GetField(string name)
|
{
|
if (name.ToLower() == "".ToLower()) { return name; }
|
else if (name.ToLower() == "".ToLower()) { return name; }
|
else { return string.Empty; }
|
}
|
|
public Dictionary<string, int> GetPrimaryKey()
|
{
|
Dictionary<string, int> dict = new Dictionary<string, int>();
|
dict.Add("", 0);
|
dict.Add("ddd", 1);
|
return dict;
|
}
|
|
private void button1_Click(object sender, EventArgs e)
|
{
|
|
}
|
|
private string ToProto3Type(string type)
|
{
|
if (type.ToLower() == "int") { return "int32"; }
|
else if (type.ToLower() == "bytestring") { return "bytes"; }
|
else if (type.ToLower() == "long") { return "int64"; }
|
else if (type.ToLower() == "datetime") { return "google.protobuf.Timestamp"; }
|
else { return type.ToLower(); }
|
}
|
|
|
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
{
|
|
}
|
|
private void button2_Click(object sender, EventArgs e)
|
{
|
// /// ****************************** Description *******************************
|
// /// VXe¼Ì
|
// /// @PMS FrameWork 1.0
|
// /// Tv
|
// /// @SPAÅ
|
// /// ð
|
// /// @}X^f[^Ìîb
|
// /// ****************************** Declarations ******************************
|
// export default interface IMasterListRowBase
|
// {
|
// ID: number;
|
// Name: string;
|
//}
|
|
|
//±ñÈ´¶
|
// import MasterBase from './MasterBase';
|
|
// export default class Login extends MasterBase
|
// {
|
// public GroupID: number = 0;
|
// public Kana: string = '';
|
// public Password: string = '';
|
// public PWCreateDate: Date = new Date();
|
// public LanguageType: number = 0;
|
//}
|
|
|
DirectoryInfo dir = Directory.CreateDirectory(Application.StartupPath + Path.DirectorySeparatorChar + @"Work");
|
|
//NX
|
string[] items = new string[17];
|
items[0] = txtTsBeanClassName.Text;
|
items[1] = CConvert.ToDateString(DateTime.Now);
|
items[2] = txtTsBeanClassName.Text;
|
items[3] = string.Empty;
|
|
//C^[tF[X
|
string[] accessItems = new string[11];
|
accessItems[0] = txtTsBeanInterfaceName.Text;
|
accessItems[1] = CConvert.ToDateString(DateTime.Now);
|
accessItems[2] = txtTsBeanInterfaceName.Text;
|
accessItems[3] = string.Empty;
|
|
int index = 0;
|
foreach (DataGridViewRow row in dataGridView2.Rows)
|
{
|
if (!CConvert.ToBool(row.Cells["colFieldSel"].Value)) { continue; }
|
|
string type = TypeScriptFactory.ToTsType(row.Cells["Type"].Value.ToString());
|
string name = row.Cells["Field"].Value.ToString();
|
if(name.ToUpper() == "ID" || name.ToUpper() == "NAME") { continue; }
|
|
if(index > 0)
|
{
|
items[3] += Environment.NewLine;
|
accessItems[3] += Environment.NewLine;
|
}
|
|
items[3] += $" public {name}: {type} = {TypeScriptFactory.GetDefValue(row.Cells["Type"].Value.ToString())};";
|
accessItems[3] += $" {name}: {type};";
|
index++;
|
}
|
|
string fileInfo = EnvironmentSetting.TsBeanFileMode;
|
for (int i = 0; i < items.Length; i++)
|
{
|
fileInfo = fileInfo.Replace("@" + i.ToString() + "@", items[i]);
|
}
|
if (!Directory.Exists(dir.FullName + Path.DirectorySeparatorChar + @"Ts\")) { Directory.CreateDirectory(dir.FullName + Path.DirectorySeparatorChar + @"Ts\"); }
|
File.WriteAllText(dir.FullName + Path.DirectorySeparatorChar + @"Ts\" + txtTsBeanClassName.Text + ".ts", fileInfo, Encoding.UTF8);
|
|
fileInfo = EnvironmentSetting.TsInterfaceFileMode;
|
for (int i = 0; i < accessItems.Length; i++)
|
{
|
fileInfo = fileInfo.Replace("@" + i.ToString() + "@", accessItems[i]);
|
}
|
if (!Directory.Exists(dir.FullName + Path.DirectorySeparatorChar + @"Ts\")) { Directory.CreateDirectory(dir.FullName + Path.DirectorySeparatorChar + @"Ts\"); }
|
File.WriteAllText(dir.FullName + Path.DirectorySeparatorChar + @"Ts\" + txtTsBeanInterfaceName.Text + ".ts", fileInfo, Encoding.UTF8);
|
|
MessageBox.Show("OK");
|
|
}
|
|
private void BeanCreator_FormClosed(object sender, FormClosedEventArgs e)
|
{
|
if (msSqlNet != null) { msSqlNet.Dispose(); }
|
}
|
|
private void btnCreate_Click(object sender, EventArgs e)
|
{
|
string tableName = dataGridView1.CurrentRow.Cells[0].Value.ToString();
|
string baseName = tableName.Substring(2);
|
|
string root = Path.Combine(Application.StartupPath, @"Work");
|
if (!Directory.Exists(root)) { Directory.CreateDirectory(root); }
|
string[] accessItems = new string[6];
|
accessItems[0] = baseName;
|
accessItems[1] = tableName;
|
accessItems[2] = ""; //2.int id,int id....
|
accessItems[3] = ""; //3.ID = {id}
|
accessItems[4] = "HotelPms.DataAccessGrpc.Client";
|
accessItems[5] = chkUseInfo.Checked ? "UseInfo" : "Master";
|
|
string[] beanItems = new string[15];
|
beanItems[0] = baseName; //NX
|
beanItems[1] = ""; //1.vC}[L[ê
|
beanItems[2] = ""; //2.CompareTo
|
beanItems[3] = ""; //3.CopyTo
|
beanItems[4] = ""; //4.Clear
|
beanItems[5] = ""; //5.ConvertDataRowA
|
beanItems[6] = ""; //6.ToDataRow
|
beanItems[7] = ""; //7.AddSql
|
beanItems[8] = ""; //8.UpdateSql
|
beanItems[9] = ""; //9.ToText
|
beanItems[10] = ""; //10.GetField
|
beanItems[11] = "internal";
|
beanItems[12] = chkUseInfo.Checked ? "HotelPms.Data.UseInfo" : "HotelPms.Data.Master";
|
beanItems[13] = ""; //13.SetField
|
beanItems[14] = ""; //14.ConvertReader
|
|
string[] viewModelItems = new string[2];
|
viewModelItems[0] = baseName;
|
viewModelItems[1] = "";
|
|
|
string[] tableItems = new string[2];
|
tableItems[0] = "internal";
|
tableItems[1] = baseName;
|
|
string[] proto3Items = new string[5];
|
proto3Items[0] = baseName;
|
proto3Items[1] = "";
|
proto3Items[2] = "";
|
proto3Items[3] = chkUseInfo.Checked ? "UseInfo" : "Master";
|
proto3Items[4] = "";
|
|
string[] serviceItems = new string[3];
|
serviceItems[0] = baseName;
|
serviceItems[1] = tableName;
|
serviceItems[2] = chkUseInfo.Checked ? "UseInfo" : "Master";
|
|
|
string fieldList = string.Empty;
|
string indexList = string.Empty;
|
int addIndex = 0;
|
string ret = string.Empty;
|
|
string ret1 = string.Empty;
|
string fieldList1 = string.Empty;
|
int fieldCount = 0;
|
string whereList = string.Empty;
|
int whereCount = 0;
|
int uptIndex = 0;
|
|
int index = 0;
|
int pkCount = 0;
|
foreach (DataGridViewRow row in dataGridView2.Rows)
|
{
|
if (!CConvert.ToBool(row.Cells["colFieldSel"].Value)) { continue; }
|
|
string sqlType = row.Cells["Type"].Value.ToString();
|
string type = CommonFunc.ConvertToCsType(sqlType);
|
string name = row.Cells["Field"].Value.ToString();
|
string varName = $"p{name}";
|
string caption = row.Cells["Caption"].Value.ToString();
|
int maxLen = CConvert.ToInt(row.Cells["MaxLen"].Value);
|
|
if (CConvert.ToInt(row.Cells["PKFlg"].Value.ToString()) == 1)
|
{
|
beanItems[1] += $" PrimaryKey.TryAdd(\"{name}\", 0); " + Environment.NewLine;
|
|
//õL[
|
accessItems[2] += (accessItems[2].Length == 0 ? string.Empty : ",") + type + " " + varName;
|
accessItems[3] += (accessItems[3].Length == 0 ? string.Empty : " AND ") + name + " = " + CommonFunc.ToSqlValue(type, varName);
|
pkCount++;
|
}
|
|
beanItems[2] += (index == 0 ? "" : " || ");
|
beanItems[2] += $"{name}.CompareTo(item.{name}) != 0";
|
beanItems[2] += Environment.NewLine;
|
|
beanItems[3] += string.Format(" item.{0} = {0};" + Environment.NewLine, name);
|
beanItems[4] += string.Format(" {0} = {1};" + Environment.NewLine, name, CommonFunc.GetDefValue(sqlType));
|
beanItems[5] += CommonFunc.GetConvertDataRowCode(type, name);
|
beanItems[14] += CommonFunc.GetConvertReaderCode(sqlType, name);
|
beanItems[6] += $" row[\"{name}\"] = {CommonFunc.ToDataRow(type, name)};" + Environment.NewLine;
|
beanItems[9] += (" text.AppendFormat(\"" + name + "={0};\", " + name + ");" + Environment.NewLine);
|
beanItems[10] += (Environment.NewLine + $" {(index == 0 ? string.Empty : "else ")}if (name == \"{name}\")" + " { return " + name + "; }");
|
beanItems[13] += (Environment.NewLine + $" {(index == 0 ? string.Empty : "else ")}if (name == \"{name}\")" + " { " + CommonFunc.GetConvertValue(type, name) + "return true; }");
|
|
if (sqlType.ToLower() == "datetime" && proto3Items[2].Length == 0) { proto3Items[2] = "import \"google/protobuf/timestamp.proto\";"; }
|
if ((sqlType.ToLower() == "decimal" || sqlType.ToLower() == "date") && proto3Items[4].Length == 0) { proto3Items[4] = "import \"customTypes.proto\";"; }
|
proto3Items[1] += $" {CommonFunc.ToProto3Type(type)} {name} = {index + 1};{Environment.NewLine}";
|
|
viewModelItems[1] += (Environment.NewLine + " Add(new ValidField() { Name = \"" + name + "\", Caption = \"" + caption + "\", MaxLenth = " + maxLen.ToString() + ", InputChar = " + CommonFunc.ToInputChar(sqlType) + " });");
|
|
#region ÇÁsql
|
|
if (name.Equals("UpdateDate"))
|
{
|
fieldList += ",UpdateDate";
|
indexList += ",GETDATE()";
|
}
|
else
|
{
|
if (addIndex > 0) { fieldList += ","; indexList += ","; ret += ","; }
|
fieldList += name;
|
indexList += CommonFunc.ToSqlValue(type, name);
|
addIndex++;
|
}
|
|
|
#endregion
|
|
#region XVsql
|
|
if (name.Equals("UpdateDate"))
|
{
|
fieldList1 += ",UpdateDate = GETDATE()";
|
}
|
else
|
{
|
if (uptIndex > 0) { ret1 += ","; }
|
|
//uÚ={index}vÌ®
|
string item = name + " = ";
|
item += CommonFunc.ToSqlValue(type, name);
|
|
if (CConvert.ToInt(row.Cells["PKFlg"].Value.ToString()) == 1)
|
{
|
if (whereCount > 0) { whereList += " AND "; }
|
whereList += item;
|
whereCount++;
|
}
|
else
|
{
|
if (fieldCount > 0) { fieldList1 += ","; }
|
fieldList1 += item;
|
fieldCount++;
|
}
|
uptIndex++;
|
}
|
|
#endregion
|
|
index++;
|
}
|
|
beanItems[7] = " " + "return $@\"" + $"INSERT INTO {tableName}({fieldList}) VALUES({indexList});" + "\";";
|
beanItems[8] = " " + "return $@\"" + $"UPDATE {tableName} SET {fieldList1} WHERE {whereList};" + "\";";
|
|
#region Workàêt@Cì¬
|
|
//HotelPms.Client.Blazor>>ViewModel
|
CreateCsFile(root + @"\HotelPms.Client.Blazor\ViewModel", EnvironmentSetting.ViewModel, viewModelItems, $"{baseName}.cs");
|
|
//Protos
|
CreateCsFile(root + @"\Protos", EnvironmentSetting.Proto3Master, proto3Items, $"{baseName.ToLower()}.proto");
|
|
//HotelPms.GrpcService>>Service
|
CreateCsFile(root + @"\HotelPms.GrpcService\Services", EnvironmentSetting.BeanFileMode_ProtoEx_Service, serviceItems, $"{baseName}Service.cs");
|
|
//HotelPms.DataAccessGrpc.Client
|
accessItems[4] = "HotelPms.DataAccessGrpc.Client";
|
CreateCsFile(root + @"\HotelPms.DataAccessGrpc.Client", EnvironmentSetting.DataAccessFileMode, accessItems, $"{baseName}Access.cs");
|
|
beanItems[11] = "public";
|
tableItems[0] = "public";
|
if (chkUseInfo.Checked)
|
{
|
//ProtosExpan>>UseInfo>>
|
CreateCsFile(root + @"\ProtosExpan\UseInfo", EnvironmentSetting.BeanFileMode, beanItems, $"{baseName}.cs");
|
}
|
else
|
{
|
//ProtosExpan>>Master>>
|
CreateCsFile(root + @"\ProtosExpan\Master", EnvironmentSetting.BeanFileMode, beanItems, $"{baseName}.cs");
|
CreateCsFile(root + @"\ProtosExpan\Master", EnvironmentSetting.BeanFileMode_ProtoEx_Table, tableItems, $"{baseName}Table.cs");
|
}
|
|
#endregion
|
|
if (!chkCopy.Checked)
|
{
|
CConvert.StartFile(root);
|
return;
|
}
|
|
#region Copy To Project
|
|
string projDir = @"\HotelPms.Client.Blazor\";
|
using (FileEdit.Core core = new FileEdit.Core())
|
{
|
FileEdit.Item item;
|
FileEdit.EditData edit;
|
|
//HotelPms.Client.Blazor>>ViewModel
|
File.Copy(root + @"\HotelPms.Client.Blazor\ViewModel\" + $"{baseName}.cs", txtSlnDir.Text + projDir + @"ViewModel\" + $"{baseName}.cs", true);
|
chkBlazorViewModel.Checked = true;
|
|
File.Copy(root + @"\Protos\" + $"{baseName.ToLower()}.proto", txtSlnDir.Text + @"\Protos\" + $"{baseName.ToLower()}.proto", true);
|
chkProtos.Checked = true;
|
|
//HotelPms.GrpcService>>Service
|
projDir = @"\HotelPms.GrpcService\";
|
edit = new FileEdit.EditData { FilePath = txtSlnDir.Text + $@"{projDir}Program.cs", Encoding = Encoding.UTF8 };
|
string line = $"app.MapGrpcService<{baseName}Service>().RequireCors(\"AllowAll\");";
|
if (!edit.Exists(line))
|
{
|
item = new FileEdit.Item { Key1 = "app.MapControllers()", Key2 = "app.MapGrpcService" };
|
item.Data.Add(line);
|
edit.Data.Add(item);
|
}
|
core.Execute(edit);
|
chkStartup.Checked = true;
|
|
|
File.Copy(root + @"\HotelPms.GrpcService\Services\" + $"{baseName}Service.cs", txtSlnDir.Text + projDir + @"Services\" + $"{baseName}Service.cs", true);
|
chkServices.Checked = true;
|
|
//HotelPms.DataAccessGrpc.Client
|
projDir = @"\HotelPms.DataAccessGrpc.Client\";
|
|
File.Copy(root + @"\HotelPms.DataAccessGrpc.Client\" + $"{baseName}Access.cs", txtSlnDir.Text + projDir + $"{baseName}Access.cs", true);
|
chkClientAccess.Checked = true;
|
|
edit = new FileEdit.EditData { FilePath = txtSlnDir.Text + $@"\HotelPms.Data.Client\HotelPms.Data.Client.csproj", Encoding = Encoding.UTF8 };
|
var edit2 = new FileEdit.EditData { FilePath = txtSlnDir.Text + $@"\HotelPms.Data.Server\HotelPms.Data.Server.csproj", Encoding = Encoding.UTF8 };
|
|
if (chkUseInfo.Checked)
|
{
|
//HotelPms.Data.Client>>UseInfo>>
|
File.Copy(root + @"\ProtosExpan\UseInfo\" + $"{baseName}.cs", txtSlnDir.Text + @"\ProtosExpan\UseInfo\" + $"{baseName}.cs", true);
|
chkClientUse.Checked = true;
|
|
//NCAg¤
|
line = $" <Compile Include=\"..\\ProtosExpan\\UseInfo\\{baseName}.cs\" Link=\"ProtosExpan\\UseInfo\\{baseName}.cs\" />";
|
item = new FileEdit.Item { Key1 = "<ItemGroup>", Key2 = "<Compile Include=\"..\\ProtosExpan" };
|
item.Data.Add(line);
|
if (!edit.Exists(line)) { edit.Data.Add(item); }
|
|
//T[o[¤
|
if (!edit2.Exists(line)) { edit2.Data.Add(item); }
|
}
|
else
|
{
|
//HotelPms.Data.Client>>Master>>
|
File.Copy(root + @"\ProtosExpan\Master\" + $"{baseName}.cs", txtSlnDir.Text + @"\ProtosExpan\Master\" + $"{baseName}.cs", true);
|
chkClientMaster.Checked = true;
|
|
//NCAg¤
|
line = $" <Compile Include=\"..\\ProtosExpan\\Master\\{baseName}.cs\" Link=\"ProtosExpan\\Master\\{baseName}.cs\" />";
|
item = new FileEdit.Item { Key1 = "<ItemGroup>", Key2 = "<Compile Include=\"..\\ProtosExpan" };
|
item.Data.Add(line);
|
if (!edit.Exists(line)) { edit.Data.Add(item); }
|
|
//T[o[¤
|
if (!edit2.Exists(line)) { edit2.Data.Add(item); }
|
|
|
#region ?????Table.cs
|
|
File.Copy(root + @"\ProtosExpan\Master\" + $"{baseName}Table.cs", txtSlnDir.Text + @"\ProtosExpan\Master\" + $"{baseName}Table.cs", true);
|
chkClientTable.Checked = true;
|
|
//NCAg¤ÌÝ
|
line = $" <Compile Include=\"..\\ProtosExpan\\Master\\{baseName}Table.cs\" Link=\"ProtosExpan\\Master\\{baseName}Table.cs\" />";
|
item = new FileEdit.Item { Key1 = "<ItemGroup>", Key2 = "<Compile Include=\"..\\ProtosExpan" };
|
item.Data.Add(line);
|
if(!edit.Exists(line)) { edit.Data.Add(item); }
|
|
#endregion
|
}
|
|
//@HotelPms.Data.Client.csproj
|
line = $" <Protobuf Include=\"..\\Protos\\{baseName.ToLower()}.proto\" GrpcServices=\"Client\" Link=\"Protos\\{baseName.ToLower()}.proto\" />";
|
item = new FileEdit.Item { Key1 = "<ItemGroup>", Key2 = "<Protobuf" };
|
item.Data.Add(line);
|
if (!edit.Exists(line)) { edit.Data.Add(item); }
|
core.Execute(edit);
|
chkClient.Checked = true;
|
|
//HotelPms.Data.Server
|
line = $" <Protobuf Include=\"..\\Protos\\{baseName.ToLower()}.proto\" GrpcServices=\"Server\" Link=\"Protos\\{baseName.ToLower()}.proto\" />";
|
projDir = @"\HotelPms.Data.Server\";
|
item = new FileEdit.Item { Key1 = "<ItemGroup>", Key2 = "<Protobuf" };
|
item.Data.Add(line);
|
if (!edit2.Exists(line)) { edit2.Data.Add(item); }
|
core.Execute(edit2);
|
chkServer.Checked = true;
|
}
|
|
#endregion
|
|
MessageBox.Show("OK");
|
}
|
|
private void CreateCsFile(string root, string template, string[] items, string fileName)
|
{
|
if (!Directory.Exists(root)) { Directory.CreateDirectory(root); }
|
string fileInfo = template;
|
for (int i = 0; i < items.Length; i++)
|
{
|
fileInfo = fileInfo.Replace($"@{i}@", items[i]);
|
}
|
File.WriteAllText(root + Path.DirectorySeparatorChar + fileName, fileInfo, Encoding.UTF8);
|
}
|
}
|
}
|