Exemplo n.º 1
0
        private void showData()
        {
            dScript = DataScriptDAL.getInfo(FID);
            dRule   = DataScriptRuleDAL.getInfo(FID);

            ProjectCode.SelectedValue = dScript.ProjectCode;
            TaskName.Text             = dScript.TaskName;
            txtTableName.Text         = dScript.TableName;
            MidsScriptCode.Text       = dScript.MidsScriptCode;
            MidsScriptName.Text       = dScript.MidsScriptName;
            MidsScriptVesion.Text     = dScript.MidsScriptVesion;
            FileType.SelectedValue    = dScript.FileType;
            IndexKey.Text             = dScript.IndexKey;
            ValidFlag.Text            = dScript.ValidFlag;
            Remark.Text = dScript.Remark;
            ApplyTestProject.SelectedValue = dScript.ApplyTestProject;
            ScriptType.SelectedIndex       = dScript.ScriptType;

            SetColSperator(dRule.ColSperator);
            ColName_Lines.Text = dRule.ColnameLines.ToString();

            if (tables.SingleOrDefault(it => it.TableName == dRule.DesTable) == null)
            {
                tables.Add(new TableInfo()
                {
                    TableDesc = dRule.DesTable, TableName = dRule.DesTable
                });
            }
            ProjectCode.SelectedValue = dScript.ProjectCode;

            txtTemplageFile.Text = dRule.DesFile;
        }
Exemplo n.º 2
0
        public static int Insert(DataScriptRule item)
        {
            string sql = string.Format("INSERT INTO MDS_IMP_DATA_SCRIPT_RULE(FID,MDS_IMP_DATA_SCRIPT_ID,LINE_SEPERATOR,COL_SEPERATOR,COLNAME_LINES,DATA_LINES,DES_TABLE,REMARK,CREATED_BY,CREATION_DATE,LAST_UPDATED_BY,LAST_UPDATE_DATE,LAST_UPDATE_IP,VERSION,DES_FILE) ");

            sql += string.Format("VALUES('{0}','{1}','{2}','{3}',{4},{5},'{6}','{7}','{8}',to_date('{9}','yyyy/mm/dd hh24:mi:ss'),'{10}',to_date('{11}','yyyy/mm/dd hh24:mi:ss'),'{12}',{13},'{14}')",
                                 item.FID, item.MdsImpDataScriptID, item.LineSeperator, item.ColSperator, item.ColnameLines, item.DataLines,
                                 item.DesTable, item.Remark, item.CreatedBy,
                                 item.CreationDate.ToString("yyyy/MM/dd HH:mm:ss"), item.LastUpdatedBy, item.LastUpdateDate.ToString("yyyy/MM/dd HH:mm:ss"), item.LastUpdateIp, item.Version, item.DesFile);

            return(OracleHelper.Excuse(sql));
        }
Exemplo n.º 3
0
        public static int update(DataScriptRule item)
        {
            string sql = string.Format("UPDATE MDS_IMP_DATA_SCRIPT_RULE SET ");

            sql += string.Format("LINE_SEPERATOR='{0}',", item.LineSeperator);
            sql += string.Format("COL_SEPERATOR='{0}',", item.ColSperator);
            sql += string.Format("COLNAME_LINES={0},", item.ColnameLines);
            sql += string.Format("DATA_LINES={0},", item.DataLines);
            sql += string.Format("DES_TABLE='{0}',", item.DesTable);
            sql += string.Format("DES_FILE='{0}',", item.DesFile);
            sql += string.Format("REMARK='{0}',", item.Remark);
            sql += string.Format("LAST_UPDATE_DATE=to_date('{0}','yyyy/mm/dd hh24:mi:ss') ", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
            sql += string.Format("WHERE FID='{0}' ", item.FID);
            return(OracleHelper.Excuse(sql));
        }
Exemplo n.º 4
0
        public static DataScriptRule getInfo(string fid)
        {
            DataScriptRule result = null;

            string sql = string.Format("SELECT * FROM MDS_IMP_DATA_SCRIPT_RULE WHERE FID='{0}'", fid);

            DataSet ds = OracleHelper.Query(sql);

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                DataScriptRule item = DataScriptRule.Parse(dr);
                result = item;
            }
            return(result);
        }
