Ejemplo n.º 1
0
        void resolver(string title, string scriptId)
        {
            bool retest = System.Configuration.ConfigurationManager.AppSettings["retest"] == "true";

            if (title == "已执行" && !retest)
            {
                MessageBox.Show("解析器已执行,无法重复执行!");
                return;
            }

            string taskid = currentInfo.id;

            DataImport.DataAccess.Entitys.TaskInfo.resolver ar = currentInfo.resolvers.FirstOrDefault(it => it.resolverId == scriptId);
            if (ar != null)
            {
                TaskCenter.TaskID      = currentInfo.id;
                TaskCenter.CurrentInfo = currentInfo;
                TaskCenter.ScriptCode  = ar.resolverCode;
                TaskCenter.ScriptID    = ar.resolverId;

                MainWindow window = App.Current.MainWindow as MainWindow;

                UIElement item = new ImportFileSelecte();

                ImportStack.clear();
                ImportStack.Push(this);

                window.StartPage(item);
            }
        }
Ejemplo n.º 2
0
        private void prvButton_Click(object sender, RoutedEventArgs e)
        {
            MainWindow window = App.Current.MainWindow as MainWindow;
            UIElement  item   = ImportStack.Pop();

            window.StartPage(item);
        }
Ejemplo n.º 3
0
        private void nextButton_Click(object sender, RoutedEventArgs e)
        {
            string erromsg = "";


            if (string.IsNullOrEmpty(MidsScriptCode.Text.Trim()))
            {
                erromsg += "请输入解析器编码!\r\n";
            }
            else
            {
                if (string.IsNullOrEmpty(FID) && (!checkCode()))
                {
                    erromsg += "解析器编码重复!\r\n";
                }
            }
            if (string.IsNullOrEmpty(MidsScriptName.Text.Trim()))
            {
                erromsg += "请输入解析器名称!\r\n";
            }
            if (string.IsNullOrEmpty(txtTemplageFile.Text.Trim()))
            {
                erromsg += "请选择样例文件!\r\n";
            }
            if (Des_Table.SelectedIndex == -1)
            {
                erromsg += "请选择目标数据表!\r\n";
            }

            if (!string.IsNullOrEmpty(erromsg))
            {
                MessageBox.Show(erromsg);
                return;
            }

            if (string.IsNullOrEmpty(FID))
            {
                insert();
            }
            else
            {
                Update();
            }

            DataScriptMapModify mapModify = new DataScriptMapModify();

            mapModify.FID            = FID;
            mapModify.DataScriptRule = dRule;
            mapModify.DataScript     = dScript;
            MainWindow window = App.Current.MainWindow as MainWindow;

            ImportStack.Push(this);

            window.StartPage(mapModify);
        }
Ejemplo n.º 4
0
        private void btNext_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(txtTemplageFile.Text.Trim()))
            {
                MessageBox.Show("请选择导入文件");
                return;
            }

            if (f**k.IsChecked.Value && false)
            {
                List <string> difference = new List <string>();

                foreach (DataColumn column in sourceDt.Columns)
                {
                    if (structures.FirstOrDefault(it => it.Comments == column.ColumnName) == null)
                    {
                        difference.Add(column.ColumnName);
                    }
                }

                if (difference.Count > structures.Count(it => string.IsNullOrEmpty(it.Comments)))
                {
                    MessageBox.Show("剩余空闲字段不足,无法导入全部字段,请重新选择数据文件!");
                    return;
                }
                Comments();

                if (update.IsChecked.Value)
                {
                    float newVersion = float.Parse(dataScript.MidsScriptVesion) + 0.1f;
                    DataScriptDAL.updateLevel(dataScript.FID, newVersion.ToString());
                }
            }


            dataScript = (DataScript)ScriptName.SelectedItem;

            ImportMapModify mapModify = new ImportMapModify();

            mapModify.FID            = dataScript.FID;
            mapModify.DataScriptRule = dataRule;
            mapModify.DataScript     = dataScript;
            mapModify.sourceFile     = txtTemplageFile.Text;

            importGrid.getHexColumn();

            ImportStack.Push(this);
            MainWindow window = App.Current.MainWindow as MainWindow;

            window.StartPage(mapModify);
        }
Ejemplo n.º 5
0
        private void Direct_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Image img = (Image)sender;

            TaskCenter.TaskID = img.Tag.ToString();
            var project = dataSource.SingleOrDefault(it => it.FID == TaskCenter.TaskID);

            if (project != null)
            {
                TaskCenter.ScriptID = project.ScriptID;
            }

            MainWindow window = App.Current.MainWindow as MainWindow;

            UIElement item = new DataImportInteractive.DataScriptInfo();

            ImportStack.clear();
            ImportStack.Push(this);

            window.StartPage(item);
        }
