Ejemplo n.º 1
0
 public bool AddDataBaseName()
 {
     DAL.Common.Initialise();
     using (DbConnection conn = new DbConnection())
     {
         bool         flag         = false;
         string[]     names        = pathTextBox.Text.Split("\\".ToCharArray());
         DataBaseName dataBaseName = new DataBaseName()
         {
             DataBaseCode = names[names.Count() - 1],
             Location     = pathTextBox.Text,
             DataBaseType = (int)DataBaseType.SQLite
         };
         List <DataBaseName> dataBaseNameList = DataBaseNameDic.GetDataBaseNameDic().GetAllBaseNames();
         for (int i = 0; i < dataBaseNameList.Count; i++)
         {
             if (dataBaseNameList[i].Location == pathTextBox.Text)
             {
                 flag = true;
             }
         }
         if (!flag)
         {
             DataBaseNameDic.GetDataBaseNameDic().Add(dataBaseName);
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 提取其他数据库
 /// </summary>
 private void ExtractOtherDb()
 {
     try
     {
         List <DataBaseName> dataBaselist = DataBaseNameDic.GetDataBaseNameDic().GetOtherDataBaseName();
         if (dataBaselist.Count > 0)
         {
             foreach (DataBaseName baseName in dataBaselist)
             {
                 try
                 {
                     this.ExtractOtherOneDb(baseName);
                 }
                 catch (Exception ex)
                 {
                     log.Error(ex.Message);
                     continue;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         log.Error(ex.Message);
     }
 }
Ejemplo n.º 3
0
 public bool AddDataBaseName(string dbName, string path, int daType)
 {
     using (DbConnection conn = new DbConnection())
     {
         bool         flag         = false;
         DataBaseName dataBaseName = new DataBaseName()
         {
             DataBaseCode = dbName,
             Location     = path,
             DataBaseType = daType,
         };
         DataBaseNameDic.GetDataBaseNameDic();
         List <DataBaseName> dataBaseNameList = DataBaseNameDic.GetDataBaseNameDic().GetAllBaseNames();
         for (int i = 0; i < dataBaseNameList.Count; i++)
         {
             if (dataBaseNameList[i].Location == path)
             {
                 flag = true;
             }
         }
         if (!flag)
         {
             DataBaseNameDic.GetDataBaseNameDic().Add(dataBaseName);
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Ejemplo n.º 4
0
        private void addGroupButton_Click(object sender, EventArgs e)
        {
            string orgin    = "填写或选择分组";
            bool   divCal   = false;
            int    DBNameID = 0;

            if (filOrChoGroupComboBox.Text != orgin)
            {
                if (!filOrChoGroupComboBox.Items.Contains(filOrChoGroupComboBox.Text) &&
                    filOrChoGroupComboBox.Text != "")
                {
                    using (DbConnection conn = new DbConnection())
                    {
                        DataBaseNameDic.GetDataBaseNameDic();
                        List <DataBaseName> dataBaseNameList = DataBaseNameDic.GetDataBaseNameDic().GetAllBaseNames();

                        for (int i = 0; i < dataBaseNameList.Count; i++)
                        {
                            if (DBLocation == dataBaseNameList[i].Location)
                            {
                                DBNameID = Convert.ToInt32(dataBaseNameList[i].ID);
                            }
                        }

                        int safetypeid = -1;

                        foreach (IDandName idandName in IdName)
                        {
                            if (idandName.Name == safeTypeComboBox.Text)
                            {
                                safetypeid = idandName.ID;
                            }
                        }
                        if (divCalCheckBox.Checked)
                        {
                            divCal = true;
                        }

                        GroupInfo group = new GroupInfo()
                        {
                            GroupName            = filOrChoGroupComboBox.Text,
                            DataBaseID           = DBNameID,
                            Safetyfactortypeid   = safetypeid,
                            CombinationCalculate = divCal
                        };
                        int groupId = GroupInfosDic.GetGroupInfoDic().CheckAdd(group);
                        if (AddSensorToGroup(groupId))
                        {
                            MessageBox.Show("添加成功");
                        }
                    }
                }
            }
            InitlizeFilOrChoGroupComboBox();
        }
Ejemplo n.º 5
0
 private void ExtractTextDb()
 {
     try
     {
         List <DataBaseName> dataBaselist = DataBaseNameDic.GetDataBaseNameDic().GetTextBaseNames();
         if (dataBaselist.Count > 0)
         {
             foreach (DataBaseName baseName in dataBaselist)
             {
                 this.ExtractOneTextDb(baseName);
             }
         }
     }
     catch (Exception ex)
     {
         log.Error(ex.Message);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 查找所有有配置表的数据库
        /// </summary>
        /// <returns></returns>
        public List <DataBaseName> SeleDataBaseNames()
        {
            List <DataBaseName> list = new List <DataBaseName>();

            foreach (ConfigTable config in configTables.Values)
            {
                // config.DataBaseId
                bool ishas = false;
                foreach (DataBaseName dataBase in list)
                {
                    if ((int)dataBase.ID == config.DataBaseId)
                    {
                        ishas = true;
                        break;
                    }
                }
                if (!ishas)
                {
                    list.Add(DataBaseNameDic.GetDataBaseNameDic().SelectBaseName(config.DataBaseId));
                }
            }

            return(list);
        }
Ejemplo n.º 7
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            int  m    = 0;
            bool flag = false;

            for (m = 0; m < dgvDataBase.Rows.Count; m++)
            {
                if (dgvDataBase.Rows[m].Selected)
                {
                    string       Id     = dgvDataBase.Rows[m].Cells[0].Value.ToString();
                    DialogResult result = MessageBox.Show(@"是否删除?", @"提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    {
                        if (result == DialogResult.Yes)
                        {
                            if (DataBaseNameDic.GetDataBaseNameDic().Delete(Convert.ToInt32(Id)))
                            {
                                bool deleResult = false;
                                //同时删除与该数据库有关的配置

                                //删除配置表的信息
                                List <ConfigTable> listConfigTable = ConfigTableDic.GetConfigTableDic().SelectList();
                                for (int i = 0; i < listConfigTable.Count; i++)
                                {
                                    if (listConfigTable[i].DataBaseId == Convert.ToInt32(Id))
                                    {
                                        deleResult = ConfigTableDic.GetConfigTableDic().Delete(Convert.ToInt32(listConfigTable[i].ID));
                                    }
                                }

                                //删除数据表的信息
                                List <TableFieldInfo> listTable = TableFieldInfoDic.GetTableFieldInfoDic().GetAllTableFieldInfos();
                                for (int i = 0; i < listTable.Count; i++)
                                {
                                    if (listTable[i].DataBaseId == Convert.ToInt32(Id))
                                    {
                                        deleResult = (deleResult && TableFieldInfoDic.GetTableFieldInfoDic().Delete(Convert.ToInt32(listTable[i].Id)));
                                    }
                                }


                                MessageBox.Show(@"删除成功");
                                flag = true;
                            }
                            else
                            {
                                MessageBox.Show(@"删除失败");
                            }
                        }
                        else
                        {
                            return;
                        }
                    }
                }
            }
            if (m == dgvDataBase.Rows.Count && !flag)
            {
                MessageBox.Show(@"请选择要删除的数据库信息");
                m = 0;
            }
            dgvDataBase.Columns.Clear();
            dgvDataBase.DataSource = null;
            DataBaseAddColumns();
            dataGriewDataBaseSource         = DataBaseNameDic.GetDataBaseNameDic().GetAllBaseNames();
            dgvDataBase.DataSource          = dataGriewDataBaseSource;
            dgvDataBase.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            if (dgvDataBase.Rows.Count > 0)
            {
                dgvDataBase.Rows[0].Selected = false;
            }

            BingDataSource();
        }
Ejemplo n.º 8
0
        private void BingDataSource()
        {
            int width = 0;//定义一个局部变量,用于存储自动调整列宽以后整个DtaGridView的宽度

            //数据库信息绑定
            dgvDataBase.Columns.Clear();
            dgvDataBase.DataSource = null;
            DataBaseAddColumns();
            dataGriewDataBaseSource         = DataBaseNameDic.GetDataBaseNameDic().GetAllBaseNames();
            dgvDataBase.DataSource          = dataGriewDataBaseSource;
            dgvDataBase.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            //配置表信息绑定
            gdvConfigTable.Columns.Clear();
            gdvConfigTable.DataSource = null;
            ConfigTableAddColumns();
            dataGriewConfigTableSource         = ConfigTableDic.GetConfigTableDic().SelectList();
            gdvConfigTable.DataSource          = dataGriewConfigTableSource;
            gdvConfigTable.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            for (int i = 0; i < this.gdvConfigTable.Columns.Count; i++)                           //对于DataGridView的每一个列都调整
            {
                this.gdvConfigTable.AutoResizeColumn(i, DataGridViewAutoSizeColumnMode.AllCells); //将每一列都调整为自动适应模式
                width += this.gdvConfigTable.Columns[i].Width;                                    //记录整个DataGridView的宽度
            }
            if (width > this.gdvConfigTable.Size.Width)                                           //判断调整后的宽度与原来设定的宽度的关系,如果是调整后的宽度大于原来设定的宽度,则将DataGridView的列自动调整模式设置为显示的列即可,如果是小于原来设定的宽度,将模式改为填充。
            {
                this.gdvConfigTable.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
            }
            else
            {
                this.gdvConfigTable.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            }


            //数据表信息配置
            dgvDataTableInfo.Columns.Clear();
            dgvDataTableInfo.DataSource = null;
            DataTablesAddColumns();
            dataGriewDataTableSource             = TableFieldInfoDic.GetTableFieldInfoDic().GetAllTableFieldInfos();
            dgvDataTableInfo.DataSource          = dataGriewDataTableSource;
            dgvDataTableInfo.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            width = 0;
            for (int i = 0; i < this.dgvDataTableInfo.Columns.Count; i++)                           //对于DataGridView的每一个列都调整
            {
                this.dgvDataTableInfo.AutoResizeColumn(i, DataGridViewAutoSizeColumnMode.AllCells); //将每一列都调整为自动适应模式
                width += this.dgvDataTableInfo.Columns[i].Width;                                    //记录整个DataGridView的宽度
            }
            if (width > this.dgvDataTableInfo.Size.Width)                                           //判断调整后的宽度与原来设定的宽度的关系,如果是调整后的宽度大于原来设定的宽度,则将DataGridView的列自动调整模式设置为显示的列即可,如果是小于原来设定的宽度,将模式改为填充。
            {
                this.dgvDataTableInfo.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
            }
            else
            {
                this.dgvDataTableInfo.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            }
            if (dgvDataBase.Rows.Count > 0)
            {
                dgvDataBase.Rows[0].Selected = false;
            }
        }
Ejemplo n.º 9
0
        private void finishButton_Click(object sender, EventArgs e)
        {
            //保存安全监测监测因素和数据过滤方式到DataFilter表
            string filDec           = filDateComboBox.Text;
            string safeType         = cmbSafeFactor.Text;
            int    safeId           = 0;
            int    dataFilterTypeId = 0;
            int    dataBaseId       = 0;

            for (int i = 0; i < filterList.Count; i++)
            {
                if (filDec == filterList[i].FilterDesc)
                {
                    dataFilterTypeId = Convert.ToInt32(filterList[i].ID);
                    break;
                }
            }
            foreach (IDandName idname in IdName)
            {
                if (idname.Name == safeType)
                {
                    safeId = idname.ID;
                    break;
                }
            }

            List <DataBaseName> list = DataBaseNameDic.GetDataBaseNameDic().GetAllBaseNames();

            foreach (DataBaseName name in list)
            {
                if (DBLocation == name.Location)
                {
                    dataBaseId = Convert.ToInt32(name.ID);
                    break;
                }
            }

            using (DbConnection conn = new DbConnection())
            {
                DataFilter v = new DataFilter()
                {
                    SafetyFactorType = safeId,
                    FilterType       = dataFilterTypeId,
                    DataBaseId       = dataBaseId
                };
                if (v.FilterType != 0 && v.SafetyFactorType != 0)
                {
                    int[] id = DataFilterDic.GetDataFilterDic().GetSafetyfactortypes();
                    if (!id.Contains(v.SafetyFactorType))
                    {
                        if (DataFilterDic.GetDataFilterDic().Add(v))
                        {
                            MessageBox.Show(@"添加完成");
                        }
                    }
                    else
                    {
                        MessageBox.Show(@"已存在");
                    }
                }
            }

            DialogResult result = MessageBox.Show(@"是否继续配置", @"提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                tabControl1.SelectTab(0);
                DisableTab3();
                EnableTab1();
                nextButton.Enabled = false;
            }
            else
            {
                DisableTab3();
                closeF();
                this.Close();
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 提取统一采集软件数据
        /// </summary>
        private void ExtractFSDB()
        {
            try
            {
                if (!string.IsNullOrEmpty(DataBaseNameDic.GetDataBaseNameDic().GetFSUSBaseName().DataBaseCode))
                {
                    var bll = new SelectFSUSDBTablesBll();

                    DataBaseName dataBase = DataBaseNameDic.GetDataBaseNameDic().GetFSUSBaseName();
                    DataSet      ds       = bll.Select(dataBase);
                    foreach (DataTable dt in ds.Tables)
                    {
                        try
                        {
                            if (this.messagesShowEventHandler != null)
                            {
                                var msg = new StringBuilder();
                                msg.Append("提取").Append(dt.TableName).Append(dt.Rows.Count).Append("条数据");
                                log.Info(msg.ToString());
                                this.messagesShowEventHandler(
                                    this,
                                    new MessagesShowEventArgs
                                {
                                    MessageType  = MsgType.Info,
                                    MessagesShow = msg.ToString()
                                });
                            }
                            List <Data> list = new List <Data>();
                            if (dt != null && dt.Rows.Count > 0)
                            {
                                log.Info("进入提取数据表");
                                foreach (DataRow row in dt.Rows)
                                {
                                    DateTime collectTime;
                                    ValueHelper.String2Time(row[5].ToString().Trim(), out collectTime);
                                    Data data = new Data
                                    {
                                        ProjectCode = Convert.ToInt16(row[0].ToString().Trim()),
                                        DataBaseId  = Convert.ToInt32(row[1].ToString().Trim()),
                                        SensorId    = Convert.ToInt32(row[2].ToString().Trim()),
                                        MoudleNo    = row[3].ToString().Trim(),
                                        ChannelId   = Convert.ToInt32(row[4].ToString().Trim()),
                                        CollectTime = collectTime,
                                        SafeTypeId  = Convert.ToInt32(row[6].ToString().Trim())
                                    };
                                    data.DataSet = new List <double>();
                                    for (int i = 7; i < row.ItemArray.Length; i++)
                                    {
                                        if (row[i] != DBNull.Value && !string.IsNullOrEmpty(row[i].ToString().Trim()))
                                        {
                                            double value;
                                            double.TryParse(row[i].ToString().Trim(), out value);
                                            data.DataSet.Add(value);
                                        }
                                        else
                                        {
                                            data.DataSet.Add(0);
                                        }
                                    }
                                    list.Add(data);
                                }
                                string timestr = dt.Compute("Max(ACQUISITION_DATETIME)", Boolean.TrueString).ToString();
                                ExtractionConfigDic.GetExtractionConfigDic()
                                .UpdateExtractionConfig(
                                    new ExtractionConfig
                                {
                                    DataBaseId = (int)dataBase.ID,
                                    TableName  = dt.TableName,
                                    Acqtime    = timestr
                                });
                                log.Info("提取数据表结束");
                            }
                            //添加到队列
                            foreach (Data data in list)
                            {
                                datasTobesent.Enqueue(data);
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Error(ex.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
            }
        }