Exemplo n.º 5
0
        public static List <DataScriptRule> getList()
        {
            List <DataScriptRule> result = new List <DataScriptRule>();

            string sql = "SELECT * FROM MDS_IMP_DATA_SCRIPT_RULE";

            DataSet ds = OracleHelper.Query(sql);

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                DataScriptRule item = DataScriptRule.Parse(dr);
                result.Add(item);
            }

            return(result);
        }
Exemplo n.º 6
0
        public Class1(string userID, string userName, string projectCode, string taskCode, string scriptCode, int times, string sourceFile)
        {
            this.userID = userID;
            var taskInfoList = WebHelper.listTdmTasks(userName);

            this.taskInfo = taskInfoList.FirstOrDefault(it => it.taskCode == taskCode);

            // "b1190f6a66a94b6eb110b3ffc0739887";
            string fid = scriptCode2Fid(scriptCode);

            this.dataScript     = DataScriptDAL.getInfo(fid);
            this.dataScriptRule = DataScriptRuleDAL.getInfo(fid);
            this.times          = times;
            this.sourceFile     = sourceFile;
            this.columnMap      = getColumnMap();
            this.calColumnMap();

            if (this.dataScriptRule != null)
            {
                this.structList = TableDAL.getTableStructure(this.dataScriptRule.DesTable);
            }
        }
Exemplo n.º 7
0
        private void insert()
        {
            dScript = new DataScript();

            dScript.FID              = Guid.NewGuid().ToString().Replace("-", "");
            FID                      = dScript.FID;
            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;

            dRule     = new DataScriptRule();
            dRule.FID = dScript.FID;    // Guid.NewGuid().ToString().Replace("-", "");
            dRule.MdsImpDataScriptID = dScript.FID;
            dRule.ColSperator        = GetColSperator();
            dRule.ColnameLines       = int.Parse(ColName_Lines.Text.Trim());
            dRule.DesTable           = (Des_Table.SelectedItem as TableInfo).TableName;
            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;

            DataScriptDAL.Insert(dScript);
            DataScriptRuleDAL.Insert(dRule);
        }
Exemplo n.º 8
0
        private DataTable GetDataTable(string fileName)
        {
            DataTable dt;

            if (FileType.SelectedValue.ToString() == "mdb")
            {
                AccessImportHelper helper = new AccessImportHelper(fileName);
                dt = helper.getDataTable();
            }
            else if (FileType.SelectedValue.ToString() == "xls/xlsx")
            {
                dt = ExcelImportHelper.GetDataTable(fileName);
            }
            else if (FileType.SelectedValue.ToString() == "db")
            {
                dt = SQLiteImportHelper.GetDataTable(fileName);
            }
            else
            {
                dt = TextImportHelper.GetDataTable(fileName, DataScriptRule.getColSeperatorChar(GetColSperator()));
            }
            return(dt);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        private void openTemplateFile_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog();

            if (FileType.SelectedValue.ToString() == "xls/xlsx")
            {
                dialog.Filter = "(Excel 文件)|*.xls;*.xlsx";
            }
            if (FileType.SelectedValue.ToString() == "txt")
            {
                dialog.Filter = "(文本文件)|*.txt";
            }
            if (FileType.SelectedValue.ToString() == "dat")
            {
                dialog.Filter = "(数据文件)|*.dat";
            }
            if (FileType.SelectedValue.ToString() == "mdb")
            {
                dialog.Filter = "(数据文件)|*.mdb";
            }
            if (FileType.SelectedValue.ToString() == "db")
            {
                dialog.Filter = "(sqlite文件)|*.db";
            }
            if (FileType.SelectedValue.ToString() == "fws10")
            {
                dialog.Filter = "(fws10文件)|*.fws10";
            }

            System.Windows.Forms.DialogResult result = dialog.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                txtTemplageFile.Text = dialog.FileName;

                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)
                    {
                        MessageBox.Show("数据文件列分隔符不存在,请选择相应列分隔符!");
                    }

                    if (columns.Contains(System.Configuration.ConfigurationManager.AppSettings["pk"]))
                    {
                        nextButton.Visibility = System.Windows.Visibility.Visible;
                    }
                    else
                    {
                        nextButton.Visibility = System.Windows.Visibility.Collapsed;
                        MessageBox.Show(string.Format("数据文件中缺少默认主键列({0}),请重新选择正确数据文件!", ConfigurationManager.AppSettings["pk"]));
                    }
                }
            }
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
        public bool init()
        {
            var taskInfoList = TaskinfoDAL.getList(userName);

            if (taskInfoList == null || taskInfoList.Count == 0)
            {
                SendMessageEvent(false, string.Format("用户[{0}],无任务数据", userName));
                CompleteEvent(this, new CompleteArgs()
                {
                    Message = "数据导入失败"
                });
                return(false);
            }

            this.taskInfo = taskInfoList.FirstOrDefault(it => it.taskCode == taskCode);

            if (taskInfo == null)
            {
                SendMessageEvent(false, string.Format("任务[{0}],不存在", taskCode));
                CompleteEvent(this, new CompleteArgs()
                {
                    Message = "数据导入失败"
                });
                return(false);
            }

            var dataSource = WebHelper.listTdmTaskTimesInfo(taskInfo.id);

            if (dataSource.Count(it => it.TestTime == this.times.ToString()) < 1)
            {
                SendMessageEvent(false, string.Format("任务 [ {0} ] ,试验次数 [ {1} ] 不存在,", taskCode, this.times));
                CompleteEvent(this, new CompleteArgs()
                {
                    Message = "数据导入失败"
                });
                return(false);
            }

            string fid = scriptCode2Fid(scriptCode);

            if (string.IsNullOrEmpty(fid))
            {
                SendMessageEvent(false, string.Format("任务[{0}],不存在", taskCode));
                CompleteEvent(this, new CompleteArgs()
                {
                    Message = "数据导入失败"
                });
                return(false);
            }

            this.dataScript = DataScriptDAL.getInfo(fid);

            if (dataScript == null)
            {
                SendMessageEvent(false, string.Format("任务[{0}],不存在", taskCode));
                CompleteEvent(this, new CompleteArgs()
                {
                    Message = "数据导入失败"
                });
                return(false);
            }

            this.dataScriptRule = DataScriptRuleDAL.getInfo(fid);

            if (dataScriptRule == null)
            {
                SendMessageEvent(false, string.Format("任务规则[{0}],不存在", fid));
                CompleteEvent(this, new CompleteArgs()
                {
                    Message = "数据导入失败"
                });
                return(false);
            }

            this.columnMap = getColumnMap();

            if (this.dataScriptRule != null)
            {
                this.structList = TableDAL.getTableStructure(this.dataScriptRule.DesTable);
            }

            return(true);
        }