Ejemplo n.º 6
0
        private void scriptrun_Click(object sender, RoutedEventArgs e)
        {
            var taskinfos = taskGrid.getTaskInfos(); // dataGrid.SelectedItems;

            Dictionary <string, string> files = new Dictionary <string, string>();

            if (taskinfos.Count == 0)
            {
                MessageBox.Show("您未选择任何工序!");
                return;
            }

            foreach (TaskInfo info in taskinfos)
            {
                string scriptPath = string.Format(@"{0}\{1}\Sequence.xml", AppDomain.CurrentDomain.BaseDirectory + @"scripts", info.id);
                if (downLoadScriptFile(info))
                {
                    files.Add(info.taskName, scriptPath);
                }
            }

            if (files.Count == taskinfos.Count)
            {
                MainWindow window = App.Current.MainWindow as MainWindow;

                UIElement item = new SequencesView(files);

                ImportStack.clear();
                ImportStack.Push(this);

                window.StartPage(item);
            }
            else
            {
                MessageBox.Show("您选择的工序没有配置脚本文件!");
            }
        }
Ejemplo n.º 7
0
        private void nextButton_Click(object sender, RoutedEventArgs e)
        {
            string erromsg = "";

            if (string.IsNullOrEmpty(txtTemplageFile.Text.Trim()))
            {
                erromsg += "请选择样例文件!\r\n";
            }

            if (Des_Table.SelectedIndex == -1)
            {
                erromsg += "请选择目标数据表!\r\n";
            }

            if (Des_Table.SelectedIndex == 0 && string.IsNullOrEmpty(txtTableName.Text))
            {
                erromsg += "请输入数据表名称!\r\n";
            }

            if (Des_Table.SelectedIndex == 0 && string.IsNullOrEmpty(txtTableCode.Text))
            {
                erromsg += "请输入数据表代码!\r\n";
            }


            if (cbSave.IsChecked.Value)
            {
                if (string.IsNullOrEmpty(MidsScriptCode.Text.Trim()))
                {
                    erromsg += "请输入解析器编码!\r\n";
                }
                else
                {
                    if (!checkCode())
                    {
                        erromsg += "解析器编码重复!\r\n";
                    }
                }
                if (string.IsNullOrEmpty(MidsScriptName.Text.Trim()))
                {
                    erromsg += "请输入解析器名称!\r\n";
                }
            }

            if (!string.IsNullOrEmpty(erromsg))
            {
                MessageBox.Show(erromsg);
                return;
            }

            builderScript();


            if (cbSave.IsChecked.Value)
            {
                insert();
            }
            DataTable dt = new DataTable();

            if (FileType.SelectedValue.ToString() == "xls/xlsx")
            {
                dt = ExcelImportHelper.GetDataTable(txtTemplageFile.Text.Trim());
            }
            else
            {
                dt = TextImportHelper.GetDataTable(txtTemplageFile.Text.Trim(), DataScriptRule.getColSeperatorChar(GetColSperator()));
            }

            TableDAL.CreateTable(txtTableCode.Text.ToUpper(), dt);

            int count = ObjtableInfoDAL.Count(txtTableCode.Text.ToUpper());

            if (count == 0)
            {
                ObjtableInfo oinfo = new ObjtableInfo();
                oinfo.FID             = Guid.NewGuid().ToString().Replace("-", "");
                oinfo.CreatedBy       = MainWindow.UserID;
                oinfo.LastUpdatedBy   = MainWindow.UserID;
                oinfo.ObjectTableCode = txtTableCode.Text.ToUpper();
                oinfo.ObjectTableName = txtTableName.Text;
                oinfo.Status          = "02";
                oinfo.Version         = 1;
                oinfo.LastUpdateIp    = "127.0.0.1";
                oinfo.LastUpdateDate  = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                oinfo.CreationDate    = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                ObjtableInfoDAL.Insert(oinfo);
            }

            ImportMapModify mapModify = new ImportMapModify();

            mapModify.FID            = FID;
            mapModify.DataScriptRule = dRule;
            mapModify.DataScript     = dScript;
            mapModify.sourceFile     = txtTemplageFile.Text.Trim();
            mapModify.isAutoDrawLine = true;

            ImportStack.Push(this);
            MainWindow window = App.Current.MainWindow as MainWindow;

            window.StartPage(mapModify);
        }
