数据读写逻辑修改

This commit is contained in:
sc committed 2025-08-25 00:23:34 +08:00
commit fb1b024944
6 files changed
+38 -53

No files matched your search

+3 -25
View File
@@ -49,7 +49,6 @@ namespace DyeingComputer.UserClass
{
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
DataTable data_t = WorkOrderStep_.Clone();
int a = WorkOrderStep_.Rows.Count;
if (a < 1)
{
@@ -65,11 +64,7 @@ namespace DyeingComputer.UserClass
}
for (int i = 0; i < a; i++)
{
data_t.Clear();//清空
DataRow dr = data_t.NewRow();
dr.ItemArray = WorkOrderStep_.Rows[i].ItemArray;
data_t.Rows.InsertAt(dr, 0);
SQLiteHelpers.InsertData("WorkorderSteps", SQLiteHelpers.DataTableToDictionary(data_t));//行插入
SQLiteHelpers.InsertData("WorkorderSteps", SQLiteHelpers.ToDictionary(WorkOrderStep_.Rows[i]));//行插入
}
SQLiteHelpers.Close(); //关闭连接
return true;
@@ -86,22 +81,10 @@ namespace DyeingComputer.UserClass
MainWindowViewModel.ProgramName = SQLiteHelpers.ExecuteScalar("select ProgramName from Workorder where ProgramID = '" + workName + "'", null).ToString();
SQLiteHelpers.Delete("RUN", null, null); //删除run信息
DataTable data_t = new DataTable();
data_t = MainWindowViewModel.dt_TP.Clone();
data_t.Columns.Add("DYELOT", typeof(string)); //添加列
int a = MainWindowViewModel.dt_TP.Rows.Count;
for (int i = 0; i < a; i++)
{
data_t.Clear();//清空
DataRow dt = MainWindowViewModel.dt_TP.Rows[i];//行转
DataRow dr = data_t.NewRow();
dr.ItemArray = dt.ItemArray;
dr.BeginEdit(); //添加订单号
dr["DYELOT"] = MainWindowViewModel.WorkNumder;
dr.EndEdit();
data_t.Rows.InsertAt(dr, 0); //行转换
r = SQLiteHelpers.InsertData("RUN", SQLiteHelpers.DataTableToDictionary(data_t));//行插入
SQLiteHelpers.InsertData("RUN", SQLiteHelpers.ToDictionary(MainWindowViewModel.dt_TP.Rows[i]));//行插入
}
//数据插入
MainWindowViewModel.WorkNumder = SQLiteHelpers.ExecuteDataSet("select WorkOrder from Workorder where ProgramID = '" + workName + "'", null);;
@@ -141,7 +124,6 @@ namespace DyeingComputer.UserClass
}
DyelotTable.Rows.Add(newRow);
}
DataTable data_t = DyelotTable.Clone();
int a = DyelotTable.Rows.Count;
if (a < 1) return false;
string Dyelot = DyelotTable.Rows[0][0].ToString();
@@ -155,11 +137,7 @@ namespace DyeingComputer.UserClass
}
for (int i = 0; i < a; i++)
{
data_t.Clear();//清空
DataRow dr = data_t.NewRow();
dr.ItemArray = DyelotTable.Rows[i].ItemArray;
data_t.Rows.InsertAt(dr, 0);
SQLiteHelpers.InsertData("Dyelot", SQLiteHelpers.DataTableToDictionary(data_t));//行插入
SQLiteHelpers.InsertData("Dyelot", SQLiteHelpers.ToDictionary(DyelotTable.Rows[i]));//行插入
}
SQLiteHelpers.Close(); //关闭连接
return true;
+17
View File
@@ -680,6 +680,23 @@ namespace DyeingComputer.UserClass
return result;
}
/// <summary>
/// 将DataRow转换为Dictionary&lt;string, object&gt;
/// </summary>
/// <param name="row">DataRow实例</param>
/// <returns>键为列名、值为对应数据的字典</returns>
public Dictionary<string, object> ToDictionary(DataRow row)
{
var dictionary = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
if (row == null) return dictionary;
foreach (DataColumn column in row.Table.Columns)
{
object value = row[column] == DBNull.Value ? null : row[column];
dictionary[column.ColumnName] = value;
}
return dictionary;
}
}
#endregion
}
+8 -18
View File
@@ -384,18 +384,13 @@ namespace DyeingComputer.View
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
SQLiteHelpers.Delete("RUN", null, null);
DataTable data_t = MainWindowViewModel.dt_TP.Clone();
for (int i = 0; i < MainWindowViewModel.dt_TP.Rows.Count; i++)
{
data_t.Clear();//清空
DataRow dt = MainWindowViewModel.dt_TP.Rows[i];//行转换
DataRow drT = data_t.NewRow();
drT.ItemArray = dt.ItemArray;
data_t.Rows.InsertAt(drT, 0);
drT.BeginEdit(); //添加订单号
drT["DYELOT"] = MainWindowViewModel.WorkNumder;
drT.EndEdit();
SQLiteHelpers.InsertData("RUN", SQLiteHelpers.DataTableToDictionary(data_t));//行插入
dt.BeginEdit(); //添加订单号
dt["DYELOT"] = MainWindowViewModel.Dyelot;
dt.EndEdit();
SQLiteHelpers.InsertData("RUN", SQLiteHelpers.ToDictionary(dt));//行插入
}
SQLiteHelpers.Close(); //关闭连接
APILog.LOGlog(MainWindowViewModel.WorkNumder.ToString(), "UserActions", "EDIT STEP = " + n,
@@ -553,18 +548,13 @@ namespace DyeingComputer.View
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
SQLiteHelpers.Delete("RUN", null, null);
DataTable data_t = MainWindowViewModel.dt_TP.Clone();
for (int i = 0; i < MainWindowViewModel.dt_TP.Rows.Count; i++)
{
data_t.Clear();//清空
DataRow dt = MainWindowViewModel.dt_TP.Rows[i];//行转换
DataRow drT = data_t.NewRow();
drT.ItemArray = dt.ItemArray;
data_t.Rows.InsertAt(drT, 0);
drT.BeginEdit(); //添加订单号
drT["DYELOT"] = MainWindowViewModel.WorkNumder;
drT.EndEdit();
SQLiteHelpers.InsertData("RUN", SQLiteHelpers.DataTableToDictionary(data_t));//行插入
dt.BeginEdit(); //添加订单号
dt["DYELOT"] = MainWindowViewModel.Dyelot;
dt.EndEdit();
SQLiteHelpers.InsertData("RUN", SQLiteHelpers.ToDictionary(dt));//行插入
}
SQLiteHelpers.Close(); //关闭连接
APILog.LOGlog(MainWindowViewModel.WorkNumder.ToString(), "UserActions", "Insert STEP = " + n,
+1
View File
@@ -91,6 +91,7 @@
<DataGridTextColumn Header="{x:Static lang:Resources.ProcessName}" Width="350" Binding="{Binding ProgramName}" IsReadOnly="True"/>
<DataGridTextColumn Header="ProcessID" Binding="{Binding ProgramID}" Width="0" MinWidth="0" MaxWidth="0"/>
<DataGridTextColumn Header="lock" Binding="{Binding lock}" Width="0" MinWidth="0" MaxWidth="0"/>
<DataGridTextColumn Header="DYELOT" Binding="{Binding Dyelot}" Width="0" MinWidth="0" MaxWidth="0"/>
<DataGridTextColumn Header="{x:Static lang:Resources.State}" Width="120" IsReadOnly="True">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
+7 -10
View File
@@ -83,6 +83,7 @@ namespace DyeingComputer.View
string Process_Name;
string Process_id;
string _lock;
string Dyelot;
bool SQL_UPDATE = false;
int inf_cont = 0;
@@ -225,6 +226,7 @@ namespace DyeingComputer.View
Process_Name = (Grid.Columns[1].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第1列,
Process_id = (Grid.Columns[2].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第0列,
_lock = (Grid.Columns[3].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第1列,
Dyelot = (Grid.Columns[4].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第1列,
SQL_UPDATE = true;
@@ -339,7 +341,6 @@ namespace DyeingComputer.View
}
DataTable WorkorderSteps = new DataTable();
DataTable data_t = new DataTable();
int a;
/*检查并写入run信息*/
@@ -369,27 +370,23 @@ namespace DyeingComputer.View
updata_temp.Clear(); //使用前清缓存
updata_temp.Add("State", 205);
SQLiteHelpers.Update("WorkOrder", updata_temp, "WorkOrder='" + WorkOrder_Numder + "'", null);
MainWindowViewModel.Dyelot_dat = SQLiteHelpers.ExecuteDataSet("select * from Dyelot where WorkOrder = '" +
WorkOrder_Numder + "'", null).Tables[0];
MainWindowViewModel.Dyelot_dat = SQLiteHelpers.ExecuteDataSet("select * from Dyelot where Dyelot = '" +
Dyelot + "'", null).Tables[0];
WorkorderSteps = SQLiteHelpers.ExecuteDataSet(
"select * from WorkorderSteps where WorkOrder='" + WorkOrder_Numder + "'", null).Tables[0]; //读取表写入缓存
MainWindowViewModel.ProgramName = Process_Name;
MainWindowViewModel.Dyelot = Dyelot;
SQLiteHelpers.Delete("RUN", null, null); //删除run信息
data_t = WorkorderSteps.Clone();
a = WorkorderSteps.Rows.Count;
for (int i = 0; i < a; i++)
{
data_t.Clear();//清空
DataRow dt = WorkorderSteps.Rows[i];//行转
DataRow dr = data_t.NewRow();
dr.ItemArray = dt.ItemArray;
DataRow dr = WorkorderSteps.Rows[i];//行转
dr.BeginEdit(); //添加订单号
dr["ProgramID"] = Process_id;
dr["Program"] = MainWindowViewModel.ProgramName;
dr.EndEdit();
data_t.Rows.InsertAt(dr, 0); //行转换
SQLiteHelpers.InsertData("RUN", SQLiteHelpers.DataTableToDictionary(data_t));//行插入
SQLiteHelpers.InsertData("RUN", SQLiteHelpers.ToDictionary(dr));//行插入
}
updata_temp.Clear(); //使用前清缓存
updata_temp.Add("RUN", 1);
+2
View File
@@ -79,6 +79,7 @@ namespace DyeingComputer.ViewModel
public static DataTable errTabler = new DataTable();//错误表
public static DataTable RUN_DATATABLE = new DataTable();//缓存工作表
public static DataTable Dyelot_dat = new DataTable();//物料表
public static string Dyelot; //领料单号
public static int RUN_STEPID;//当前步骤
public static int SYS_REDYE=0;//当前重燃步
public static string SYSKEY;
@@ -2843,6 +2844,7 @@ namespace DyeingComputer.ViewModel
dat_FR.Add("State", "201");
dat_FR.Add("Tank", TANK.ToString());
dat_FR.Add("Machine", S01);
dat_FR.Add("Type", Type);
dat_FR.Add("CALL_TIME", sys_Time);
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径