Exemplo n.º 13
0
        private void openTemplateFile_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            dataScript = ScriptName.SelectedItem as DataScript;

            dataRule = DataScriptRuleDAL.getInfo(dataScript.FID);

            System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog();

            if (FileType.SelectedValue.ToString() == "xls/xlsx")
            {
                dialog.Filter = "(Excel 文件)|*.xls;*.xlsx";
            }
            else if (FileType.SelectedValue.ToString() == "dat")
            {
                dialog.Filter = "(dat 文件)|*.dat";
            }
            else if (FileType.SelectedValue.ToString() == "db")
            {
                dialog.Filter = "(sqlite 文件)|*.db";
            }
            else if (FileType.SelectedValue.ToString() == "mdb")
            {
                dialog.Filter = "(mdb 文件)|*.mdb";
            }
            else if (FileType.SelectedValue.ToString() == "fws10")
            {
                dialog.Filter = "(fws10 文件)|*.fws10";
            }
            else
            {
                dialog.Filter = "(文本文件)|*.txt";
            }

            System.Windows.Forms.DialogResult result = dialog.ShowDialog();

            DataTable dt = new DataTable();

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                txtTemplageFile.Text = dialog.FileName;

                if (FileType.SelectedValue.ToString() == "mdb")
                {
                    AccessImportHelper helper = new AccessImportHelper(dialog.FileName);
                    dt = helper.getDataTable();
                }
                else if (FileType.SelectedValue.ToString() == "xls/xlsx")
                {
                    dt = ExcelImportHelper.GetDataTable(dialog.FileName);
                }
                else if (FileType.SelectedValue.ToString() == "db")
                {
                    dt = SQLiteImportHelper.GetDataTable(dialog.FileName);
                }
                else
                {
                    dt = TextImportHelper.GetDataTable(dialog.FileName, dataRule.getColSeperatorChar());
                }

                dataGrid.ItemsSource   = dt.AsDataView();
                importGrid.ItemsSource = dt;
                checkStruct(dt, dataScript);
            }
        }