Ejemplo n.º 8
0
        private void nextButton_Click(object sender, RoutedEventArgs e)
        {
            string erromsg = "";

            if (string.IsNullOrEmpty(MidsScriptCode.Text.Trim()))
            {
                erromsg += "请输入解析器编码!\r\n";
            }


            if (string.IsNullOrEmpty(TaskName.Text.Trim()))
            {
                erromsg += "请输入试验名称!\r\n";
            }
            if (string.IsNullOrEmpty(MidsScriptName.Text.Trim()))
            {
                erromsg += "请输入解析器名称!\r\n";
            }
            if (string.IsNullOrEmpty(txtTemplageFile.Text.Trim()))
            {
                erromsg += "请选择样例文件!\r\n";
            }
            else if (FileType.SelectedValue.ToString() != "xls/xlsx" && FileType.SelectedValue.ToString() != "mdb" && FileType.SelectedValue.ToString() != "db")
            {
                string[] columns = TextImportHelper.GetColumns(txtTemplageFile.Text, DataScriptRule.getColSeperatorChar(GetColSperator()));
                if (columns.Length < 2)
                {
                    erromsg += "数据文件列分隔符不存在,请选择相应列分隔符!\r\n";
                }
            }

            dScript = new DataScript();


            dScript.MidsScriptCode   = MidsScriptCode.Text.Trim();
            dScript.MidsScriptName   = MidsScriptName.Text.Trim();
            dScript.MidsScriptVesion = MidsScriptVesion.Text.Trim();
            dScript.FileType         = FileType.SelectedValue.ToString();
            dScript.IndexKey         = IndexKey.Text.Trim();
            dScript.ValidFlag        = ValidFlag.Text.Trim();
            dScript.ApplyTestProject = ApplyTestProject.SelectedValue.ToString();
            dScript.CreationDate     = DateTime.Now;
            dScript.LastUpdateDate   = DateTime.Now;
            dScript.LastUpdateIp     = "127.0.0.1";
            dScript.Version          = 1;
            dScript.LastUpdatedBy    = MainWindow.UserID;
            dScript.CreatedBy        = MainWindow.UserID;
            dScript.ScriptType       = ScriptType.SelectedIndex;
            dScript.TableName        = txtTableName.Text;
            dScript.ProjectCode      = ProjectCode.SelectedValue.ToString();
            dScript.TaskName         = TaskName.Text.Trim();

            // 这是sqlitedb格式,需要计算tablenameex
            if (FileType.SelectedValue.ToString() == "db")
            {
                int    count      = SQLiteImportHelper.GetTableNames(txtTemplageFile.Text).Count();
                string tablenames = "";
                for (int i = 1; i <= count; i++)
                {
                    tablenames += string.Format("{0}_{1},", txtTableName.Text, i);
                }
                dScript.TableNameExt = tablenames.TrimEnd(',');
            }

            dRule = new DataScriptRule();

            dRule.ColSperator    = GetColSperator();
            dRule.ColnameLines   = int.Parse(ColName_Lines.Text.Trim());
            dRule.DesTable       = txtTableName.Text;
            dRule.DesFile        = txtTemplageFile.Text;
            dRule.CreationDate   = DateTime.Now;
            dRule.LastUpdateDate = DateTime.Now;
            dRule.LastUpdateIp   = "127.0.0.1";
            dRule.Version        = 1;
            dRule.DesBusinessPk  = "";
            dRule.CreatedBy      = MainWindow.UserID;
            dRule.LastUpdatedBy  = MainWindow.UserID;

            // 我发现,现在就没有更新逻辑
            //if (string.IsNullOrEmpty(FID))
            //{
            //    var oldScript = scripts.FirstOrDefault(it => it.ScriptType == dScript.ScriptType && it.ProjectCode == dScript.ProjectCode && it.TaskName == dScript.TaskName);
            //    if (oldScript != null)
            //    {
            //        FID = oldScript.FID;
            //        dScript.FID = FID;

            //    }
            //}

            if (!string.IsNullOrEmpty(erromsg))
            {
                MessageBox.Show(erromsg);
                return;
            }

            var oldScript = scripts.FirstOrDefault(it => it.ScriptType == dScript.ScriptType && it.ProjectCode == dScript.ProjectCode && it.TaskName == dScript.TaskName);

            if (oldScript != null)
            {
                dScript.FID = Guid.NewGuid().ToString().Replace("-", "");
                FID         = dScript.FID;
                dRule.FID   = dScript.FID;
                dRule.MdsImpDataScriptID = dScript.FID;

                insertScript();
                // 正常表
                updateTableStructure();

                if (FileType.SelectedValue.ToString() == "db")
                {
                    // sqlite 多表
                    foreach (string tname in dScript.TableNameExt.Split(','))
                    {
                        updateTableStructure(tname);
                    }
                }
            }
            else
            {
                dScript.FID = Guid.NewGuid().ToString().Replace("-", "");
                FID         = dScript.FID;
                dRule.FID   = dScript.FID;
                dRule.MdsImpDataScriptID = dScript.FID;

                insertScript();
                // 正常表
                insertTableStructure();

                if (FileType.SelectedValue.ToString() == "db")
                {
                    // sqlite 多表,再把多表搞一下。
                    foreach (string tname in dScript.TableNameExt.Split(','))
                    {
                        insertTableStructure(tname);
                    }
                }
            }


            DataScriptMapModify mapModify = new DataScriptMapModify();

            mapModify.FID            = FID;
            mapModify.DataScriptRule = dRule;
            mapModify.DataScript     = dScript;
            MainWindow window = App.Current.MainWindow as MainWindow;

            ImportStack.Push(this);

            window.StartPage(mapModify);
        }
