Exemplo n.º 1
0
        /// <summary>
        /// 通过SQL命令获取表
        /// </summary>
        /// <param name="weburl">WEB地址</param>
        /// <param name="sqlcmd">SQL命令</param>
        /// <param name="dbindex">数据库索引</param>
        /// <returns>成功返回表</returns>
        public static DataTable GetDataTableBySqlCommand(string weburl, string sqlcmd, int dbindex)
        {
            DataTable dt = null;

            try
            {
                CIPS.Dictionary.WebDict.Service web;
                web = new CIPS.Dictionary.WebDict.Service(weburl);
                byte[]          b         = web.GetDataTableBySqlCommand(sqlcmd, dbindex);
                BinaryFormatter formatter = new BinaryFormatter();
                MemoryStream    stream    = new MemoryStream(b, 0, b.Length);
                try
                {
                    dt = (DataTable)formatter.Deserialize(stream);
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine(sqlcmd + "反序列化失败" + ex.ToString());
                }
                stream.Close();
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(sqlcmd + "读WEB失败:" + ex.ToString());
            }
            return(dt);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 读表
        /// </summary>
        /// <param name="web">WEB地址</param>
        /// <param name="tablename">表名</param>
        /// <param name="param">参数</param>
        /// <param name="index">数据库</param>
        /// <returns>成功返回表</returns>
        public static DataTable LoadTable(CIPS.Dictionary.WebDict.Service web, string tablename, string param, int index)
        {
            DataTable dt = null;

            try
            {
                web.Timeout = 300000;
                byte[]          b         = web.GetTable(tablename, param, index);
                BinaryFormatter formatter = new BinaryFormatter();
                MemoryStream    stream    = new MemoryStream(b, 0, b.Length);
                try
                {
                    dt = (DataTable)formatter.Deserialize(stream);
                    System.Console.WriteLine(tablename + "读WEB:成功");
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine(tablename + "读WEB:反序列化失败" + ex.ToString());
                }
                stream.Close();
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(tablename + "读WEB失败:" + ex.ToString());
            }
            return(dt);
        }
Exemplo n.º 3
0
 bool LoadFromWeb(List <TableInfo> tables)
 {
     bool[] needload = new bool[3];
     for (int i = 0; i < needload.Length; i++)
     {
         needload[i] = false;
     }
     foreach (TableInfo t in tables)
     {
         if (t.index > 0 && t.index < needload.Length)
         {
             needload[t.index] = true;
         }
     }
     ClTable[] cts = new ClTable[needload.Length];
     CIPS.Dictionary.WebDict.Service web;
     web = new CIPS.Dictionary.WebDict.Service(weburl);
     for (int i = 0; i < cts.Length; i++)
     {
         if (!needload[i])
         {
             continue;
         }
         try
         {
             byte[] buf = web.GetClTable("DM_SA_DC_MODIFY", "", i);
             if (buf != null)
             {
                 cts[i] = new ClTable(buf);
             }
         }
         catch { }
     }
     foreach (TableInfo t in tables)
     {
         t.modified = false;
         //DateTime time = GetLastModifyTime(web, t.tablename, t.index);
         if (t.index == 0)
         {
             continue;
         }
         DateTime time = GetLastModifyTime(cts, t.tablename, t.index);
         if (time > t.lastModifyTime)
         {
             LoadTableFromWeb(web, t);
             if (t.tablename == "DC_NC_TERM")
             {
                 ClTable   ct_test = new ClTable(t.buf);
                 DataTable dt_test = ct_test.GetDataTable();
             }
             if (t.key && t.buf == null)
             {
                 return(false);
             }
         }
     }
     return(true);
     //return Tables2DataSet(tables);
 }
Exemplo n.º 4
0
 static DateTime GetLastModifyTime(CIPS.Dictionary.WebDict.Service web, string tablename, int dbindex)
 {
     try
     {
         return(web.GetLastModifyTime(tablename, dbindex));
     }
     catch { }
     return(new DateTime(1900, 1, 1));
 }
Exemplo n.º 5
0
        /// <summary>
        /// 读表
        /// </summary>
        /// <param name="weburl">WEB地址</param>
        /// <param name="tablename">表名</param>
        /// <param name="param">参数</param>
        /// <param name="index">数据库</param>
        /// <returns>成功返回表</returns>
        public static DataTable LoadTable(string weburl, string tablename, string param, int index)
        {
            DataTable dt = null;

            try
            {
                CIPS.Dictionary.WebDict.Service web;
                web = new CIPS.Dictionary.WebDict.Service(weburl);
                dt  = LoadTable(web, tablename, param, index);
            }
            catch { }
            return(dt);
        }
Exemplo n.º 6
0
 /// <summary>
 /// 执行存Sql命令
 /// </summary>
 /// <param name="weburl">WEB地址</param>
 /// <param name="cmdstr">命令</param>
 /// <param name="dbindex">数据库索引</param>
 /// <returns>成功返回TRUE</returns>
 public static bool ExecuteSqlCommand(string weburl, string cmdstr, int dbindex)
 {
     try
     {
         CIPS.Dictionary.WebDict.Service web;
         web         = new CIPS.Dictionary.WebDict.Service(weburl);
         web.Timeout = 1200000;
         CIPS.Dictionary.WebDict.OleDbParameter[] ps = null;
         return(web.ExecuteSqlCommand(cmdstr, dbindex));
     }
     catch (Exception ex)
     {
         System.Console.WriteLine("执行SQL失败" + ex.ToString());
     }
     return(false);
 }
Exemplo n.º 7
0
 /// <summary>
 /// 以CLTABLE格式读表
 /// </summary>
 /// <param name="web">WEB地址</param>
 /// <param name="tablename">表名</param>
 /// <param name="param">参数</param>
 /// <param name="index">数据库索引</param>
 /// <returns>成功返回CLTABLE格式的表</returns>
 public static CIPS.ClTable LoadClTable(CIPS.Dictionary.WebDict.Service web, string tablename, string param, int index)
 {
     CIPS.ClTable dt = null;
     try
     {
         web.Timeout = 300000;
         byte[] b = web.GetClTable(tablename, param, index);
         dt = new ClTable(b);
         System.Console.WriteLine(tablename + "读WEB:成功(CL)");
     }
     catch (Exception ex)
     {
         System.Console.WriteLine(tablename + "读WEB失败(CL):" + ex.ToString());
     }
     return(dt);
 }
Exemplo n.º 8
0
        /// <summary>
        /// 通过SQL命令获取CLTABLE格式的表
        /// </summary>
        /// <param name="weburl">WEB地址</param>
        /// <param name="sqlcmd">SQL命令</param>
        /// <param name="dbindex">数据库索引</param>
        /// <returns>成功返回表</returns>
        public static CIPS.ClTable GetClTableBySqlCommand(string weburl, string sqlcmd, int dbindex)
        {
            ClTable ct = null;

            try
            {
                CIPS.Dictionary.WebDict.Service web;
                web = new CIPS.Dictionary.WebDict.Service(weburl);
                byte[] b = web.GetClTableBySqlCommand(sqlcmd, dbindex);
                ct = new ClTable(b);
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(sqlcmd + "读WEB失败:" + ex.ToString());
            }
            return(ct);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 更新表
        /// </summary>
        /// <param name="weburl">WEB地址</param>
        /// <param name="dt">表</param>
        /// <param name="index">数据库</param>
        /// <returns>成功返回TRUE</returns>
        public static bool UpdateTable(string weburl, DataTable dt, int index)
        {
            bool ret = false;

            try
            {
                CIPS.Dictionary.WebDict.Service web;
                web = new CIPS.Dictionary.WebDict.Service(weburl);
                BinaryFormatter formatter = new BinaryFormatter();
                MemoryStream    stream    = new MemoryStream();
                formatter.Serialize(stream, dt);
                ret = web.UpdateTable(stream.GetBuffer(), index);
                stream.Close();
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(dt.TableName + "保存表至WEB失败" + ex.ToString());
            }
            return(ret);
        }
Exemplo n.º 10
0
 void LoadTableFromWeb(CIPS.Dictionary.WebDict.Service web, TableInfo table)
 {
     try
     {
         table.modified = false;
         byte[] buf = web.GetClTable(table.tablename, table.param, table.index);
         if (buf != null)
         {
             table.lastModifyTime = DateTime.Now;
             if (!MemCmp(buf, table.buf))
             {
                 table.buf      = buf;
                 table.modified = true;
             }
         }
     }
     catch (Exception ex)
     {
         System.Console.WriteLine(table.tablename + "读WEB失败" + ex.ToString());
     }
 }
Exemplo n.º 11
0
 /// <summary>
 /// 执行存储过程命令
 /// </summary>
 /// <param name="weburl">WEB地址</param>
 /// <param name="cmdstr">命令</param>
 /// <param name="param">执行参数</param>
 /// <param name="dbindex">数据库索引</param>
 /// <returns>成功返回TRUE</returns>
 public static bool ExecuteStoredProcedure(string weburl, string cmdstr, List <CIPS.Dictionary.WebDict.OleDbParameter> param, int dbindex)
 {
     try
     {
         CIPS.Dictionary.WebDict.Service web;
         web         = new CIPS.Dictionary.WebDict.Service(weburl);
         web.Timeout = 1200000;
         CIPS.Dictionary.WebDict.OleDbParameter[] ps = null;
         if (param != null && param.Count > 0)
         {
             ps = new CIPS.Dictionary.WebDict.OleDbParameter[param.Count];
             for (int i = 0; i < ps.Length; i++)
             {
                 ps[i] = param[i];
             }
         }
         return(web.ExecuteStoredProcedure(cmdstr, ps, dbindex));
     }
     catch (Exception ex)
     {
         System.Console.WriteLine("执行SQL失败" + ex.ToString());
     }
     return(false);
 }
Exemplo n.º 12
0
 /// <summary>
 /// 以CLTABLE格式读表
 /// </summary>
 /// <param name="weburl">WEB地址</param>
 /// <param name="tablename">表名</param>
 /// <param name="param">参数</param>
 /// <param name="index">数据库索引</param>
 /// <returns>成功返回CLTABLE格式的表</returns>
 public static CIPS.ClTable LoadClTable(string weburl, string tablename, string param, int index)
 {
     CIPS.Dictionary.WebDict.Service web;
     web = new CIPS.Dictionary.WebDict.Service(weburl);
     return(LoadClTable(web, tablename, param, index));
 }
Exemplo n.º 13
0
        void Init(string[] conditions1, string[] conditions2, string webUrl, Form wnd, string description)
        {
            if (description == null)
            {
                description = "";
            }
            dictPath += description;
            TableInfos.Add(new TableInfo("HostList", 0));
            string[] str;
            str = conditions1;
            TableInfo ti;

            for (int i = 0; i < 2; i++)
            {
                if (str != null)
                {
                    foreach (string s in str)
                    {
                        ti = new TableInfo(s, i + 1);
                        if (ti.tablename != null)
                        {
                            bool found = false;
                            foreach (TableInfo t in TableInfos)
                            {
                                if (t.tablename == ti.tablename)
                                {
                                    found = true;
                                    break;
                                }
                            }
                            if (!found)
                            {
                                TableInfos.Add(ti);
                            }
                        }
                    }
                }
                str = conditions2;
            }
            mForm  = wnd;
            weburl = webUrl;
            bool whole = true;

            if (mForm != null)
            {
                whole = LoadFromFiles(TableInfos);
            }
            else
            {
                whole = false;
            }
            foreach (TableInfo t in TableInfos)
            {
                if (t.tablename == "HostList")
                {
                    CIPS.Dictionary.WebDict.Service web = new CIPS.Dictionary.WebDict.Service(weburl);
                    LoadTableFromWeb(web, t);
                    if (t.modified)
                    {
                        _Save2File(t);
                        t.modified = false;
                    }
                    if (t.buf == null)
                    {
                        List <TableInfo> ifs = new List <TableInfo>();
                        ifs.Add(t);
                        LoadFromFiles(ifs);
                    }
                }
            }

            if (!whole)
            {
                whole = LoadFromWeb(TableInfos);
                foreach (TableInfo t in TableInfos)
                {
                    if (t.buf != null)
                    {
                        byte[] b = LoadTableFromFile(t.tablename);
                        if (!MemCmp(b, t.buf))
                        {
                            _Save2File(t);
                        }
                    }
                }

                //if (whole)
                //    Save2File(TableInfos);
            }
            if (mForm == null && !whole)
            {
                LoadFromFiles(TableInfos);
            }
            //if (dsDict != null)
            //    CheckFromWeb(Tables);
        }