Exemple #1
0
        /// <summary>
        /// 保存脚本到数据库
        /// </summary>
        /// <param name="fieldid"></param>
        /// <param name="tabid"></param>
        /// <param name="strcode"></param>
        /// <returns></returns>
        public static bool SaveScriptByID(string strTableName, string fieldid, string tabid, string strcode)
        {
            if (m_conn == null)
            {
                return(false);
            }
            //先看看是否存在记录再说
            SqlDb sqlDB = new SqlDb();

            sqlDB.SetConnection(m_conn);
            string sql = string.Format("select count(*) as c from sys_scriptstore where fieldid={0} and modtabid={1}", fieldid, tabid);

            /* remoting
             * DataSet ds = sqlDB.ExeSqlDs(sql, "sys_scriptstore");
             */

            //DataSet ds = new DataSet();
            DataTable tbl_script = Helper.GetDataTableWithSqlProxy("sys_scriptstore", sql, m_conn);

            //ds.Tables.Add(tbl_script);

            if (tbl_script.Rows[0]["c"].ToString() == "0")
            {
                //添加记录一条
                string table_name = "";
                string field_name = "";
                if (fieldid == "0" || fieldid == "-1") // -1 表示所有tab页总的lua代码
                {
                    sql = string.Format("select tablename from sys_modl_tab_def where modtabid='{0}'", tabid);

                    /* remoting
                     * DataRowCollection drc = sqlDB.ExeSqlDs(sql, "test").Tables[0].Rows;
                     */

                    DataRowCollection drc = Helper.GetDataTableWithSqlProxy("sys_modl_tab_def", sql, m_conn).Rows;
                    if (drc.Count == 0)
                    {
                        return(false);
                    }
                    table_name = drc[0]["tablename"].ToString();
                    field_name = "#";
                }
                else
                {
                    sql = string.Format("select rtrim(tablename) as table_name, rtrim(fieldname) as field_name from sys_meta_info where fieldid={0}", fieldid);

                    /* remoting
                     * DataRowCollection drc = sqlDB.ExeSqlDs(sql, "test").Tables[0].Rows;
                     */

                    DataRowCollection drc = Helper.GetDataTableWithSqlProxy("sys_modl_tab_def", sql, m_conn).Rows;


                    if (drc.Count == 0)
                    {
                        return(false);
                    }
                    table_name = strTableName;// drc[0]["table_name"].ToString();
                    field_name = drc[0]["field_name"].ToString();
                }
                sql = @"insert into sys_scriptstore(fieldid, modtabid, tablename, fieldname, scriptlanguage)
                        values ('{0}','{1}','{2}','{3}','LUA')";
                sql = string.Format(sql, fieldid, tabid, table_name, field_name);
                //int ret = sqlDB.ExeNoQuery(sql);
                int ret = Helper.ExecuteCommand("sys_scriptstore", sql, m_conn);
                if (ret == -1)
                {
                    return(false);
                }
            }

            /* remoting
             * Byte[] ab = Encoding.UTF8.GetBytes(strcode);
             * sql = string.Format("update sys_scriptstore set scriptcode=(@strcode) where fieldid={0} and modtabid={1}", fieldid, tabid);
             * SqlCommand cmd = new SqlCommand(sql, sqlDB.getConn());
             * SqlParameter spcode = new SqlParameter("@strcode", ab);
             * cmd.Parameters.Add(spcode);
             * cmd.Connection.Open();
             * int t = cmd.ExecuteNonQuery();
             */
            Byte[]    ab     = Encoding.UTF8.GetBytes(strcode);
            string    filter = string.Format("fieldid={0} and modtabid={1}", fieldid, tabid);
            DataTable tbl    = Helper.GetDataTableProxy("sys_scriptstore", filter, null, m_conn);
            int       t      = 0;

            foreach (DataRow row in tbl.Rows)
            {
                row["scriptcode"] = ab;
                t++;
            }
            string sql_script = string.Format("select * from sys_scriptstore where {0}", filter);

            Helper.SaveTable(tbl, sql_script, m_conn);
            //cmd.Connection.Close();
            if (t == -1)               //成功的时候,是2
            {
                return(false);
            }
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// 保存脚本到数据库
        /// </summary>
        /// <param name="fieldid"></param>
        /// <param name="tabid"></param>
        /// <param name="strcode"></param>
        /// <returns></returns>
        public static bool SaveScriptByID(string strTableName, string fieldid, string tabid, string strcode)
        {
            if ( m_conn == null )
            {
                return false;
            }
            //先看看是否存在记录再说
            SqlDb sqlDB = new SqlDb();
            sqlDB.SetConnection(m_conn);
            string sql = string.Format("select count(*) as c from sys_scriptstore where fieldid={0} and modtabid={1}", fieldid, tabid);
            
            /* remoting
            DataSet ds = sqlDB.ExeSqlDs(sql, "sys_scriptstore");
            */

            //DataSet ds = new DataSet();
            DataTable tbl_script = Helper.GetDataTableWithSqlProxy("sys_scriptstore", sql, m_conn);
            //ds.Tables.Add(tbl_script);

            if (tbl_script.Rows[0]["c"].ToString() == "0")
            {
                //添加记录一条
                string table_name = "";
                string field_name = "";
                if (fieldid == "0" || fieldid == "-1") // -1 表示所有tab页总的lua代码
                {
                    
                    sql = string.Format("select tablename from sys_modl_tab_def where modtabid='{0}'", tabid);
                    /* remoting
                    DataRowCollection drc = sqlDB.ExeSqlDs(sql, "test").Tables[0].Rows;
                     */

                    DataRowCollection drc = Helper.GetDataTableWithSqlProxy("sys_modl_tab_def", sql, m_conn).Rows;
                    if (drc.Count == 0) return false;
                    table_name = drc[0]["tablename"].ToString();
                    field_name = "#";
                }
                else
                {
                    sql = string.Format("select rtrim(tablename) as table_name, rtrim(fieldname) as field_name from sys_meta_info where fieldid={0}", fieldid);
                    
                    /* remoting
                    DataRowCollection drc = sqlDB.ExeSqlDs(sql, "test").Tables[0].Rows;
                    */

                    DataRowCollection drc = Helper.GetDataTableWithSqlProxy("sys_modl_tab_def", sql, m_conn).Rows;
 

                    if (drc.Count == 0) return false;
                    table_name = strTableName;// drc[0]["table_name"].ToString();
                    field_name = drc[0]["field_name"].ToString();
                }
                sql = @"insert into sys_scriptstore(fieldid, modtabid, tablename, fieldname, scriptlanguage)
                        values ('{0}','{1}','{2}','{3}','LUA')";
                sql = string.Format(sql, fieldid, tabid, table_name, field_name);
                //int ret = sqlDB.ExeNoQuery(sql);
                int ret = Helper.ExecuteCommand("sys_scriptstore", sql, m_conn);
                if (ret == -1)
                {
                    return false;
                }
            }
            /* remoting
            Byte[] ab = Encoding.UTF8.GetBytes(strcode);
            sql = string.Format("update sys_scriptstore set scriptcode=(@strcode) where fieldid={0} and modtabid={1}", fieldid, tabid);
            SqlCommand cmd = new SqlCommand(sql, sqlDB.getConn());
            SqlParameter spcode = new SqlParameter("@strcode", ab);
            cmd.Parameters.Add(spcode);
            cmd.Connection.Open();
            int t = cmd.ExecuteNonQuery();
             */
            Byte[] ab = Encoding.UTF8.GetBytes(strcode);
            string filter = string.Format("fieldid={0} and modtabid={1}", fieldid, tabid);
            DataTable tbl = Helper.GetDataTableProxy("sys_scriptstore", filter, null, m_conn);
            int t = 0;
            foreach (DataRow row in tbl.Rows)
            {
                row["scriptcode"] = ab;
                t++;
            }
            string sql_script = string.Format("select * from sys_scriptstore where {0}", filter);
            Helper.SaveTable(tbl, sql_script, m_conn);
            //cmd.Connection.Close();
            if (t == -1)               //成功的时候,是2
            {
                return false;
            }
            return true;
        }