using System; using System.Collections.Generic; using System.Linq; using System.Web; using DSWeb.Models; using WebSqlHelper; using System.Text; using System.Data; using System.Data.SqlClient; namespace DSWeb.EntityDA { public class CodeOwefeeModuleSetDA { SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction); /// /// 返回 某字段 /// /// public string GetStrSQL(string strfield, string strSQL) { string alt = ""; DataSet DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, strSQL); if (DS != null) { if (DS.Tables[0].Rows.Count > 0) { alt = DS.Tables[0].Rows[0]["" + strfield + ""].ToString(); } } return alt; } /// /// 返回 数据集 /// /// public DataSet GetAllSQL(string strSQL) { DataSet DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, strSQL); try { if (DS.Tables[0].Rows.Count <= 0) { DS = null; } } catch { DS = null; } return DS; } /////////////////////////////////////////////////////////////////////////////////////////////////////////// /// /// 根据gid删除信息 /// /// /// public int CreateTable(string gv_gid) { string sSQL = "select TABLENAME from code_owefee_module where GID='" + gv_gid + "'"; string sTableName = GetStrSQL("TABLENAME", sSQL); // string sqlstr = "CREATE TABLE [dbo].[" + sTableName + "] ("; // sSQL = "select FIELDNAME from code_owefee_module_detail where LINKGID='" + gv_gid + "' order by ISFEEFIELD,FIELDNAME"; DataSet ds = GetAllSQL(sSQL); if(ds!=null) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { sqlstr += "[" + ds.Tables[0].Rows[i]["FIELDNAME"] + "] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,"; } } // sqlstr += " ) ON [PRIMARY]"; // int result = 0; try { SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr); result = 1; } catch (Exception) { result = -1; //throw e; } return result; } /// /// 根据gid删除信息 /// /// /// public int DelteGid(string ID) { string sqlstr = "delete from [code_owefee_module] where gid='" + ID + "' "; int result = 0; try { SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr); result = 1; } catch (Exception error) { result = -1; throw error; } return result; } /// /// 修改信息 GID /// /// public int UpdateGid(CodeOweFeeModuleEntity opctn) { StringBuilder sqlstr = new StringBuilder(); sqlstr.Append("UPDATE [code_owefee_module] SET [MODULENAME] = @MODULENAME WHERE GID=@GID"); SqlParameter[] param = new SqlParameter[] { new SqlParameter("@GID",opctn.GID), new SqlParameter("@MODULENAME",opctn.MODULENAME) }; int result = 0; using (conn) { try { SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sqlstr.ToString(), param); result = 1; } catch (Exception error) { result = -1; throw error; } } return result; } /// /// 添加新的信息 /// /// /// public void Insert(string strGID, string strMODULENAME, string strTABLENAME, string strUserID, string strCompanyID) { StringBuilder sqlstr = new StringBuilder(); sqlstr.Append(" INSERT INTO [code_owefee_module]([GID],[MODULENAME],[TABLENAME],[CREATEUSER],[CORPID])"); sqlstr.Append(" VALUES(@GID,@MODULENAME,@TABLENAME,@CREATEUSER,@CORPID)"); SqlParameter[] param = new SqlParameter[] { new SqlParameter("@GID",strGID), new SqlParameter("@MODULENAME",strMODULENAME), new SqlParameter("@TABLENAME",strTABLENAME), new SqlParameter("@CREATEUSER",strUserID), new SqlParameter("@CORPID",strCompanyID), }; try { SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction.ToString(), CommandType.Text, sqlstr.ToString(), param); } catch (Exception error) { throw error; } } /////////////////////////////////////////////////////////////////////////////////////////////////////////// /// /// 根据gid删除信息 /// /// /// public int DelteGidFee(string ID) { string sqlstr = "delete from [code_owefee_module_detail] where gid='" + ID + "'"; int result = 0; try { SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr); result = 1; } catch (Exception error) { result = -1; throw error; } return result; } /// /// 修改信息 GID /// /// public int UpdateGidFee(CodeOweFeeModuleDetailEntity opctn) { StringBuilder sqlstr = new StringBuilder(); sqlstr.Append("UPDATE [code_owefee_module_detail] SET [FIELDS] = @FIELDS,[FIELDNAME] = @FIELDNAME WHERE GID=@GID"); SqlParameter[] param = new SqlParameter[] { new SqlParameter("@GID",opctn.GID), new SqlParameter("@FIELDS",opctn.FIELDS), new SqlParameter("@FIELDNAME",opctn.FIELDNAME) }; int result = 0; using (conn) { try { SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sqlstr.ToString(), param); result = 1; } catch (Exception error) { result = -1; throw error; } } return result; } /// /// 添加新的信息 /// /// /// public void InsertFee(string strGID, string strLINKGID, string strFIELDS, string strFIELDNAME, Boolean blISFEEFIELD, int i) { int iResult = 0; using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { if (i == 0) { string ls = "delete from code_owefee_module_detail where LINKGID='" + strLINKGID + "' and ISFEEFIELD=0"; iResult = -3; SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, ls, null); } // StringBuilder sqlstr = new StringBuilder(); sqlstr.Append(" INSERT INTO [code_owefee_module_detail]([GID],[LINKGID],[FIELDS],[FIELDNAME],[ISFEEFIELD])"); sqlstr.Append(" VALUES(@GID,@LINKGID,@FIELDS,@FIELDNAME,@ISFEEFIELD)"); SqlParameter[] param = new SqlParameter[] { new SqlParameter("@GID",strGID), new SqlParameter("@LINKGID",strLINKGID), new SqlParameter("@FIELDS",strFIELDS), new SqlParameter("@FIELDNAME",strFIELDNAME), new SqlParameter("@ISFEEFIELD",blISFEEFIELD) }; iResult = -4; SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sqlstr.ToString(), param); // sqlTran.Commit(); iResult = 1;//状态为1表示更新成功 } catch (Exception execError) { iResult = -1;//有异常,更新失败 sqlTran.Rollback(); iResult = -2;//更新异常,事务已回滚成功 throw execError; } finally { SqlHelper.CloseConnection(); } } } // /// /// 添加新的信息 /// /// /// public void InsertDetailFee(string strLINKGID, string strFIELDNAME, int i) { int iResult = 0; using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { if (i == 0) { string ls = "delete from code_owefee_module_detail_fee where LINKGID='" + strLINKGID + "'"; iResult = -3; SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, ls, null); } // StringBuilder sqlstr = new StringBuilder(); sqlstr.Append(" INSERT INTO [code_owefee_module_detail_fee]([GID],[LINKGID],[FIELDNAME])"); sqlstr.Append(" VALUES(newid(),@LINKGID,@FIELDNAME)"); SqlParameter[] param = new SqlParameter[] { new SqlParameter("@LINKGID",strLINKGID), new SqlParameter("@FIELDNAME",strFIELDNAME) }; iResult = -4; SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sqlstr.ToString(), param); // sqlTran.Commit(); iResult = 1;//状态为1表示更新成功 } catch (Exception execError) { iResult = -1;//有异常,更新失败 sqlTran.Rollback(); iResult = -2;//更新异常,事务已回滚成功 throw execError; } finally { SqlHelper.CloseConnection(); } } } // } }