using Newtonsoft.Json.Linq ;
using nGantt.GanttChart ;
using ScottPlot.Palettes ;
using SunlightCentralizedControlManagement_SCCM_.UserClass ;
using SunlightCentralizedControlManagement_SCCM_.ViewModel ;
using SunlightCentralizedControlManagement_SCCM_.WindowsView ;
using System ;
using System.Collections.Generic ;
using System.Data ;
using System.Data.SqlClient ;
using System.Linq ;
using System.Text ;
using System.Text.RegularExpressions ;
using System.Threading.Tasks ;
using System.Windows ;
using System.Windows.Controls ;
using System.Windows.Data ;
using System.Windows.Documents ;
using System.Windows.Input ;
using System.Windows.Media ;
using System.Windows.Media.Imaging ;
using System.Windows.Navigation ;
using System.Windows.Shapes ;
using System.Xml.Linq ;
using TouchSocket.Core ;
using static SunlightCentralizedControlManagement_SCCM_ . UserClass . SqliteHelper ;
using static SunlightCentralizedControlManagement_SCCM_ . WindowsView . ViewStep ;
using static System . Windows . Forms . AxHost ;
namespace SunlightCentralizedControlManagement_SCCM_.View
{
/// <summary>
/// ProductionPlanningEdit.xaml 的交互逻辑
/// </summary>
public partial class DyeingPlanView : UserControl
{
private SQLiteHelper SQLiteHelpers = null ; //定义数据库
private readonly string DBAddress = Environment . CurrentDirectory + "\\DataBase\\SCCM.db" ; //数据库路径
DataTable ProgramName = new DataTable ( ) ;
DataTable WorkOrder = new DataTable ( ) ;
DataTable dat = new DataTable ( ) ;
DataTable TEMPTable = new DataTable ( ) ;
DataTable DyelotsBulkedRecipe = new DataTable ( ) ;
public string WorkOrder_n ;
public DyeingPlanView ( )
{
InitializeComponent ( ) ;
SQLiteHelpers = new SQLiteHelper ( DBAddress ) ; //数据库连接路径
SQLiteHelpers . Open ( ) ; //打开数据库
ProgramName = SQLiteHelpers . ExecuteDataSet ( "select * from ProgramName order by ProgramID desc" , null ) . Tables [ 0 ] ; //缓存
SQLiteHelpers . Close ( ) ; //关闭连接
comboBoxMachine . ItemsSource = MainWindowViewModel . Machines . AsEnumerable ( ) . Select ( rowdata = > rowdata . Field < string > ( "name" ) ) . ToList ( ) ; //转换机台
comboBoxProgram . ItemsSource = ProgramName . AsEnumerable ( ) . Select ( rowdata = > rowdata . Field < string > ( "ProgramName" ) ) . ToList ( ) ; //转换工艺代码
TEXTUSER . Text = MainWindow . user_ ;
TEMPTable . Columns . Add ( "Time" , Type . GetType ( "System.String" ) ) ;
TEMPTable . Columns . Add ( "MST" , Type . GetType ( "System.Double" ) ) ;
}
private void UserControl_Loaded ( object sender , RoutedEventArgs e )
{
}
private void comboBoxMachine_DropDownClosed ( object sender , EventArgs e ) //机台选择
{
string [ ] sArray = Regex . Split ( comboBoxMachine . Text , @"\+" , RegexOptions . IgnoreCase ) ;
if ( sArray . Length < = 1 )
{
comboBoxDyelot . IsEnabled = true ;
SQLiteHelpers = new SQLiteHelper ( DBAddress ) ; //数据库连接路径
SQLiteHelpers . Open ( ) ; //打开数据库
DataTable DatDyelot = SQLiteHelpers . ExecuteDataSet ( "select * from Dyelot where Machine='" + comboBoxMachine . Text + "' and State='101' order by Dyelot desc" , null ) . Tables [ 0 ] ; //读取计划表写入缓存
SQLiteHelpers . Close ( ) ; //关闭连接
comboBoxDyelot . ItemsSource = DatDyelot . AsEnumerable ( ) . Select ( rowdata = > rowdata . Field < string > ( "Dyelot" ) ) . ToList ( ) ; //转换代码
}
}
private void Button_Click ( object sender , RoutedEventArgs e ) //保存按钮
{
if ( string . IsNullOrEmpty ( comboBoxMachine . Text ) )
{
MessageBox . Show ( "Not Machine" , "SCCM" , MessageBoxButton . OK , MessageBoxImage . Question ) ;
return ;
}
if ( string . IsNullOrEmpty ( comboBoxProgram . Text ) )
{
MessageBox . Show ( "Not Program" , "SCCM" , MessageBoxButton . OK , MessageBoxImage . Question ) ;
return ;
}
string [ ] pArray = Regex . Split ( comboBoxProgram . Text , @"\+" , RegexOptions . IgnoreCase ) ;
//单机器信息写入
string sTime ;
string StartTime_ ;
string WorkOrder_ = comboBoxMachine . Text + "_" + DateTime . Now . ToString ( "yyMMddHHmmss" ) ;
if ( ! string . IsNullOrEmpty ( comboBoxWorkOrder . Text ) ) WorkOrder_ = comboBoxWorkOrder . Text ;
string ProgramName_ = comboBoxProgram . Text ;
string ProgramID_ = null ;
for ( int j = 0 ; j < pArray . Length ; j + + )
{
try
{
if ( j = = 0 )
{
ProgramID_ = ProgramName . Select ( "ProgramName='" + pArray [ j ] + "'" ) .
First ( ) . Field < object > ( "ProgramID" ) . ToString ( ) ;
}
else
{
ProgramID_ = ProgramID_ + "+" + ProgramName . Select ( "ProgramName='" + pArray [ j ] + "'" ) .
First ( ) . Field < object > ( "ProgramID" ) . ToString ( ) ;
}
}
catch ( Exception )
{
MessageBox . Show ( "Not Program" , "SCCM" , MessageBoxButton . OK , MessageBoxImage . Question ) ;
return ;
}
}
string Machines_ = comboBoxMachine . Text ;
string State_ = "100" ;
string Dyelot_ = comboBoxDyelot . Text ;
string color_ = color . Background . ToString ( ) ;
SQLiteHelpers = new SQLiteHelper ( DBAddress ) ; //数据库连接路径
SQLiteHelpers . Open ( ) ; //打开数据库
try
{
sTime = SQLiteHelpers . ExecuteDataSet (
"select * from WorkOrder where Machines='" + comboBoxMachine . Text + "' order by EndTime desc" , null ) .
Tables [ 0 ] . Select ( ) . First ( ) . Field < object > ( "EndTime" ) . ToString ( ) ; //读取计划表写入缓存
if ( DateTime . Now < DateTime . Parse ( sTime ) )
{
StartTime_ = DateTime . Parse ( sTime ) . AddMinutes ( 1 ) . ToString ( "yyyy/MM/dd HH:mm:ss" ) ;
}
else
{
StartTime_ = DateTime . Now . AddMinutes ( 1 ) . ToString ( "yyyy/MM/dd HH:mm:ss" ) ;
}
}
catch ( Exception )
{
StartTime_ = DateTime . Now . AddMinutes ( 1 ) . ToString ( "yyyy/MM/dd HH:mm:ss" ) ;
}
string Time_ = "0:00" ;
for ( int k = 0 ; k < pArray . Length ; k + + )
{
string t = ProgramName . Select ( "ProgramName='" + pArray [ k ] + "'" ) .
First ( ) . Field < object > ( "Time" ) . ToString ( ) ;
Time_ = ( DateTime . Parse ( Time_ ) + DateTime . Parse ( t ) . TimeOfDay ) . ToString ( "HH:mm:ss" ) ;
}
string EndTime_ = ( DateTime . Parse ( StartTime_ ) + DateTime . Parse ( Time_ ) . TimeOfDay ) . ToString ( "yyyy/MM/dd HH:mm:ss" ) ;
//插入数据信息
Dictionary < string , object > WorkOrder_new = new Dictionary < string , object > ( ) ; //缓存函数
WorkOrder_new . Add ( "StartTime" , StartTime_ ) ;
WorkOrder_new . Add ( "EndTime" , EndTime_ ) ;
WorkOrder_new . Add ( "Time" , Time_ ) ;
WorkOrder_new . Add ( "WorkOrder" , WorkOrder_ ) ;
WorkOrder_new . Add ( "ProgramName" , ProgramName_ ) ;
WorkOrder_new . Add ( "ProgramID" , ProgramID_ ) ;
WorkOrder_new . Add ( "Machines" , Machines_ ) ;
WorkOrder_new . Add ( "State" , State_ ) ;
WorkOrder_new . Add ( "Dyelot" , Dyelot_ ) ;
WorkOrder_new . Add ( "Remark" , null ) ;
WorkOrder_new . Add ( "lock" , 0 ) ;
WorkOrder_new . Add ( "color" , color_ ) ;
WorkOrder_new . Add ( "ColorNumber" , TEXTColorNumber . Text ) ;
WorkOrder_new . Add ( "Client" , TEXTClient . Text ) ;
WorkOrder_new . Add ( "ClothWeight" , TEXTClothWeight . Text ) ;
WorkOrder_new . Add ( "ClothSpecies" , TEXTClothSpecies . Text ) ;
WorkOrder_new . Add ( "BathRatio" , TEXTBathRatio . Text ) ;
WorkOrder_new . Add ( "Total" , TEXTTotal . Text ) ;
WorkOrder_new . Add ( "USER" , TEXTUSER . Text ) ;
WorkOrder_new . Add ( "ColorName" , TEXTColorName . Text ) ;
SQLiteHelpers . InsertData ( "WorkOrder" , WorkOrder_new ) ; // 执行插入
Dictionary < string , object > WorkOrder_DAT = new Dictionary < string , object > ( ) ; //缓存函数
for ( int x = 0 ; x < dat . Rows . Count ; x + + )
{
WorkOrder_DAT . Add ( "WorkOrder" , WorkOrder_ ) ;
WorkOrder_DAT . Add ( "Dyelot" , Dyelot_ ) ;
WorkOrder_DAT . Add ( "ProgramID" , dat . Rows [ x ] [ "ProgramID" ] ) ;
WorkOrder_DAT . Add ( "Program" , dat . Rows [ x ] [ "Program" ] ) ;
WorkOrder_DAT . Add ( "Step" , dat . Rows [ x ] [ "Step" ] ) ;
WorkOrder_DAT . Add ( "StepID" , dat . Rows [ x ] [ "StepID" ] ) ;
WorkOrder_DAT . Add ( "StepName" , dat . Rows [ x ] [ "StepName" ] ) ;
WorkOrder_DAT . Add ( "ParameterName" , dat . Rows [ x ] [ "ParameterName" ] ) ;
WorkOrder_DAT . Add ( "Parameter1" , dat . Rows [ x ] [ "Parameter1" ] ) ;
WorkOrder_DAT . Add ( "Parameter2" , dat . Rows [ x ] [ "Parameter2" ] ) ;
WorkOrder_DAT . Add ( "Parameter3" , dat . Rows [ x ] [ "Parameter3" ] ) ;
WorkOrder_DAT . Add ( "Parameter4" , dat . Rows [ x ] [ "Parameter4" ] ) ;
WorkOrder_DAT . Add ( "Parameter5" , dat . Rows [ x ] [ "Parameter5" ] ) ;
WorkOrder_DAT . Add ( "Parameter6" , dat . Rows [ x ] [ "Parameter6" ] ) ;
WorkOrder_DAT . Add ( "Parameter7" , dat . Rows [ x ] [ "Parameter7" ] ) ;
WorkOrder_DAT . Add ( "Parameter8" , dat . Rows [ x ] [ "Parameter8" ] ) ;
WorkOrder_DAT . Add ( "Parameter9" , dat . Rows [ x ] [ "Parameter9" ] ) ;
WorkOrder_DAT . Add ( "Parameter10" , dat . Rows [ x ] [ "Parameter10" ] ) ;
SQLiteHelpers . InsertData ( "WorkorderSteps" , WorkOrder_DAT ) ; //行插入
WorkOrder_DAT . Clear ( ) ;
}
if ( ! String . IsNullOrEmpty ( comboBoxDyelot . Text ) ) //料单信息
{
for ( int x = 0 ; x < DyelotsBulkedRecipe . Rows . Count ; x + + )
{
WorkOrder_DAT . Add ( "WorkOrder" , comboBoxWorkOrder . Text ) ;
WorkOrder_DAT . Add ( "Dyelot" , DyelotsBulkedRecipe . Rows [ x ] [ "Dyelot" ] ) ;
WorkOrder_DAT . Add ( "Redye" , DyelotsBulkedRecipe . Rows [ x ] [ "Redye" ] ) ;
WorkOrder_DAT . Add ( "Step" , DyelotsBulkedRecipe . Rows [ x ] [ "StepNumber" ] ) ;
WorkOrder_DAT . Add ( "TIME" , DyelotsBulkedRecipe . Rows [ x ] [ "Created" ] ) ;
WorkOrder_DAT . Add ( "Tank" , DyelotsBulkedRecipe . Rows [ x ] [ "TankNo" ] ) ;
WorkOrder_DAT . Add ( "State" , DyelotsBulkedRecipe . Rows [ x ] [ "DispenseResult" ] ) ;
WorkOrder_DAT . Add ( "Machine" , comboBoxMachine . Text ) ;
WorkOrder_DAT . Add ( "ProductCode" , DyelotsBulkedRecipe . Rows [ x ] [ "ProductCode" ] ) ;
WorkOrder_DAT . Add ( "ProductName" , DyelotsBulkedRecipe . Rows [ x ] [ "ProductName" ] ) ;
WorkOrder_DAT . Add ( "ProductType" , DyelotsBulkedRecipe . Rows [ x ] [ "ProductType" ] ) ;
WorkOrder_DAT . Add ( "Grams" , DyelotsBulkedRecipe . Rows [ x ] [ "Grams" ] ) ;
WorkOrder_DAT . Add ( "Amount" , DyelotsBulkedRecipe . Rows [ x ] [ "Amount" ] ) ;
WorkOrder_DAT . Add ( "DispenseStartTime" , DyelotsBulkedRecipe . Rows [ x ] [ "DispenseStartTime" ] ) ;
WorkOrder_DAT . Add ( "DispenseEndTime" , DyelotsBulkedRecipe . Rows [ x ] [ "DispenseEndTime" ] ) ;
WorkOrder_DAT . Add ( "DispenseGrams" , DyelotsBulkedRecipe . Rows [ x ] [ "DispenseGrams" ] ) ;
WorkOrder_DAT . Add ( "Dispense" , DyelotsBulkedRecipe . Rows [ x ] [ "Dispenser" ] ) ;
WorkOrder_DAT . Add ( "UserAccount" , DyelotsBulkedRecipe . Rows [ x ] [ "UserAccount" ] ) ;
SQLiteHelpers . InsertData ( "Dyelot" , WorkOrder_DAT ) ; //行插入
WorkOrder_DAT . Clear ( ) ;
}
}
SQLiteHelpers . Close ( ) ; //关闭连接
LogGing . ExchangeDATA ( "Dyelot=" + comboBoxWorkOrder . Text + ";Machine=" + comboBoxMachine . Text +
";Program=" + comboBoxProgram . Text + ";User=" + TEXTUSER . Text + ";" ) ;
this . Visibility = Visibility . Collapsed ;
ProductionPlanningView . UI = true ;
}
private void Button_Quit ( object sender , RoutedEventArgs e ) //退出
{
this . Visibility = Visibility . Collapsed ;
}
public void DatSteps ( DataTable db ) //行号刷新
{
int a = db . Rows . Count ;
for ( int i = 0 ; i < a ; i + + )
{
DataRow dr = db . Rows [ i ] ;
dr . BeginEdit ( ) ;
dr [ "Step" ] = i + 1 ;
dr . EndEdit ( ) ;
}
}
private void comboBoxProgram_DropDownClosed ( object sender , EventArgs e ) //工艺选择事件
{
if ( ! string . IsNullOrEmpty ( comboBoxProgram . Text ) )
{
dat . Clear ( ) ;
SQLiteHelpers = new SQLiteHelper ( DBAddress ) ; //数据库连接路径
SQLiteHelpers . Open ( ) ; //打开数据库
dat = SQLiteHelpers . ExecuteDataSet (
"select * from ProgramSteps where Program='" + comboBoxProgram . SelectedValue + "' order by Step asc" , null ) . Tables [ 0 ] ; //读取计划表写入缓存
SQLiteHelpers . Close ( ) ; //关闭连接
DatSteps ( dat ) ;
Grid_data . ItemsSource = dat . DefaultView ;
}
}
private void comboBoxProgram_TextChanged ( object sender , TextChangedEventArgs e )
{
dat . Clear ( ) ;
string text = comboBoxProgram . Text ;
if ( ! string . IsNullOrEmpty ( text ) )
{
try
{
string [ ] sArray = Regex . Split ( text , @"\+" , RegexOptions . IgnoreCase ) ;
SQLiteHelpers = new SQLiteHelper ( DBAddress ) ; //数据库连接路径
SQLiteHelpers . Open ( ) ; //打开数据库
/ * if ( ! string . IsNullOrEmpty ( WorkOrder_n ) )
{
dat = SQLiteHelpers . ExecuteDataSet (
"select * from WorkorderSteps where WorkOrder='" + WorkOrder_n + "' order by Step asc" , null ) . Tables [ 0 ] ; //读取计划表写入缓存
} //插入工单不为空时载入细节信息*/
for ( int i = 0 ; i < sArray . Length ; i + + )
{
DataTable temp = SQLiteHelpers . ExecuteDataSet (
"select * from ProgramSteps where Program='" + sArray [ i ] + "' order by Step asc" , null ) . Tables [ 0 ] ; //读取计划表写入缓存
if ( dat . Columns . Count = = 0 ) dat = temp . Clone ( ) ;
foreach ( DataRow drT in temp . Rows )
{
dat . Rows . Add ( drT . ItemArray ) ;
}
} //以工艺名组合工艺细节
SQLiteHelpers . Close ( ) ; //关闭连接
DatSteps ( dat ) ;
Grid_data . ItemsSource = dat . DefaultView ;
TEMP ( ) ;
}
catch ( Exception ) { }
}
} //工艺修改事件
string Numder = null ;
string ID = null ;
string P1 , P2 , P3 , P4 , P5 ;
private void MenuItem_edit ( object sender , RoutedEventArgs e )
{
int rownum = Grid_data . SelectedIndex ; //获取鼠标选中行并定义变量
if ( rownum ! = - 1 ) //判断鼠标定位是否有效
{
ID = ( Grid_data . Columns [ 2 ] . GetCellContent ( Grid_data . Items [ rownum ] ) as TextBlock ) . Text ; //定位第0列,
Numder = ( Grid_data . Columns [ 3 ] . GetCellContent ( Grid_data . Items [ rownum ] ) as TextBlock ) . Text ; //定位第1列,
P1 = ( Grid_data . Columns [ 6 ] . GetCellContent ( Grid_data . Items [ rownum ] ) as TextBlock ) . Text ; //定位第6列,
P2 = ( Grid_data . Columns [ 7 ] . GetCellContent ( Grid_data . Items [ rownum ] ) as TextBlock ) . Text ; //定位第7列,
P3 = ( Grid_data . Columns [ 8 ] . GetCellContent ( Grid_data . Items [ rownum ] ) as TextBlock ) . Text ; //定位第8列,
P4 = ( Grid_data . Columns [ 9 ] . GetCellContent ( Grid_data . Items [ rownum ] ) as TextBlock ) . Text ; //定位第9列,
P5 = ( Grid_data . Columns [ 1 0 ] . GetCellContent ( Grid_data . Items [ rownum ] ) as TextBlock ) . Text ; //定位第10列,
if ( string . IsNullOrEmpty ( Numder ) ) { Numder = null ; P1 = "0" ; P2 = "0" ; P3 = "0" ; P4 = "0" ; P5 = "0" ; }
if ( ID = = null ) ID = dat . Rows . Count . ToString ( ) ;
ViewStep viewstop = new ViewStep ( Numder , P1 , P2 , P3 , P4 , P5 ) ;
viewstop . AddressUpdated + = new ViewStep . AddressUpdateHandler ( Address_ButtonClicked ) ;
viewstop . data = ID ;
viewstop . ShowDialog ( ) ;
}
}
private void MenuItem_Insert ( object sender , RoutedEventArgs e ) //右键插入
{
int rownum = Grid_data . SelectedIndex ; //获取鼠标选中行并定义变量
if ( rownum ! = - 1 ) //判断鼠标定位是否有效
{
ID = ( Grid_data . Columns [ 2 ] . GetCellContent ( Grid_data . Items [ rownum ] ) as TextBlock ) . Text ; //定位列,
int d = 0 ;
if ( ID ! = null ) { d = Convert . ToInt32 ( ID ) ; } else { return ; }
string ProgramID = dat . Select ( ) . First ( ) . Field < string > ( "ProgramID" ) . ToString ( ) ;
string ProgramNAME = dat . Select ( ) . First ( ) . Field < string > ( "Program" ) . ToString ( ) ;
DataRow dr = dat . NewRow ( ) ; //添加表数据
dr [ "ProgramID" ] = ProgramID ;
dr [ "Program" ] = ProgramNAME ;
dat . Rows . InsertAt ( dr , d - 1 ) ;
DatSteps ( dat ) ;
Grid_data . ItemsSource = dat . DefaultView ;
if ( ID = = null ) ID = dat . Rows . Count . ToString ( ) ;
ViewStep viewstop = new ViewStep ( null , null , null , null , null , null ) ;
viewstop . AddressUpdated + = new ViewStep . AddressUpdateHandler ( Address_ButtonClicked ) ;
viewstop . data = ID ;
viewstop . ShowDialog ( ) ;
}
}
private void MenuItem_Delete ( object sender , RoutedEventArgs e ) //右键删除
{
int rownum = Grid_data . SelectedIndex ; //获取鼠标选中行并定义变量
if ( rownum ! = - 1 ) //判断鼠标定位是否有效
{
ID = ( Grid_data . Columns [ 2 ] . GetCellContent ( Grid_data . Items [ rownum ] ) as TextBlock ) . Text ; //定位第0列,
dat . Rows . RemoveAt ( Convert . ToInt32 ( ID ) - 1 ) ;
DatSteps ( dat ) ;
Grid_data . ItemsSource = dat . DefaultView ;
}
}
private void Grid_data_MouseDoubleClick ( object sender , MouseButtonEventArgs e )
{
int rownum = Grid_data . SelectedIndex ; //获取鼠标选中行并定义变量
if ( rownum ! = - 1 ) //判断鼠标定位是否有效
{
ID = ( Grid_data . Columns [ 2 ] . GetCellContent ( Grid_data . Items [ rownum ] ) as TextBlock ) . Text ; //定位第0列,
Numder = ( Grid_data . Columns [ 3 ] . GetCellContent ( Grid_data . Items [ rownum ] ) as TextBlock ) . Text ; //定位第1列,
P1 = ( Grid_data . Columns [ 6 ] . GetCellContent ( Grid_data . Items [ rownum ] ) as TextBlock ) . Text ; //定位第6列,
P2 = ( Grid_data . Columns [ 7 ] . GetCellContent ( Grid_data . Items [ rownum ] ) as TextBlock ) . Text ; //定位第7列,
P3 = ( Grid_data . Columns [ 8 ] . GetCellContent ( Grid_data . Items [ rownum ] ) as TextBlock ) . Text ; //定位第8列,
P4 = ( Grid_data . Columns [ 9 ] . GetCellContent ( Grid_data . Items [ rownum ] ) as TextBlock ) . Text ; //定位第9列,
P5 = ( Grid_data . Columns [ 1 0 ] . GetCellContent ( Grid_data . Items [ rownum ] ) as TextBlock ) . Text ; //定位第10列,
if ( string . IsNullOrEmpty ( Numder ) ) { Numder = null ; P1 = "0" ; P2 = "0" ; P3 = "0" ; P4 = "0" ; P5 = "0" ; }
if ( ID = = null ) ID = dat . Rows . Count . ToString ( ) ;
ViewStep viewstop = new ViewStep ( Numder , P1 , P2 , P3 , P4 , P5 ) ;
viewstop . AddressUpdated + = new ViewStep . AddressUpdateHandler ( Address_ButtonClicked ) ;
viewstop . data = ID ;
viewstop . ShowDialog ( ) ;
}
}
private void Address_ButtonClicked ( object sender , AddressUpdateEventArgs e ) //编辑返回结果
{
int i = dat . Rows . Count ;
int n = StrToInt . To16Convert10 ( ID ) ;
if ( e . Mode )
{
DataRow dr = dat . Rows [ n - 1 ] ;
dr . BeginEdit ( ) ;
dr [ "StepID" ] = e . StepID ;
dr [ "StepName" ] = e . StepNAME ;
dr [ "ParameterName" ] = e . PNAME ;
dr [ "Parameter1" ] = e . P1 ;
dr [ "Parameter2" ] = e . P2 ;
dr [ "Parameter3" ] = e . P3 ;
dr [ "Parameter4" ] = e . P4 ;
dr [ "Parameter5" ] = e . P5 ;
dr . EndEdit ( ) ;
}
else
{
dat . Rows . RemoveAt ( Convert . ToInt32 ( ID ) - 1 ) ;
DatSteps ( dat ) ;
}
Grid_data . ItemsSource = dat . DefaultView ;
}
private void TEMP ( )
{
//处理计划温度图表
TEMPTable . Clear ( ) ;
DataRow nrow = TEMPTable . NewRow ( ) ;
string TIMET = "00:00:00" ;
Double MSTT = 3 0.0 ;
TEMPTable . Rows . Add ( new object [ ] { TIMET , MSTT } ) ;
for ( int i = 0 ; i < dat . Rows . Count ; i + + )
{
switch ( dat . Rows [ i ] [ 3 ] . ToString ( ) ) //步骤用时计算
{
case "001" :
Double TT = MSTT ;
Double TC ;
TC = ( Double ) dat . Rows [ i ] [ 7 ] ;
if ( TC > 9.9 | | TC < 0.1 ) TC = 9.9 ; //计算限制
MSTT = ( Double ) dat . Rows [ i ] [ 6 ] ;
TT = Math . Abs ( MSTT - TT ) / TC * 6 0 ;
TIMET = Convert . ToDateTime ( TIMET ) . AddSeconds ( TT ) . ToString ( "HH:mm:ss" ) ;
TEMPTable . Rows . Add ( new object [ ] { TIMET , MSTT } ) ;
TIMET = Convert . ToDateTime ( TIMET ) . AddMinutes ( ( Double ) dat . Rows [ i ] [ 8 ] ) . ToString ( "HH:mm:ss" ) ;
TEMPTable . Rows . Add ( new object [ ] { TIMET , MSTT } ) ;
break ;
case "007" :
TIMET = Convert . ToDateTime ( TIMET ) . AddMinutes ( 5 ) . ToString ( "HH:mm:ss" ) ;
TEMPTable . Rows . Add ( new object [ ] { TIMET , MSTT } ) ;
break ;
case "008" :
TIMET = Convert . ToDateTime ( TIMET ) . AddMinutes ( 5 ) . ToString ( "HH:mm:ss" ) ;
TEMPTable . Rows . Add ( new object [ ] { TIMET , MSTT } ) ;
break ;
case "013" :
break ;
case "015" :
break ;
case "017" :
break ;
case "020" :
TIMET = Convert . ToDateTime ( TIMET ) . AddMinutes ( 5 ) . ToString ( "HH:mm:ss" ) ;
TEMPTable . Rows . Add ( new object [ ] { TIMET , MSTT } ) ;
break ;
case "022" :
TIMET = Convert . ToDateTime ( TIMET ) . AddMinutes ( 5 ) . ToString ( "HH:mm:ss" ) ;
TEMPTable . Rows . Add ( new object [ ] { TIMET , MSTT } ) ;
break ;
case "031" :
TIMET = Convert . ToDateTime ( TIMET ) . AddMinutes ( ( int ) dat . Rows [ i ] [ 6 ] ) . ToString ( "HH:mm:ss" ) ;
TEMPTable . Rows . Add ( new object [ ] { TIMET , MSTT } ) ;
break ;
case "065" :
TIMET = Convert . ToDateTime ( TIMET ) . AddMinutes ( ( int ) dat . Rows [ i ] [ 8 ] ) . ToString ( "HH:mm:ss" ) ;
TEMPTable . Rows . Add ( new object [ ] { TIMET , MSTT } ) ;
break ;
case "091" :
break ;
case "093" :
TIMET = Convert . ToDateTime ( TIMET ) . AddMinutes ( ( int ) dat . Rows [ i ] [ 6 ] ) . ToString ( "HH:mm:ss" ) ;
TEMPTable . Rows . Add ( new object [ ] { TIMET , MSTT } ) ;
break ;
default :
break ;
}
}
Picture . Content = new View . CurveTemp ( TEMPTable ) ;
} //计划温度图表
private async void comboBoxWorkOrder_KeyDown ( object sender , KeyEventArgs e ) //工单输入
{
if ( e . Key = = Key . Enter & & MainWindowViewModel . DyelotsDispenser )
{
SQLiteHelpers = new SQLiteHelper ( DBAddress ) ;
SQLiteHelpers . Open ( ) ; //打开数据库
int dat_c = SQLiteHelpers . ExecuteDataSet ( "select * from WorkOrder where WorkOrder = '" + comboBoxWorkOrder . Text + "'" , null ) . Tables [ 0 ] . Rows . Count ; //缓存
SQLiteHelpers . Close ( ) ;
if ( dat_c > 0 ) //查询料单是否可用
{
comboBoxWorkOrder . Text = null ;
MessageBox . Show ( Properties . Resources . TTAE , "WorkOrder" , MessageBoxButton . OK , MessageBoxImage . Information ) ; //连接成功提示是否保存
return ;
}
string Connstr_SC ;
string DYELOTS_sql = "SELECT * FROM [dbo].[DYELOTS] WHERE Dyelot = '" + comboBoxWorkOrder . Text + "'" ; //单号查询语句
string DyelotsBulkedRecipe_sql = "SELECT * FROM [dbo].[DyelotsBulkedRecipe] WHERE Dyelot = '" + comboBoxWorkOrder . Text + "'" ;
try
{
if ( MainWindowViewModel . SQMOD = = "Windows Authentication" )
{
Connstr_SC = "server=" + MainWindowViewModel . SQLIP + ";database=" + MainWindowViewModel . SQLNAME + ";Trusted_Connection=SSPI" ;
}
else
{
Connstr_SC = "server=" + MainWindowViewModel . SQLIP + ";database=" + MainWindowViewModel . SQLNAME + ";User ID=" + MainWindowViewModel . SQLUSER + ";Password=" + MainWindowViewModel . SQLPASWORD ;
}
SqlConnection conn_SC = new SqlConnection ( Connstr_SC ) ;
await conn_SC . OpenAsync ( ) ; //连接数据库
SqlDataAdapter DYELOTS_data = new SqlDataAdapter ( DYELOTS_sql , Connstr_SC ) ; //查询
SqlDataAdapter DyelotsBulkedRecipe_ = new SqlDataAdapter ( DyelotsBulkedRecipe_sql , Connstr_SC ) ;
conn_SC . Close ( ) ;
DyelotsBulkedRecipe_ . Fill ( DyelotsBulkedRecipe ) ;
DataTable ds = new DataTable ( ) ; //载入信息
DYELOTS_data . Fill ( ds ) ;
TEXTColorNumber . Text = ds . AsEnumerable ( ) . Select ( row = > row . Field < string > ( "ColorNo" ) ) . First ( ) ;
TEXTColorName . Text = ds . AsEnumerable ( ) . Select ( row = > row . Field < string > ( "ColorName" ) ) . First ( ) ;
TEXTClient . Text = ds . AsEnumerable ( ) . Select ( row = > row . Field < string > ( "CustomerName" ) ) . First ( ) ;
TEXTClothSpecies . Text = ds . AsEnumerable ( ) . Select ( row = > row . Field < string > ( "FabricName" ) ) . First ( ) ;
TEXTClothWeight . Text = ds . AsEnumerable ( ) . Select ( row = > row . Field < Double > ( "TotalWeight" ) ) . First ( ) . ToString ( ) ;
TEXTBathRatio . Text = ds . AsEnumerable ( ) . Select ( row = > row . Field < string > ( "LiquidRatio" ) ) . First ( ) ;
TEXTTotal . Text = ds . AsEnumerable ( ) . Select ( row = > row . Field < string > ( "TotalVolume" ) ) . First ( ) ;
comboBoxDyelot . Text = ds . AsEnumerable ( ) . Select ( row = > row . Field < string > ( "Dyelot" ) ) . First ( ) ;
string machine_ = ds . AsEnumerable ( ) . Select ( row = > row . Field < string > ( "Machine" ) ) . First ( ) ; //机台
if ( MainWindowViewModel . Machines . Select ( "Name ='" + machine_ + "'" ) . Length = = 0 )
{
comboBoxMachine . Text = null ;
}
else
{
comboBoxMachine . Text = machine_ ;
}
string user_ = ds . AsEnumerable ( ) . Select ( row = > row . Field < string > ( "UserAccount" ) ) . First ( ) ; //用户名
if ( ! String . IsNullOrEmpty ( user_ ) ) TEXTUSER . Text = user_ ;
comboBoxProgram . Text = ds . AsEnumerable ( ) . Select ( row = > row . Field < string > ( "Program" ) ) . First ( ) ;
if ( ds . AsEnumerable ( ) . Select ( row = > row . Field < int > ( "color" ) ) . First ( ) > 0 ) //颜色
{
string colorValue = string . Format ( "{0:X6}" , ds . AsEnumerable ( ) . Select ( row = > row . Field < int > ( "color" ) ) . First ( ) ) ; //十进制RGB数值转十六进制六位RGB并补0位例“C0C0C0”
color . Background = new SolidColorBrush ( ( Color ) ColorConverter . ConvertFromString (
"#FF" + colorValue . Substring ( 4 , 2 ) + colorValue . Substring ( 2 , 2 ) + colorValue . Substring ( 0 , 2 ) ) ) ;
}
}
catch ( Exception ex )
{
LogGing . ERRDATA ( ex ) ;
}
}
}
private async void comboBoxDyelot_KeyDown ( object sender , KeyEventArgs e ) //料单输入
{
if ( e . Key = = Key . Enter & & MainWindowViewModel . DyelotsDispenser )
{
string Connstr_SC ;
string DYELOTS_sql = "SELECT * FROM [dbo].[DYELOTS] WHERE Dyelot = '" + comboBoxDyelot . Text + "'" ; //单号查询语句
try
{
SQLiteHelpers = new SQLiteHelper ( DBAddress ) ;
SQLiteHelpers . Open ( ) ; //打开数据库
int dat_c = SQLiteHelpers . ExecuteDataSet ( "select * from Dyelot where Dyelot = '" + comboBoxDyelot . Text + "'" , null ) . Tables [ 0 ] . Rows . Count ; //缓存
SQLiteHelpers . Close ( ) ;
if ( dat_c > 0 ) //查询料单是否可用
{
comboBoxDyelot . Text = null ;
MessageBox . Show ( Properties . Resources . TPLHBU , "Dyelot" , MessageBoxButton . OK , MessageBoxImage . Information ) ; //连接成功提示是否保存
return ;
}
if ( MainWindowViewModel . SQMOD = = "Windows Authentication" )
{
Connstr_SC = "server=" + MainWindowViewModel . SQLIP + ";database=" + MainWindowViewModel . SQLNAME + ";Trusted_Connection=SSPI" ;
}
else
{
Connstr_SC = "server=" + MainWindowViewModel . SQLIP + ";database=" + MainWindowViewModel . SQLNAME + ";User ID=" + MainWindowViewModel . SQLUSER + ";Password=" + MainWindowViewModel . SQLPASWORD ;
}
SqlConnection conn_SC = new SqlConnection ( Connstr_SC ) ;
await conn_SC . OpenAsync ( ) ; //连接数据库
SqlDataAdapter DYELOTS_data = new SqlDataAdapter ( DYELOTS_sql , Connstr_SC ) ; //查询
conn_SC . Close ( ) ;
DataTable ds = new DataTable ( ) ; //载入信息
DYELOTS_data . Fill ( ds ) ;
TEXTColorNumber . Text = ds . AsEnumerable ( ) . Select ( row = > row . Field < string > ( "ColorNo" ) ) . First ( ) ;
TEXTColorName . Text = ds . AsEnumerable ( ) . Select ( row = > row . Field < string > ( "ColorName" ) ) . First ( ) ;
TEXTClient . Text = ds . AsEnumerable ( ) . Select ( row = > row . Field < string > ( "CustomerName" ) ) . First ( ) ;
TEXTClothSpecies . Text = ds . AsEnumerable ( ) . Select ( row = > row . Field < string > ( "FabricName" ) ) . First ( ) ;
TEXTClothWeight . Text = ds . AsEnumerable ( ) . Select ( row = > row . Field < Double > ( "TotalWeight" ) ) . First ( ) . ToString ( ) ;
TEXTBathRatio . Text = ds . AsEnumerable ( ) . Select ( row = > row . Field < string > ( "LiquidRatio" ) ) . First ( ) ;
TEXTTotal . Text = ds . AsEnumerable ( ) . Select ( row = > row . Field < string > ( "TotalVolume" ) ) . First ( ) ;
// comboBoxDyelot.Text = ds.AsEnumerable().Select(row => row.Field<string>("Dyelot")).First();
string machine_ = ds . AsEnumerable ( ) . Select ( row = > row . Field < string > ( "Machine" ) ) . First ( ) ; //机台
if ( MainWindowViewModel . Machines . Select ( "Name ='" + machine_ + "'" ) . Length = = 0 )
{
comboBoxMachine . Text = null ;
}
else
{
comboBoxMachine . Text = machine_ ;
}
string user_ = ds . AsEnumerable ( ) . Select ( row = > row . Field < string > ( "UserAccount" ) ) . First ( ) ; //用户名
if ( ! String . IsNullOrEmpty ( user_ ) ) TEXTUSER . Text = user_ ;
comboBoxProgram . Text = ds . AsEnumerable ( ) . Select ( row = > row . Field < string > ( "Program" ) ) . First ( ) ;
if ( ds . AsEnumerable ( ) . Select ( row = > row . Field < int > ( "color" ) ) . First ( ) > 0 ) //颜色
{
string colorValue = string . Format ( "{0:X6}" , ds . AsEnumerable ( ) . Select ( row = > row . Field < int > ( "color" ) ) . First ( ) ) ; //十进制RGB数值转十六进制六位RGB并补0位例“C0C0C0”
color . Background = new SolidColorBrush ( ( Color ) ColorConverter . ConvertFromString (
"#FF" + colorValue . Substring ( 4 , 2 ) + colorValue . Substring ( 2 , 2 ) + colorValue . Substring ( 0 , 2 ) ) ) ;
}
}
catch ( Exception ex )
{
LogGing . ERRDATA ( ex ) ;
}
}
}
private void Tb_KeyTEXTClothWeight ( object sender , TextCompositionEventArgs e ) //输入事件
{
Regex numbeRegex = new Regex ( "^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$" ) ;
e . Handled =
! numbeRegex . IsMatch (
TEXTClothWeight . Text . Insert (
TEXTClothWeight . SelectionStart , e . Text ) ) ;
TEXTClothWeight . Text = TEXTClothWeight . Text . Trim ( ) ;
}
private void Tb_KeyTEXTBathRatio ( object sender , TextCompositionEventArgs e ) //输入事件
{
Regex numbeRegex = new Regex ( "^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$" ) ;
e . Handled =
! numbeRegex . IsMatch (
TEXTBathRatio . Text . Insert (
TEXTBathRatio . SelectionStart , e . Text ) ) ;
TEXTBathRatio . Text = TEXTBathRatio . Text . Trim ( ) ;
}
private void Tb_KeyTEXTTotal ( object sender , TextCompositionEventArgs e ) //输入事件
{
Regex numbeRegex = new Regex ( "^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$" ) ;
e . Handled =
! numbeRegex . IsMatch (
TEXTTotal . Text . Insert (
TEXTTotal . SelectionStart , e . Text ) ) ;
TEXTTotal . Text = TEXTTotal . Text . Trim ( ) ;
}
private void color_color_MouseDoubleClick ( object sender , MouseButtonEventArgs e ) //颜色
{
System . Windows . Forms . ColorDialog colorDialog = new System . Windows . Forms . ColorDialog ( ) ; //使用调色盘控件ColorDialog
if ( colorDialog . ShowDialog ( ) = = System . Windows . Forms . DialogResult . OK ) //打开调色盘
{
System . Drawing . Color DColor = colorDialog . Color ; ////获取选中色彩信息
//System.Windows.Media.Color MColor = new System.Windows.Media.Color();//转换
System . Windows . Media . Color MColor = System . Windows . Media . Color . FromArgb ( DColor . A , DColor . R , DColor . G , DColor . B ) ; //转换并配置ARGB参数
color . Background = new SolidColorBrush ( MColor ) ; //ARGB参数输出至Color的背景色
//string colorCode = string.Format("{0:X2}", DColor.B) + string.Format("{0:X2}", DColor.G) + string.Format("{0:X2}", DColor.R);//反向十六进制RGB
//string colorCode = string.Format("{0:X2}", DColor.R) + string.Format("{0:X2}", DColor.G) + string.Format("{0:X2}", DColor.B);//正向十六进制RGB
//ColorCode_SQL = Convert.ToInt32(colorCode, 16);//十六进制RGB转存储数值
}
}
}
}