VSoft/Source/VSoft_Dll/FrmAddColumn.cs
2020-11-28 15:44:33 +08:00

79 lines
2.6 KiB
C#

using ryCommonDb;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VSoft.Prams;
namespace VSoft
{
public partial class FrmAddColumn : Form
{
public string SQLConnStr { get; set; } = Itrycn_Db.SQLConnStr;
public FrmAddColumn()
{
InitializeComponent();
}
public string tableName = "Columns";
public int IsAdd { get; set; } = 1;
public int SelectId { get; set; } = -1;
public void GetInfo(int id)
{
SelectId = id;
Text = "修改栏目";
DataProvider mydb = new DataProvider();
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(SQLConnStr) == 1)
{
DataSet ds = db.ReadData(tableName, id.ToString());
if (mydb.HaveData(ds))
{
DataRow reader = ds.Tables[0].Rows[0];
#region
TxtName.Text = reader["Name"].ToString();
TxtDes.Text = reader["Des"].ToString();
#endregion
}
}
db.Free();
}
private void BtnCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
private void BtnOK_Click(object sender, EventArgs e)
{
if (TxtName.Text.Length == 0)
{
MessageBox.Show("名称不能为空。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
RyQuickSQL mySQL = new RyQuickSQL(tableName);
mySQL.AddField("Name", TxtName.Text);
mySQL.AddField("Des", TxtDes.Text);
mySQL.AddField("editTime", DateTime.Now);
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(SQLConnStr) == 1)
{
if (IsAdd >= 1)
{
mySQL.AddField("sortindex", Itrycn_Db.GetColumnCount(db, 0) + 1);
mySQL.AddField("addTime", DateTime.Now);
db.ExecuteNonQuery(mySQL.GetInsertSQL(), mySQL);
}
else
{
db.ExecuteNonQuery(mySQL.GetUpdateSQL() + " where id=" + SelectId, mySQL);
}
}
db.Free();
DialogResult = DialogResult.OK;
}
}
}