Пример #1
0
        void AnalyticData(SendMessage data)
        {
            int  syncCount = 0;
            bool IsMatch   = false;

            //MachineCodes item = ServerConfiguration.Instance.Details.Where(a => a.UpLoadIdentifer == data.UpLoadIdentifier).FirstOrDefault();
            foreach (MachineCodes item in ServerConfiguration.Instance.Details.Where(a => a.UpLoadIdentifer == data.UpLoadIdentifier))
            {
                if (data.UpLoadIdentifier == item.UpLoadIdentifer)
                {
                    IsMatch = true;
                    // 未设置主键名则跳过
                    if (string.IsNullOrEmpty(item.PrimarKeys))
                    {
                        grabPerformer_OutputInfo(string.Format("{0} 提取未执行,原因:未设置主键(PrimaryKeys)参数", item.UpLoadIdentifer));
                        break;
                    }

                    OracleDapperDber selfDber = new OracleDapperDber(ServerConfiguration.Instance.SelfConnStr);
                    using (OracleConnection connection = selfDber.CreateConnection() as OracleConnection)
                    {
                        if (data.DataColumns != null)
                        {
                            // 在数据中创建表
                            if (connection.ExecuteScalar <int>(CMCS.CommonADGS.Core.OracleSqlBuilder.BuildHasTableSQL(item.DataTableName)) == 0)
                            {
                                connection.Execute(CMCS.CommonADGS.Core.OracleSqlBuilder.BuildTableSQL(item.DataTableName, data.DataColumns));
                            }
                        }
                        else if (data.DataRows != null)
                        {
                            string execSql = string.Empty;

                            // 生成主键值
                            string primaryKeyValue = item.UpLoadIdentifer + "-" + CMCS.CommonADGS.Core.OracleSqlBuilder.BuildPrimaryKeyValue(item.PrimarKeys, data.DataRows);

                            if (connection.ExecuteScalar <int>(CMCS.CommonADGS.Core.OracleSqlBuilder.BuildHasRecordSQL(item.DataTableName, primaryKeyValue)) == 0)
                            {
                                execSql = CMCS.CommonADGS.Core.OracleSqlBuilder.BuildInsertSQL(item.DataTableName, primaryKeyValue, item.UpLoadIdentifer, data.DataRows);
                            }
                            else
                            {
                                execSql = CMCS.CommonADGS.Core.OracleSqlBuilder.BuildUpdateSQL(item.DataTableName, primaryKeyValue, item.UpLoadIdentifer, data.DataRows);
                            }

                            syncCount += connection.Execute(execSql);
                        }
                    }
                }
            }
            if (!IsMatch)
            {
                grabPerformer_OutputInfo(string.Format("接收到:{0}数据,但未找到对应配置", data.UpLoadIdentifier));
            }
            if (syncCount > 0)
            {
                grabPerformer_OutputInfo(string.Format("成功接收:{0}一条数据", data.UpLoadIdentifier));
            }
        }
Пример #2
0
        /// <summary>
        /// 提取数据
        /// </summary>
        private void Grab()
        {
            OracleDapperDber selfDber = new OracleDapperDber(this._ADGSAppConfig.SelfConnStr);

            using (OracleConnection connection = selfDber.CreateConnection() as OracleConnection)
            {
                foreach (AssayGraber assayGraber in this._ADGSAppConfig.AssayGrabers)
                {
                    try
                    {
                        if (!assayGraber.Enabled)
                        {
                            continue;
                        }
                        // 未设置主键名则跳过
                        if (string.IsNullOrEmpty(assayGraber.PrimaryKeys))
                        {
                            OutputInfoMethod(string.Format("{0} 提取未执行,原因:未设置主键(PrimaryKeys)参数", assayGraber.MachineCode));
                            continue;
                        }

                        DataTable dtlAssay = assayGraber.ExecuteGrab();

                        // 在数据中创建表
                        if (connection.ExecuteScalar <int>(OracleSqlBuilder.BuildHasTableSQL(assayGraber.TableName)) == 0)
                        {
                            connection.Execute(OracleSqlBuilder.BuildTableSQL(assayGraber.TableName, dtlAssay));
                        }

                        int syncCount = 0;
                        foreach (DataRow drAssay in dtlAssay.Rows)
                        {
                            string execSql = string.Empty;

                            // 生成主键值
                            string primaryKeyValue = assayGraber.MachineCode + "-" + OracleSqlBuilder.BuildPrimaryKeyValue(assayGraber.PrimaryKeys, drAssay);

                            if (connection.ExecuteScalar <int>(OracleSqlBuilder.BuildHasRecordSQL(assayGraber.TableName, primaryKeyValue)) == 0)
                            {
                                execSql = OracleSqlBuilder.BuildInsertSQL(assayGraber.TableName, primaryKeyValue, assayGraber.MachineCode, drAssay);
                            }
                            else
                            {
                                execSql = OracleSqlBuilder.BuildUpdateSQL(assayGraber.TableName, primaryKeyValue, assayGraber.MachineCode, drAssay);
                            }

                            syncCount += connection.Execute(execSql);
                        }

                        OutputInfoMethod(string.Format("{0} 本次提取 {1} 条", assayGraber.MachineCode, syncCount));
                    }
                    catch (Exception ex)
                    {
                        OutputErrorMethod(string.Format("{0} 提取失败", assayGraber.MachineCode), ex);
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// 测试数据库连接
        /// </summary>
        /// <returns></returns>
        private bool TestDBConnect()
        {
            if (string.IsNullOrEmpty(txtSelfConnStr.Text.Trim()))
            {
                MessageBoxEx.Show("请先输入数据库连接字符串", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }
            try
            {
                OracleDapperDber dber = new OracleDapperDber(txtSelfConnStr.Text.Trim());
                dber.CreateConnection().Open();
                dber.CreateConnection().Close();

                return(true);
            }
            catch (Exception ex)
            {
                MessageBoxEx.Show("数据库连接失败," + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }
        }
Пример #4
0
        /// <summary>
        /// ²âÊÔÊý¾Ý¿âÁ¬½Ó
        /// </summary>
        /// <returns></returns>
        private bool TestDBConnect()
        {
            if (string.IsNullOrEmpty(txtSelfConnStr.Text.Trim()))
            {
                MessageBoxEx.Show("ÇëÏÈÊäÈëÊý¾Ý¿âÁ¬½Ó×Ö·û´®", "²Ù×÷Ìáʾ", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }
            try
            {
                OracleDapperDber dber = new OracleDapperDber(txtSelfConnStr.Text.Trim());
                using (OracleConnection conn = dber.CreateConnection() as OracleConnection)
                {
                    conn.Open();
                }

                return(true);
            }
            catch (Exception ex)
            {
                MessageBoxEx.Show("Êý¾Ý¿âÁ¬½Óʧ°Ü£¬" + ex.Message, "²Ù×÷Ìáʾ", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }
        }