public int InsertItem(PollItemInfo oParam) { string sql = @"INSERT INTO Poll_Item ( PollSysNo, ItemName, ItemCount ) VALUES ( @PollSysNo, @ItemName, @ItemCount );set @SysNo = SCOPE_IDENTITY();"; SqlCommand cmd = new SqlCommand(sql); SqlParameter paramSysNo = new SqlParameter("@SysNo", SqlDbType.Int,4); SqlParameter paramPollSysNo = new SqlParameter("@PollSysNo", SqlDbType.Int,4); SqlParameter paramItemName = new SqlParameter("@ItemName", SqlDbType.NVarChar,200); SqlParameter paramItemCount = new SqlParameter("@ItemCount", SqlDbType.Int,4); paramSysNo.Direction = ParameterDirection.Output; if ( oParam.PollSysNo != AppConst.IntNull) paramPollSysNo.Value = oParam.PollSysNo; else paramPollSysNo.Value = System.DBNull.Value; if ( oParam.ItemName != AppConst.StringNull) paramItemName.Value = oParam.ItemName; else paramItemName.Value = System.DBNull.Value; if ( oParam.ItemCount != AppConst.IntNull) paramItemCount.Value = oParam.ItemCount; else paramItemCount.Value = System.DBNull.Value; cmd.Parameters.Add(paramSysNo); cmd.Parameters.Add(paramPollSysNo); cmd.Parameters.Add(paramItemName); cmd.Parameters.Add(paramItemCount); return SqlHelper.ExecuteNonQuery(cmd, out oParam.SysNo); }
public void Import() { if ( !AppConfig.IsImportable) throw new BizException("Is Importable is false"); /* do not use the following code after Data Pour in */ string sql = " select top 1 * from poll "; DataSet ds = SqlHelper.ExecuteDataSet(sql); if ( Util.HasMoreRow(ds) ) throw new BizException("the table poll is not empty"); TransactionOptions options = new TransactionOptions(); options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted; options.Timeout = TransactionManager.DefaultTimeout; using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options)) { string sql1 = "select * from ipp2003..poll"; DataSet ds1 = SqlHelper.ExecuteDataSet(sql1); foreach(DataRow dr1 in ds1.Tables[0].Rows) { PollInfo oPoll = new PollInfo(); map(oPoll,dr1); switch( oPoll.Status) { case -1: case 0: oPoll.Status = (int)AppEnum.BiStatus.InValid; break; case 1: oPoll.Status = (int)AppEnum.BiStatus.Valid; break; default: throw new BizException("no such status"); } //��sysnono��û�иı���ǰ����һ��item���ַ���:�� string sql2 = "select * from ipp2003..poll_item where pollsysno=" + oPoll.SysNo; new PollDac().Insert(oPoll); DataSet ds2 = SqlHelper.ExecuteDataSet(sql2); foreach(DataRow dr2 in ds2.Tables[0].Rows) { PollItemInfo oPollItem = new PollItemInfo(); map(oPollItem, dr2); oPollItem.PollSysNo = oPoll.SysNo; new PollDac().InsertItem(oPollItem); } } scope.Complete(); } }
public void map(PollItemInfo oParam, DataRow tempdr) { oParam.SysNo = Util.TrimIntNull(tempdr["SysNo"]); oParam.PollSysNo = Util.TrimIntNull(tempdr["PollSysNo"]); oParam.ItemName = Util.TrimNull(tempdr["ItemName"]); oParam.ItemCount = Util.TrimIntNull(tempdr["ItemCount"]); }
public PollInfo Load(int sysno) { string sql = "select * from poll where sysno = " + sysno; DataSet ds = SqlHelper.ExecuteDataSet(sql); if ( !Util.HasMoreRow(ds)) return null; PollInfo oPoll = new PollInfo(); map(oPoll, ds.Tables[0].Rows[0]); string sqlItem = "select * from poll_item where pollsysno = " + sysno +" order by ItemName" ; DataSet dsItem = SqlHelper.ExecuteDataSet(sqlItem); if ( Util.HasMoreRow(dsItem)) { foreach(DataRow dr in dsItem.Tables[0].Rows) { PollItemInfo oPollItem = new PollItemInfo(); map(oPollItem, dr); oPoll.itemHash.Add(oPollItem.SysNo, oPollItem); } } return oPoll; }
public void InsertItem(PollItemInfo oParam) { new PollDac().InsertItem(oParam); }