⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 customform.cs

📁 最好用的站点内容管理系统 全部源代码都有
💻 CS
📖 第 1 页 / 共 3 页
字号:
//======================================================
//==     (c)2008 aspxcms inc by NeTCMS v1.0              ==
//==          Forum:bbs.aspxcms.com                   ==
//==         Website:www.aspxcms.com                  ==
//======================================================
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using NetCMS.Model;
using NetCMS.Config;
using NetCMS.DALProfile;
using NetCMS.DALFactory;

namespace NetCMS.DALSQLServer
{
    public class CustomForm : DbBase, ICustomForm
    {
        void ICustomForm.Edit(CustomFormInfo info)
        {
            SqlConnection cn = new SqlConnection(DBConfig.CmsConString);
            cn.Open();
            SqlTransaction tran = cn.BeginTransaction();
            try
            {
                if (info.id > 0)
                {
                    #region 修改
                    string Sql = "update " + Pre + "customform set formname=@formname,accessorypath=@accessorypath,accessorysize=@accessorysize,";
                    Sql += "memo=@memo,islock=@islock,timelimited=@timelimited,starttime=@starttime,endtime=@endtime,";
                    Sql += "showvalidatecode=@showvalidatecode,submitonce=@submitonce,isdelpoint=@isdelpoint,gpoint=@gpoint,ipoint=@ipoint,";
                    Sql += "groupnumber=@groupnumber where id=" + info.id;
                    DbHelper.ExecuteNonQuery(tran, CommandType.Text, Sql, GetEditParams(info));
                    #endregion
                }
                else
                {
                    #region 新增
                    string tab = info.formtablename;
                    if (tab.IndexOf("'") >= 0)
                        tab.Replace("'", "''");
                    string Sql = "IF EXISTS (SELECT * FROM sysobjects WHERE id = object_id(N'[" + tab + "]') AND ";
                    Sql += "OBJECTPROPERTY(id, N'IsUserTable') = 1) SELECT 1 ELSE SELECT 0";
                    object obj = DbHelper.ExecuteScalar(tran, CommandType.Text, Sql, null);
                    if (obj != null && obj != DBNull.Value)
                    {
                        if (obj.ToString() == "1")
                        {
                            throw new Exception("该用户表名已经存在!");
                        }
                    }
                    else
                    {
                        throw new Exception("该用户表名已经存在(null)!");
                    }
                    Sql = "insert into " + Pre + "customform (formname,formtablename,accessorypath,accessorysize,memo,islock,timelimited,";
                    Sql += "starttime,endtime,showvalidatecode,submitonce,isdelpoint,gpoint,ipoint,groupnumber,addtime) values (";
                    Sql += "@formname,@formtablename,@accessorypath,@accessorysize,@memo,@islock,@timelimited,";
                    Sql += "@starttime,@endtime,@showvalidatecode,@submitonce,@isdelpoint,@gpoint,@ipoint,@groupnumber,'" + DateTime.Now + "')";
                    DbHelper.ExecuteNonQuery(tran, CommandType.Text, Sql, GetEditParams(info));
                    Sql = "CREATE TABLE [" + tab + "] ([id] [int] IDENTITY (1, 1) NOT NULL ,";
                    Sql += " [usernum] [nvarchar] (50) NULL ,";
                    Sql += " [username] [nvarchar] (50) NULL ,";
                    Sql += " [submit_ip] [nvarchar] (15) NULL ,";
                    Sql += " [submit_time] [datetime] NULL ,";
                    Sql += ")ON [PRIMARY]";
                    DbHelper.ExecuteNonQuery(tran, CommandType.Text, Sql, null);
                    #endregion
                }
                tran.Commit();
            }
            catch
            {
                try
                {
                    tran.Rollback();
                }
                catch
                { }
                throw;
            }
            finally
            {
                if (cn.State == ConnectionState.Open)
                    cn.Close();
            }
        }
        protected SqlParameter[] GetEditParams(CustomFormInfo info)
        {
            SqlParameter[] Param = new SqlParameter[15];
            Param[0] = new SqlParameter("@formname", SqlDbType.NVarChar, 50);
            Param[0].Value = info.formname;
            Param[1] = new SqlParameter("@formtablename", SqlDbType.NVarChar, 50);
            Param[1].Value = info.formtablename;
            Param[2] = new SqlParameter("@accessorypath", SqlDbType.NVarChar, 100);
            Param[3] = new SqlParameter("@accessorysize", SqlDbType.Int);
            if (info.accessorypath == string.Empty && info.accessorysize > 0)
            {
                Param[2].Value = DBNull.Value;
                Param[3].Value = DBNull.Value;
            }
            else
            {
                Param[2].Value = info.accessorypath;
                Param[3].Value = info.accessorysize;
            }
            Param[4] = new SqlParameter("@memo", SqlDbType.NVarChar, 255);
            if (info.memo == string.Empty)
                Param[4].Value = DBNull.Value;
            else
                Param[4].Value = info.memo;
            Param[5] = new SqlParameter("@islock", SqlDbType.Bit);
            Param[5].Value = info.islock;
            Param[6] = new SqlParameter("@timelimited", SqlDbType.Bit);
            Param[6].Value = info.timelimited;
            Param[7] = new SqlParameter("@starttime", SqlDbType.DateTime);
            Param[8] = new SqlParameter("@endtime", SqlDbType.DateTime);
            if (info.timelimited)
            {
                Param[7].Value = info.starttime;
                Param[8].Value = info.endtime;
            }
            else
            {
                Param[7].Value = DBNull.Value;
                Param[8].Value = DBNull.Value;
            }
            Param[9] = new SqlParameter("@showvalidatecode", SqlDbType.Bit);
            Param[9].Value = info.showvalidatecode;
            Param[10] = new SqlParameter("@submitonce", SqlDbType.Bit);
            Param[10].Value = info.submitonce;
            Param[11] = new SqlParameter("@isdelpoint", SqlDbType.TinyInt);
            Param[11].Value = info.isdelpoint;
            Param[12] = new SqlParameter("@gpoint", SqlDbType.Int);
            Param[12].Value = info.gpoint;
            Param[13] = new SqlParameter("@ipoint", SqlDbType.Int);
            Param[13].Value = info.ipoint;
            Param[14] = new SqlParameter("@groupnumber", SqlDbType.NText);
            if (info.groupnumber == string.Empty)
                Param[14].Value = DBNull.Value;
            else
                Param[14].Value = info.groupnumber;
            return Param;
        }
        CustomFormInfo ICustomForm.GetInfo(int id)
        {
            SqlConnection cn = new SqlConnection(DBConfig.CmsConString);
            cn.Open();
            try
            {
                return GetInfo(cn, id);
            }
            finally
            {
                if (cn.State == ConnectionState.Open)
                    cn.Close();
            }
        }
        protected CustomFormInfo GetInfo(SqlConnection cn, int id)
        {
            CustomFormInfo info = new CustomFormInfo();
            string Sql = "select * from " + Pre + "customform where id=" + id;
            bool flag = false;
            IDataReader rd = DbHelper.ExecuteReader(cn, CommandType.Text, Sql, null);
            if (rd.Read())
            {
                info.id = id;
                info.formname = rd["formname"].ToString();
                info.formtablename = rd["formtablename"].ToString();
                if (rd["accessorypath"] != DBNull.Value) info.accessorypath = rd["accessorypath"].ToString();
                if (rd["accessorysize"] != DBNull.Value) info.accessorysize = Convert.ToInt32(rd["accessorysize"]);
                if (rd["memo"] != DBNull.Value) info.memo = rd["memo"].ToString();
                if (rd["islock"] != DBNull.Value) info.islock = Convert.ToBoolean(rd["islock"]);
                info.timelimited = Convert.ToBoolean(rd["timelimited"]);
                if (rd["starttime"] != DBNull.Value) info.starttime = Convert.ToDateTime(rd["starttime"]);
                if (rd["endtime"] != DBNull.Value) info.endtime = Convert.ToDateTime(rd["endtime"]);
                info.showvalidatecode = Convert.ToBoolean(rd["showvalidatecode"]);
                info.submitonce = Convert.ToBoolean(rd["submitonce"]);
                info.isdelpoint = Convert.ToByte(rd["isdelpoint"]);
                info.gpoint = Convert.ToInt32(rd["gpoint"]);
                info.ipoint = Convert.ToInt32(rd["ipoint"]);
                if (rd["groupnumber"] != DBNull.Value) info.groupnumber = rd["groupnumber"].ToString();
                flag = true;
            }
            rd.Close();
            if (!flag)
            {
                throw new Exception("没有找到相关的自定义表单记录!");
            }
            return info;
        }
        void ICustomForm.DeleteForm(int id)
        {
            SqlConnection cn = new SqlConnection(DBConfig.CmsConString);
            cn.Open();
            SqlTransaction tran = cn.BeginTransaction();
            try
            {
                string Sql = "select formtablename from " + Pre + "customform where id=" + id;
                object obj = DbHelper.ExecuteScalar(tran, CommandType.Text, Sql, null);
                if (obj != null && obj != DBNull.Value)
                {
                    Sql = "delete from " + Pre + "customform where id=" + id;
                    DbHelper.ExecuteNonQuery(tran, CommandType.Text, Sql, null);
                    Sql = "delete from " + Pre + "customform_item where formid=" + id;
                    DbHelper.ExecuteNonQuery(tran, CommandType.Text, Sql, null);
                    Sql = "drop table [" + obj + "]";
                    DbHelper.ExecuteNonQuery(tran, CommandType.Text, Sql, null);
                    tran.Commit();
                }
                else
                {
                    throw new Exception("没有找到相关的自定义表单记录");
                }
            }
            catch
            {
                try
                {
                    tran.Rollback();
                }
                catch
                { }
                throw;
            }
            finally
            {
                if (cn.State == ConnectionState.Open)
                    cn.Close();
            }
        }
        string ICustomForm.GetFormName(int id)
        {
            string Sql = "select formname from " + Pre + "customform where id=" + id;
            object obj = DbHelper.ExecuteScalar(CommandType.Text, Sql, null);
            if (obj == null)
            {
                throw new Exception("没有找到相关的表单记录");
            }
            else
            {
                if (obj == DBNull.Value)
                    return string.Empty;
                else
                    return obj.ToString();
            }
        }
        CustomFormItemInfo ICustomForm.GetFormItemInfo(int itemid)
        {
            CustomFormItemInfo info = new CustomFormItemInfo();
            string Sql = "select a.*,b.formname from " + Pre + "customform_item a inner join " + Pre + "customform b on a.formid=b.id where a.id=" + itemid;
            bool flag = false;
            IDataReader rd = DbHelper.ExecuteReader(CommandType.Text, Sql, null);
            if (rd.Read())
            {
                info.id = Convert.ToInt32(rd["id"]);
                info.formid = Convert.ToInt32(rd["formid"]);
                info.formname = rd["formname"].ToString();
                info.seriesnumber = Convert.ToInt32(rd["seriesnumber"]);
                info.fieldname = rd["fieldname"].ToString();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -