Exemplo n.º 1
0
        //static DBCenter()
        //{
        //    //需要在非web应用上使用,避免报错影响初始化
        //    try
        //    {
        //        //根据类型,初始化不同的辅助类,和读取连接字符串
        //        string dbtype = ConfigurationManager.AppSettings["DBType"];
        //        if (string.IsNullOrEmpty(dbtype)) { dbtype = "mssql"; }
        //        DB = SqlBase.CreateHelper(dbtype);
        //        switch (dbtype)//为多数据库读取
        //        {
        //            case "oracle":
        //                DB.ConnectionString = ConfigurationManager.ConnectionStrings["OraConnection String"].ConnectionString;
        //                break;
        //            default:
        //                DB.ConnectionString = ConfigurationManager.ConnectionStrings["Connection String"].ConnectionString;
        //                break;
        //        }
        //    }
        //    catch { }
        //}
        #region 兼容区
        /// <summary>
        /// 依据ID和主键删除
        /// </summary>
        public static bool Del(string tbname, string pk, int id)
        {
            SqlModel model = new SqlModel()
            {
                cmd = SqlCmd.Delete, tbName = tbname,
            };

            model.where = "" + pk + "=" + id;
            DB.ExecuteNonQuery(model);
            return(true);
        }
Exemplo n.º 2
0
        private void btn_ok_Click(object sender, EventArgs e)
        {
            string tabName = "";
            string sqlStr  = "";

            if (string.IsNullOrEmpty(this.txt_tableName.Text))
            {
                //同步所有的zdzdbiao
                sqlStr = $"  select name from sysobjects where xtype='u'  and name like 'ZDZD_%'";
            }
            else
            {
                //指定的表
                tabName = this.txt_tableName.Text;
                sqlStr  = $" select name from sysobjects where xtype='u'  and name = 'ZDZD_{tabName}'";
            }
            //ZDZD_ZX
            SqlBase _sqlBase   = new SqlBase(ESqlConnType.ConnectionStringJCJT);
            SqlBase _DebugTool = new SqlBase(ESqlConnType.ConnectionStringDebugTool);
            SqlBase ngJCJG     = new SqlBase(ESqlConnType.ConnectionStringJCJG);

            //string sqlStr = string.Format($"SELECT 表名 = D.name,字段序号 = A.colorder,字段名 = A.name,字段说明 = isnull(G.[value], ''),类型 = B.name,占用字节数 = A.Length " +
            //   $"FROM syscolumns A  Left Join systypes B On A.xusertype = B.xusertype Inner Join sysobjects D On A.id = D.id and D.xtype = 'U' and D.name <> 'dtproperties'" +
            //   $" Left Join syscomments E on A.cdefault = E.id Left Join sys.extended_properties G on A.id = G.major_id and A.colid = G.minor_id Left Join sys.extended_properties F On D.id = F.major_id and F.minor_id = 0 " +
            //   $"where d.name = '{tabName}' "
            //   + wheresql +
            //   $"  Order By A.id, A.colorder");

            var dtTableName = _sqlBase.ExecuteDataset(sqlStr);

            if (dtTableName.Tables.Count == 0)
            {
                return;
            }
            var dt = dtTableName.Tables[0];

            var     sql    = "";
            var     syxmbh = "";
            DataSet ds     = null;

            foreach (DataRow item in dt.Rows)
            {
                syxmbh = item["name"].ToString().ToUpper().Replace("ZDZD_", "");
                ds     = _DebugTool.ExecuteDataset($" select name from sysobjects where xtype='u'  and name = 'ZDZD_{syxmbh}'");
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    //如果已经同步过,则执行下一个
                    //MessageBox.Show($"项目{syxmbh}已经同步");
                    continue;
                }
                sql = $"select * into ZDZD_{syxmbh} from jcjt_wh.dbo.ZDZD_{syxmbh} where sjbmc like 'S_{syxmbh}' or sjbmc like 'M_{syxmbh}'";
                //sql = $"select * into ZDZD_{syxmbh} from ITSV.jcjt_wh.dbo.ZDZD_{syxmbh} where sjbmc like 'S_{syxmbh}' or sjbmc like 'M_{syxmbh}'";
                //sql = $"alter table zdzd_{syxmbh} drop column sj_zs";
                try
                {
                    _sqlBase.ExecuteNonQuery(sql);
                }
                catch
                { }
            }
            //select* from ITSV.jcjt_wh.dbo.ZDZD_ZX where sjbmc like 'S_%' or sjbmc like 'M_%'
        }