Ejemplo n.º 9
0
        private void btnNext_Click(object sender, RoutedEventArgs e)
        {
            ImportRun mapModify = new ImportRun();

            mapModify.DataScript     = this.DataScript;
            mapModify.DataScriptRule = this.DataScriptRule;
            mapModify.ColumnMap      = columnConnection.ColumnMap;
            mapModify.ScriptMap      = columnConnection.ScriptMap;
            mapModify.sourceFile     = sourceFile;
            mapModify.DataScriptRule.DesBusinessPk = columnConnection.BusinessPK;

            if (!mapModify.ColumnMap.ContainsKey("COLUMN0"))
            {
                MessageBox.Show("您需要指定时间列的关联关系,才可以导入数据!");
                return;
            }

            foreach (string key in mapModify.ScriptMap.Keys)
            {
                string script = mapModify.ScriptMap[key].Trim();
                if (!string.IsNullOrEmpty(script))
                {
                    DataScriptMapDAL.SaveScriptFile(key, script);
                }
            }

            // 保存对应关系
            if (DataScriptInfo.saveScript || true)
            {
                DataScriptMapDAL.delAll(FID);

                DataScriptRuleDAL.updateBusinessPK(FID, columnConnection.BusinessPK);

                foreach (var key in columnConnection.ColumnMap.Keys)
                {
                    DataScriptMap map = new DataScriptMap();
                    map.FID = Guid.NewGuid().ToString().Replace("-", "");
                    map.MdsImpDataScriptRuleID = FID;
                    map.TableColName           = key;
                    map.FileColName            = columnConnection.ColumnMap[key];
                    map.TransferType           = "02";
                    map.CreatedBy     = MainWindow.UserID;
                    map.LastUpdatedBy = MainWindow.UserID;
                    map.LastUpdateIp  = "127.0.0.1";

                    // 如果有算式,保存
                    if (columnConnection.ScriptMap.ContainsKey(key))
                    {
                        map.TransferScript = columnConnection.ScriptMap[key];
                    }

                    DataScriptMapDAL.Insert(map);
                }
                //MessageBox.Show("对应关系已经保存!");
            }

            ImportStack.Push(this);

            MainWindow window = App.Current.MainWindow as MainWindow;

            window.StartPage(mapModify);
        }
