예제 #1
0
        /// <summary>
        ///     执行一条sql
        /// </summary>
        /// <param name="tansEntity"></param>
        /// <returns></returns>
        private static TransEntity Execute(TransEntity tansEntity)
        {
            try
            {
                var entity = new TransitEntity();
                entity.ServiceName = "dbcservice";
                entity.FuncName    = "ExecuteNoQuery";
                entity.Parameters  = new Dictionary <string, string>
                {
                    { "1", CommonFunction.ChangArrayToStr(tansEntity.SqlString) },
                    { "2", CommonFunction.ChangArrayToStr(tansEntity.ParString) }
                };
                List <AttachFile> tmpresult = ServiceManager.GetInstance().Commit(entity);
                if (tmpresult != null && tmpresult.Count == 1)
                {
                    var result = (string)tmpresult.ToArray()[0].AttachValue;
                    tansEntity.ReceiveData = new ReceiveData {
                        ExcuteIsComplete = result == "true" ? true : false
                    };
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString().Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)[0]);
            }

            return(tansEntity);
        }
예제 #2
0
        /// <summary>
        ///     执行多条SQL事务处理
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public static bool TryExecute(string[] sql, params string[][] param)
        {
            var te = new TransEntity();

            te.AddOperation(sql, param);

            Execute(te);

            return(te.ReceiveData == null ? false : te.ReceiveData.ExcuteIsComplete);
        }
예제 #3
0
        /// <summary>
        ///     SQL数据查询
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public static List <T> TryGetData <T>(string sql, params string[] param) where T : IEntity, new()
        {
            var te = new TransEntity();

            te.AddOperation(sql, param);

            GetData(te);

            if (te.ReceiveData == null || !te.ReceiveData.ExcuteIsComplete)
            {
                return(null);
            }

            return(CommonFunction.ChangeTableToEntitys <T>(te.ReceiveData.DataTables));
        }
예제 #4
0
        /// <summary>
        ///     获得服务器端时间
        /// </summary>
        /// <returns></returns>
        public static DateTime GetNowDateTime()
        {
            var tansEntity = new TransEntity();

            tansEntity.AddOperation("SELECT TO_CHAR(SYSDATE,'yyyy-MM-dd HH24:mi:ss') AS DATETIME FROM DUAL", null);
            GetData(tansEntity);
            if (tansEntity.ReceiveData == null)
            {
                return(new DateTime());
            }
            else
            {
                return(DateTime.Parse(tansEntity.ReceiveData.DataTables.Rows[0]["DATETIME"].ToString()));
            }
        }
예제 #5
0
        /// <summary>
        ///     执行SQL语句 返回单独数据
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public static object TryGetSingleData(string sql, params string[] param)
        {
            var te = new TransEntity();

            te.AddOperation(sql, param);

            GetData(te);

            if (te.ReceiveData == null || !te.ReceiveData.ExcuteIsComplete)
            {
                return(null);
            }

            else if (te.ReceiveData.DataTables.Rows.Count != 1)
            {
                return(null);
            }

            return(te.ReceiveData.DataTables.Rows[0][0]);
        }
예제 #6
0
        /// <summary>
        ///     SQL数据查询
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public static DataTable TryGetData(string sql, params string[] param)
        {
            try
            {
                var te = new TransEntity();

                te.AddOperation(sql, param);

                GetData(te);

                if (te.ReceiveData == null || !te.ReceiveData.ExcuteIsComplete)
                {
                    return(null);
                }

                return(te.ReceiveData.DataTables);
            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #7
0
        /// <summary>
        ///     从服务端获得数据
        /// </summary>
        /// <returns></returns>
        private static TransEntity GetData(TransEntity transEntity)
        {
            try
            {
                // 服务端暂时只支持一次一个查询sql,所以要转换回来到这个格式
                string[] s      = transEntity.ParString[0].Split(';');
                var      entity = new TransitEntity();
                entity.ServiceName = "dbcservice";
                entity.FuncName    = "ExecuteWithResult";
                entity.Parameters  = new Dictionary <string, string>
                {
                    { "1", CommonFunction.ChangArrayToStr(transEntity.SqlString) },
                    { "2", CommonFunction.ChangArrayToStr(s) }
                };
                List <AttachFile> tmpresult = ServiceManager.GetInstance().Commit(entity);
                if (tmpresult != null && tmpresult.Count == 1)
                {
                    transEntity.ReceiveData                  = new ReceiveData();
                    transEntity.ReceiveData.DataTables       = (DataTable)tmpresult.ToArray()[0].AttachValue;
                    transEntity.ReceiveData.ExcuteIsComplete = true;

                    // 特殊处理,给返回表格增加列明,如果能分析出来的话
                    try
                    {
                        string sql = transEntity.SqlString[0].ToUpper().Trim();
                        if (sql.StartsWith("SELECT"))
                        {
                            sql = sql.Replace("SELECT", "");
                            string[] c = sql.Split(new[] { "FROM" }, StringSplitOptions.RemoveEmptyEntries);
                            string   d = c[0].Trim();
                            c = d.Split(',');

                            if (transEntity.ReceiveData.DataTables.Columns.Count == 0)
                            {
                                foreach (string item in c)
                                {
                                    //for (int i = 0; i < c.Length; i++)
                                    string[] f = item.Trim().Split(' ');
                                    if (!InChar(f[f.Length - 1]))
                                    {
                                        transEntity.ReceiveData.DataTables.Columns.Add();
                                    }
                                }
                            }

                            int n = 0;
                            foreach (string item in c)
                            //for (int i = 0; i < c.Length; i++)
                            {
                                string[] f = item.Trim().Split(' ');
                                if (!InChar(f[f.Length - 1]))
                                {
                                    transEntity.ReceiveData.DataTables.Columns[n].ColumnName = f[f.Length - 1];
                                    n++;
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.ToString().Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                    }
                }
            }
            catch (Exception)
            {
                //MessageBox.Show(e.ToString().Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                throw;
            }

            return(transEntity);
        }
예제 #8
0
        /// <summary>
        ///     重服务器获取数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="transEntity"></param>
        /// <returns></returns>
        public T GetSingleData <T>(TransEntity transEntity)
        {
            DataTable table = GetData(transEntity).ReceiveData == null ? new DataTable() : GetData(transEntity).ReceiveData.DataTables;

            return((T)table.Rows[0][0]);
        }