using DyeingComputer.View ;
using DyeingComputer.ViewModel ;
using System ;
using System.Collections.Generic ;
using System.Data ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
using System.Windows.Documents ;
using System.Xml.Linq ;
using static DyeingComputer . UserClass . SqliteHelper ;
namespace DyeingComputer.UserClass
{
public class SQLDATA
{
// private static SQLiteHelper SQLiteHelpers = null; //定义数据库
// private readonly static string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径
//WorkOrder表检查写入
public static bool WorkOrder ( string WorkOrder , string ProgramName , string StartTime , string EndTime , string Time , string Remark , string lock_ , string state , string ProgramID , string color , string dyelot )
{
// SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
// SQLiteHelpers.Open(); //打开数据库
object i = MainWindow . SQLiteHelpers . ExecuteScalar ( "select * from WorkOrder where WorkOrder = " + WorkOrder , null ) ;
if ( i ! = null )
{
//SQLiteHelpers.Close();
return false ;
}
Dictionary < string , object > WorkOrder_new = new Dictionary < string , object > ( ) ; //缓存函数
WorkOrder_new . Add ( "WorkOrder" , WorkOrder ) ;
WorkOrder_new . Add ( "ProgramName" , ProgramName ) ;
WorkOrder_new . Add ( "StartTime" , StartTime ) ;
WorkOrder_new . Add ( "EndTime" , EndTime ) ;
WorkOrder_new . Add ( "Time" , Time ) ;
WorkOrder_new . Add ( "Remark" , Remark ) ;
WorkOrder_new . Add ( "lock" , Convert . ToInt16 ( lock_ ) ) ;
WorkOrder_new . Add ( "state" , Convert . ToInt16 ( state ) ) ;
WorkOrder_new . Add ( "ProgramID" , ProgramID ) ;
WorkOrder_new . Add ( "color" , color ) ;
WorkOrder_new . Add ( "Dyelot" , dyelot ) ;
MainWindow . SQLiteHelpers . InsertData ( "WorkOrder" , WorkOrder_new ) ;
//SQLiteHelpers.Close();
return true ;
}
public static bool WorkOderStep ( DataTable WorkOrderStep_ )
{
// SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
// SQLiteHelpers.Open(); //打开数据库
int a = WorkOrderStep_ . Rows . Count ;
if ( a < 1 )
{
MainWindow . SQLiteHelpers . Close ( ) ;
return false ;
}
string Program = WorkOrderStep_ . Rows [ 0 ] [ 0 ] . ToString ( ) ;
object n = MainWindow . SQLiteHelpers . ExecuteScalar ( "select * from WorkorderSteps where Program = " + Program , null ) ;
if ( n ! = null ) //如id存在着返回错误状态
{
//SQLiteHelpers.Close();
return false ;
}
for ( int i = 0 ; i < a ; i + + )
{
MainWindow . SQLiteHelpers . InsertData ( "WorkorderSteps" , MainWindow . SQLiteHelpers . ToDictionary ( WorkOrderStep_ . Rows [ i ] ) ) ; //行插入
}
//SQLiteHelpers.Close(); //关闭连接
return true ;
}
public static void TechnologicalProcess_START ( string workName )
{
// SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
// SQLiteHelpers.Open(); //打开数据库
string sql_script = "select * from WorkorderSteps where ProgramID = '" + workName + "'" ;
// if (TechnologicalProcessView.sql != null) TechnologicalProcessView.sql.Clear(); //清空缓存
MainWindowViewModel . dt_TP = MainWindow . SQLiteHelpers . ExecuteDataSet ( sql_script , null ) . Tables [ 0 ] ; //读取表写入缓存
MainWindowViewModel . ProgramName = MainWindow . SQLiteHelpers . ExecuteScalar ( "select ProgramName from Workorder where ProgramID = '" + workName + "'" , null ) . ToString ( ) ;
MainWindow . SQLiteHelpers . Delete ( "RUN" , null , null ) ; //删除run信息
int a = MainWindowViewModel . dt_TP . Rows . Count ;
for ( int i = 0 ; i < a ; i + + )
{
MainWindow . SQLiteHelpers . InsertData ( "RUN" , MainWindow . SQLiteHelpers . ToDictionary ( MainWindowViewModel . dt_TP . Rows [ i ] ) ) ; //行插入
}
//数据插入
MainWindowViewModel . WorkNumder = MainWindow . SQLiteHelpers . ExecuteDataSet ( "select WorkOrder from Workorder where ProgramID = '" + workName + "'" , null ) ; ;
TechnologicalProcessView . workName = workName ;
MainWindowViewModel . SYS_REDYE = 0 ;
MainWindowViewModel . ViewID = 1 ;
//SQLiteHelpers.Close(); //关闭连接
}
public static bool Dyelot ( DataTable Dyelot_ ) //领料单
{
DataTable DyelotTable = new DataTable ( ) ;
DyelotTable . Columns . Add ( "WorkOrder" , Type . GetType ( "System.String" ) ) ;
DyelotTable . Columns . Add ( "Dyelot" , Type . GetType ( "System.String" ) ) ;
DyelotTable . Columns . Add ( "Redye" , Type . GetType ( "System.Int" ) ) ;
DyelotTable . Columns . Add ( "Step" , Type . GetType ( "System.Int" ) ) ;
DyelotTable . Columns . Add ( "Tank" , Type . GetType ( "System.Int" ) ) ;
DyelotTable . Columns . Add ( "State" , Type . GetType ( "System.Int" ) ) ;
DyelotTable . Columns . Add ( "Machine" , Type . GetType ( "System.String" ) ) ;
DyelotTable . Columns . Add ( "ProductCode" , Type . GetType ( "System.String" ) ) ;
DyelotTable . Columns . Add ( "ProductName" , Type . GetType ( "System.String" ) ) ;
DyelotTable . Columns . Add ( "ProductType" , Type . GetType ( "System.Int" ) ) ;
DyelotTable . Columns . Add ( "Grams" , Type . GetType ( "System.Double" ) ) ;
DyelotTable . Columns . Add ( "Amount" , Type . GetType ( "System.Double" ) ) ;
string [ ] columnsToCopy = { "WorkOrder" , "Dyelot" , "Redye" , "Step" , "Tank" , "State" , "Machine" ,
"ProductCode" , "ProductName" , "ProductType" , "Grams" , "Amount" } ;
foreach ( DataRow sourceRow in Dyelot_ . Rows )
{
DataRow newRow = DyelotTable . NewRow ( ) ;
foreach ( string colName in columnsToCopy )
{
if ( Dyelot_ . Columns . Contains ( colName ) )
{
newRow [ colName ] = sourceRow [ colName ] ;
}
}
DyelotTable . Rows . Add ( newRow ) ;
}
int a = DyelotTable . Rows . Count ;
if ( a < 1 ) return false ;
string Dyelot = DyelotTable . Rows [ 0 ] [ 0 ] . ToString ( ) ;
//SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
//SQLiteHelpers.Open(); //打开数据库
object n = MainWindow . SQLiteHelpers . ExecuteScalar ( "select * from Dyelot where Dyelot = " + Dyelot , null ) ;
if ( n ! = null ) //如id存在着返回错误状态
{
//SQLiteHelpers.Close();
return false ;
}
for ( int i = 0 ; i < a ; i + + )
{
MainWindow . SQLiteHelpers . InsertData ( "Dyelot" , MainWindow . SQLiteHelpers . ToDictionary ( DyelotTable . Rows [ i ] ) ) ; //行插入
}
//SQLiteHelpers.Close(); //关闭连接
return true ;
}
}
}