Пример #1
0
        public int Insert(PollInfo oParam)
        {
            string sql = @"INSERT INTO Poll
                            (
                            PollName, PollCount, Status
                            )
                            VALUES (
                            @PollName, @PollCount, @Status
                            );set @SysNo = SCOPE_IDENTITY();";
            SqlCommand cmd = new SqlCommand(sql);

            SqlParameter paramSysNo = new SqlParameter("@SysNo", SqlDbType.Int,4);
            SqlParameter paramPollName = new SqlParameter("@PollName", SqlDbType.NVarChar,200);
            SqlParameter paramPollCount = new SqlParameter("@PollCount", SqlDbType.Int,4);
            SqlParameter paramStatus = new SqlParameter("@Status", SqlDbType.Int,4);

            paramSysNo.Direction = ParameterDirection.Output;

            if ( oParam.PollName != AppConst.StringNull)
                paramPollName.Value = oParam.PollName;
            else
                paramPollName.Value = System.DBNull.Value;
            if ( oParam.PollCount != AppConst.IntNull)
                paramPollCount.Value = oParam.PollCount;
            else
                paramPollCount.Value = System.DBNull.Value;
            if ( oParam.Status != AppConst.IntNull)
                paramStatus.Value = oParam.Status;
            else
                paramStatus.Value = System.DBNull.Value;

            cmd.Parameters.Add(paramSysNo);
            cmd.Parameters.Add(paramPollName);
            cmd.Parameters.Add(paramPollCount);
            cmd.Parameters.Add(paramStatus);

            return SqlHelper.ExecuteNonQuery(cmd, out oParam.SysNo);
        }
Пример #2
0
        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();
            }
        }
Пример #3
0
 public void map(PollInfo oParam, DataRow tempdr)
 {
     oParam.SysNo = Util.TrimIntNull(tempdr["SysNo"]);
     oParam.PollName = Util.TrimNull(tempdr["PollName"]);
     oParam.PollCount = Util.TrimIntNull(tempdr["PollCount"]);
     oParam.Status = Util.TrimIntNull(tempdr["Status"]);
 }
Пример #4
0
        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;
        }
Пример #5
0
 public void Insert(PollInfo oParam)
 {
     new PollDac().Insert(oParam);
 }