Beispiel #1
0
        /// <summary>
        /// 编辑分页脚本
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="e">事件参数</param>
        private void bEditScript_Click(object sender, EventArgs e)
        {
            Node   currentNode = guideTree.SelectedNode;
            string id          = currentNode.Tag as string;
            string scriptText  = "";

            SqlCommand cmd;
            string     sqlString;

            byte[] buffer;

            try
            {
                OpenConnection();

                cmd       = conn.CreateCommand();
                sqlString = string.Format("SELECT Script FROM {0} WHERE ID = {1}",
                                          tabTableName, id);
                cmd.CommandText = sqlString;
                object executeResult = cmd.ExecuteScalar();

                if (executeResult != null && !(executeResult is DBNull))
                {
                    buffer     = executeResult as byte[];
                    scriptText = Encoding.Unicode.GetString(buffer);
                }
            }
            catch (SqlException ex)
            {
                PrintExceptionMessage(ex);
            }
            finally
            {
                CloseConnection();
            }

            ScriptEditForm scriptEditForm = new ScriptEditForm(scriptText);

            if (scriptEditForm.ShowDialog() == DialogResult.OK)
            {
                scriptText = scriptEditForm.ScriptText;
                buffer     = Encoding.Unicode.GetBytes(scriptText);

                try
                {
                    OpenConnection();

                    cmd = conn.CreateCommand();
                    SqlParameter sqlParameter = new SqlParameter("@data", buffer);
                    cmd.Parameters.Add(sqlParameter);
                    sqlString = string.Format("UPDATE {0} SET Script = @data WHERE ID = {1}",
                                              tabTableName, id);
                    cmd.CommandText = sqlString;
                    cmd.ExecuteScalar();
                }
                catch (SqlException ex)
                {
                    PrintExceptionMessage(ex);
                }
                finally
                {
                    CloseConnection();
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// 编辑分页脚本
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="e">事件参数</param>
        private void bEditScript_Click(object sender, EventArgs e)
        {
            Node currentNode = guideTree.SelectedNode;
            string id = currentNode.Tag as string;
            string scriptText = "";

            SqlCommand cmd;
            string sqlString;
            byte[] buffer;

            try
            {
                OpenConnection();

                cmd = conn.CreateCommand();
                sqlString = string.Format("SELECT Script FROM {0} WHERE ID = {1}",
                                          tabTableName, id);                
                cmd.CommandText = sqlString;
                object executeResult = cmd.ExecuteScalar();

                if (executeResult != null && !(executeResult is DBNull))
                {
                    buffer = executeResult as byte[];
                    scriptText = Encoding.Unicode.GetString(buffer);
                }
            }
            catch (SqlException ex)
            {
                PrintExceptionMessage(ex);
            }
            finally
            {
                CloseConnection();
            }

            ScriptEditForm scriptEditForm = new ScriptEditForm(scriptText);

            if (scriptEditForm.ShowDialog() == DialogResult.OK)
            {
                scriptText = scriptEditForm.ScriptText;
                buffer = Encoding.Unicode.GetBytes(scriptText);

                try
                {
                    OpenConnection();

                    cmd = conn.CreateCommand();
                    SqlParameter sqlParameter = new SqlParameter("@data", buffer);
                    cmd.Parameters.Add(sqlParameter);
                    sqlString = string.Format("UPDATE {0} SET Script = @data WHERE ID = {1}",
                                              tabTableName, id);
                    cmd.CommandText = sqlString;
                    cmd.ExecuteScalar();
                }
                catch(SqlException ex)
                {
                    PrintExceptionMessage(ex);
                }
                finally
                {
                    CloseConnection();
                }
            }
        }