Ejemplo n.º 10
0
        public static bool Process(string command)
        {
            return(parser.ParseArguments <ExitOption, ConfigOption, SwitchOption, ClientOption, ImportOption, LsOption, ShowOption, AddpkgOption, EditpkgOption, DelpkgOption, AddverOption, EditverOption, DelverOption, HelpOption>(
                       CommandSplitter.Split(command))
                   .MapResult(
                       (ExitOption opt) => {
                if (opt.IsForce)
                {
                    return true;
                }
                else
                {
                    if (!General.IsMaintaining)
                    {
                        General.CoreTcpProcessor.StopListen();
                        Console.WriteLine("Waiting the release of resources...");
                        if (General.ManualResetEventList.Count != 0)
                        {
                            WaitHandle.WaitAll(General.ManualResetEventList.ToArray());
                        }
                    }
                    else
                    {
                        General.GeneralDatabase.Close();
                    }

                    General.RecordFileManager.Close();
                    return true;
                }
            },
                       (ConfigOption opt) => {
                if (opt.Key is null)
                {
                    foreach (var item in General.ConfigManager.Configuration.Keys)
                    {
                        Console.Write($"{item}: ");
                        Console.Write($"{General.ConfigManager.Configuration[item]}\n");
                    }
                }
                else
                {
                    if (opt.NewValue is null)
                    {
                        if (General.ConfigManager.Configuration.Keys.Contains(opt.Key))
                        {
                            Console.WriteLine(General.ConfigManager.Configuration[opt.Key]);
                        }
                    }
                    else
                    {
                        if (General.ConfigManager.Configuration.Keys.Contains(opt.Key))
                        {
                            General.ConfigManager.Configuration[opt.Key] = opt.NewValue;
                            General.ConfigManager.Save();
                            Console.WriteLine("New value has been applied");
                        }
                    }
                }
                return false;
            },
                       (SwitchOption opt) => {
                if (!General.IsMaintaining)
                {
                    General.CoreTcpProcessor.StopListen();
                    Console.WriteLine("Waiting the release of resources...");
                    if (General.ManualResetEventList.Count != 0)
                    {
                        WaitHandle.WaitAll(General.ManualResetEventList.ToArray());
                    }

                    General.GeneralDatabase.Open();

                    General.IsMaintaining = true;
                    ConsoleAssistance.WriteLine("Switch to maintain mode successfully.", ConsoleColor.Yellow);
                }
                else
                {
                    General.GeneralDatabase.Close();
                    //force update verify code
                    ConsoleAssistance.WriteLine("Updating verify code....", ConsoleColor.White);
                    General.VerifyBytes = SignVerifyHelper.SignData(Information.WorkPath.Enter("package.db").Path, Information.WorkPath.Enter("pri.key").Path);
                    General.ConfigManager.Configuration["VerifyBytes"] = Convert.ToBase64String(General.VerifyBytes);
                    General.ConfigManager.Save();

                    General.CoreTcpProcessor.StartListen();

                    General.IsMaintaining = false;
                    ConsoleAssistance.WriteLine("Switch to running mode successfully.", ConsoleColor.Yellow);
                }
                return false;
            },
                       (ClientOption opt) => {
                if (!CheckStatus(false))
                {
                    return false;
                }

                ConsoleAssistance.WriteLine($"Current client: {General.ManualResetEventList.Count}", ConsoleColor.Yellow);
                return false;
            },
                       (ImportOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }

                ConsoleAssistance.WriteLine("import is a dangerous command. It will load all script and run it without any error judgement! It couldn't be stopped before all of commands has been executed!", ConsoleColor.Yellow);
                var confirm = new Random().Next(100, 9999);
                ConsoleAssistance.WriteLine($"Type this random number to confirm your operation: {confirm}", ConsoleColor.Yellow);
                if (Console.ReadLine() == confirm.ToString())
                {
                    if (System.IO.File.Exists(opt.FilePath))
                    {
                        ImportStack.AppendImportedCommands(opt.FilePath);
                    }
                    else
                    {
                        ConsoleAssistance.WriteLine("Cannot find specific file", ConsoleColor.Red);
                    }
                }
                return false;
            },
                       (LsOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }

                if (opt.Condition is null)
                {
                    PackageManager.Ls(General.GeneralDatabase, "");
                }
                else
                {
                    PackageManager.Ls(General.GeneralDatabase, opt.Condition);
                }
                return false;
            },
                       (ShowOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }
                PackageManager.Show(General.GeneralDatabase, opt.FullPackageName);
                return false;
            },
                       (AddpkgOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }
                PackageManager.AddPackage(General.GeneralDatabase, opt);
                return false;
            },
                       (EditpkgOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }
                PackageManager.EditPackage(General.GeneralDatabase, opt);
                return false;
            },
                       (DelpkgOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }
                PackageManager.RemovePackage(General.GeneralDatabase, opt.Name);
                return false;
            },
                       (AddverOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }
                PackageManager.AddVersion(General.GeneralDatabase, opt);
                return false;
            },
                       (EditverOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }
                PackageManager.EditVersion(General.GeneralDatabase, opt);
                return false;
            },
                       (DelverOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }
                PackageManager.RemoveVersion(General.GeneralDatabase, opt.Name);
                return false;
            },
                       (HelpOption opt) => {
                OutputHelp();
                return false;
            },
                       errs => { ConsoleAssistance.WriteLine("Unknow command. Use help to find the correct command", ConsoleColor.Red); return false; }));
        }