You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
265 lines
11 KiB
265 lines
11 KiB
using GummingCommon;
|
|
using GummingControl;
|
|
using GummingEntity;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SQLite;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace GummingBusiness
|
|
{
|
|
public class HardFormulaCPDA
|
|
{
|
|
public static int ReadTotalCount(PagerEntity se)
|
|
{
|
|
string dbPath = FilesDirectory.DatabasePath;
|
|
if (!File.Exists(dbPath))
|
|
{
|
|
throw new Exception("database missing!");
|
|
}
|
|
try
|
|
{
|
|
SQLiteConnection conn = SQLiteHelper.CreateConnection();
|
|
if (conn.State != System.Data.ConnectionState.Open)
|
|
{
|
|
conn.Open();
|
|
SQLiteCommand cmd = new SQLiteCommand();
|
|
cmd.Connection = conn;
|
|
cmd.CommandText = "SELECT count(*) FROM Hard_Formula_CP WHERE 1=1 " + se.Conditions;
|
|
SQLiteDataReader sr = cmd.ExecuteReader();
|
|
sr.Read();
|
|
int count = sr.GetInt32(0);
|
|
sr.Close();
|
|
conn.Close();
|
|
return count;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception("打开数据库:" + dbPath + "的连接失败:" + ex.Message);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public static HardFormulaCPEntity Load(string recId)
|
|
{
|
|
string dbPath = FilesDirectory.DatabasePath;
|
|
if (!File.Exists(dbPath))
|
|
{
|
|
throw new Exception("database missing!");
|
|
}
|
|
try
|
|
{
|
|
SQLiteConnection conn = SQLiteHelper.CreateConnection();
|
|
if (conn.State != System.Data.ConnectionState.Open)
|
|
{
|
|
conn.Open();
|
|
DataTable dt = SQLiteHelper.ExecuteDataTable(conn, "SELECT * FROM Hard_Formula_CP WHERE RecId ='" + recId + "' limit 1");
|
|
List<HardFormulaCPEntity> rows = SQLiteHelper.DataTableToIList<HardFormulaCPEntity>(dt) as List<HardFormulaCPEntity>;
|
|
conn.Close();
|
|
if (rows.Count > 0)
|
|
{
|
|
return rows[0];
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception("打开数据库:" + dbPath + "的连接失败:" + ex.Message);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static RecordEntity Load(PagerEntity se)
|
|
{
|
|
string dbPath = FilesDirectory.DatabasePath;
|
|
if (!File.Exists(dbPath))
|
|
{
|
|
throw new Exception("database missing!");
|
|
}
|
|
try
|
|
{
|
|
int count = ReadTotalCount(se);
|
|
//se.OrderBy, se.SortOrder, se.PageIndex, se.Rows
|
|
SQLiteConnection conn = SQLiteHelper.CreateConnection();
|
|
if (conn.State != System.Data.ConnectionState.Open)
|
|
{
|
|
conn.Open();
|
|
DataTable dt = SQLiteHelper.ExecuteDataTable(conn, "SELECT * FROM Hard_Formula_CP WHERE 1=1 " + se.Conditions + " order by StepIndex asc limit " +
|
|
Convert.ToString(se.Rows) + " offset " + Convert.ToString((se.PageIndex - 1) * se.Rows));
|
|
List<HardFormulaCPEntity> rows = SQLiteHelper.DataTableToIList<HardFormulaCPEntity>(dt) as List<HardFormulaCPEntity>;
|
|
conn.Close();
|
|
RecordEntity result = new RecordEntity();
|
|
result.total = (int)Math.Ceiling(count * 1.0 / se.Rows);
|
|
result.page = se.PageIndex;
|
|
result.records = count;
|
|
result.rows = rows;
|
|
return result;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception("打开数据库:" + dbPath + "的连接失败:" + ex.Message);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static void Save(HardFormulaCPEntity segment)
|
|
{
|
|
string dbPath = FilesDirectory.DatabasePath;
|
|
if (!File.Exists(dbPath))
|
|
{
|
|
throw new Exception("database missing!");
|
|
}
|
|
try
|
|
{
|
|
SQLiteConnection conn = SQLiteHelper.CreateConnection();
|
|
if (conn.State != System.Data.ConnectionState.Open)
|
|
{
|
|
conn.Open();
|
|
using (SQLiteTransaction tran = conn.BeginTransaction())
|
|
{
|
|
Save(conn, segment);
|
|
tran.Commit();
|
|
}
|
|
conn.Close();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception("打开数据库:" + dbPath + "的连接失败:" + ex.Message);
|
|
}
|
|
}
|
|
|
|
public static void Save(SQLiteConnection conn, HardFormulaCPEntity segment)
|
|
{
|
|
SQLiteCommand cmd = new SQLiteCommand();
|
|
cmd.Connection = conn;
|
|
cmd.CommandText = "INSERT INTO Hard_Formula_CP (RecId,StepIndex,StepTime,Empty,Temperature,StepCode,StepName,FormulaId,OrderBy,CreateBy,CreateTime,ModifyBy,ModifyTime,IsActive) values(@RecId,@StepIndex,@StepTime,@Empty,@Temperature,@StepCode,@StepName,@FormulaId,@OrderBy,@CreateBy,@CreateTime,@ModifyBy,@ModifyTime,@IsActive)";
|
|
cmd.Parameters.AddWithValue("@RecId", Guid.NewGuid().ToString());
|
|
cmd.Parameters.AddWithValue("@StepIndex", segment.StepIndex);
|
|
cmd.Parameters.AddWithValue("@StepTime", segment.StepTime);
|
|
cmd.Parameters.AddWithValue("@Empty", segment.Empty);
|
|
cmd.Parameters.AddWithValue("@Temperature", segment.Temperature);
|
|
cmd.Parameters.AddWithValue("@StepCode", segment.StepCode);
|
|
cmd.Parameters.AddWithValue("@StepName", segment.StepName);
|
|
cmd.Parameters.AddWithValue("@FormulaId", segment.FormulaId);
|
|
cmd.Parameters.AddWithValue("@OrderBy", segment.OrderBy);
|
|
cmd.Parameters.AddWithValue("@CreateBy", Global.CurrentUserCode);
|
|
cmd.Parameters.AddWithValue("@CreateTime", DateTime.Now);
|
|
cmd.Parameters.AddWithValue("@ModifyBy", Global.CurrentUserCode);
|
|
cmd.Parameters.AddWithValue("@ModifyTime", DateTime.Now);
|
|
cmd.Parameters.AddWithValue("@IsActive", 1);
|
|
cmd.ExecuteNonQuery();
|
|
}
|
|
|
|
public static void Update(HardFormulaCPEntity segment)
|
|
{
|
|
string dbPath = FilesDirectory.DatabasePath;
|
|
if (!File.Exists(dbPath))
|
|
{
|
|
throw new Exception("database missing!");
|
|
}
|
|
try
|
|
{
|
|
SQLiteConnection conn = SQLiteHelper.CreateConnection();
|
|
if (conn.State != System.Data.ConnectionState.Open)
|
|
{
|
|
conn.Open();
|
|
using (SQLiteTransaction tran = conn.BeginTransaction())
|
|
{
|
|
Update(conn, segment);
|
|
tran.Commit();
|
|
}
|
|
conn.Close();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception("打开数据库:" + dbPath + "的连接失败:" + ex.Message);
|
|
}
|
|
}
|
|
|
|
public static void Update(SQLiteConnection conn, HardFormulaCPEntity segment)
|
|
{
|
|
SQLiteCommand cmd = new SQLiteCommand();
|
|
cmd.Connection = conn;
|
|
cmd.CommandText = "UPDATE Hard_Formula_CP SET StepIndex = @StepIndex, StepTime = @StepTime, Empty = @Empty, Temperature = @Temperature, StepCode = @StepCode, StepName = @StepName, FormulaId = @FormulaId, OrderBy = @OrderBy, ModifyBy = @ModifyBy, ModifyTime = @ModifyTime, IsActive = @IsActive WHERE RecId = @RecId";
|
|
cmd.Parameters.AddWithValue("@RecId", segment.RecId);
|
|
cmd.Parameters.AddWithValue("@StepIndex", segment.StepIndex);
|
|
cmd.Parameters.AddWithValue("@StepTime", segment.StepTime);
|
|
cmd.Parameters.AddWithValue("@Empty", segment.Empty);
|
|
cmd.Parameters.AddWithValue("@Temperature", segment.Temperature);
|
|
cmd.Parameters.AddWithValue("@StepCode", segment.StepCode);
|
|
cmd.Parameters.AddWithValue("@StepName", segment.StepName);
|
|
cmd.Parameters.AddWithValue("@FormulaId", segment.FormulaId);
|
|
cmd.Parameters.AddWithValue("@OrderBy", segment.OrderBy);
|
|
cmd.Parameters.AddWithValue("@ModifyBy", Global.CurrentUserCode);
|
|
cmd.Parameters.AddWithValue("@ModifyTime", DateTime.Now);
|
|
cmd.Parameters.AddWithValue("@IsActive", 1);
|
|
cmd.ExecuteNonQuery();
|
|
}
|
|
|
|
public static void Delete(string formulaId)
|
|
{
|
|
string dbPath = FilesDirectory.DatabasePath;
|
|
if (!File.Exists(dbPath))
|
|
{
|
|
throw new Exception("database missing!");
|
|
}
|
|
try
|
|
{
|
|
SQLiteConnection conn = SQLiteHelper.CreateConnection();
|
|
if (conn.State != System.Data.ConnectionState.Open)
|
|
{
|
|
conn.Open();
|
|
Delete(conn, formulaId);
|
|
conn.Close();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception("打开数据库:" + dbPath + "的连接失败:" + ex.Message);
|
|
}
|
|
}
|
|
|
|
public static void Delete(SQLiteConnection conn, string formulaId)
|
|
{
|
|
SQLiteCommand cmd = new SQLiteCommand();
|
|
cmd.Connection = conn;
|
|
cmd.CommandText = "delete from Hard_Formula_CP where FormulaId ='" + formulaId + "'";
|
|
cmd.ExecuteNonQuery();
|
|
}
|
|
|
|
public static void Clear()
|
|
{
|
|
string dbPath = FilesDirectory.DatabasePath;
|
|
if (!File.Exists(dbPath))
|
|
{
|
|
throw new Exception("database missing!");
|
|
}
|
|
try
|
|
{
|
|
SQLiteConnection conn = SQLiteHelper.CreateConnection();
|
|
if (conn.State != System.Data.ConnectionState.Open)
|
|
{
|
|
conn.Open();
|
|
SQLiteCommand cmd = new SQLiteCommand();
|
|
cmd.Connection = conn;
|
|
cmd.CommandText = "delete from Hard_Formula_CP";
|
|
cmd.ExecuteNonQuery();
|
|
conn.Close();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception("打开数据库:" + dbPath + "的连接失败:" + ex.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|