//读写器天线录入
    public static int WriterReader(WriterReaderBean bean,Window win)
    {
       ReaderAndWriterConnection _Connection = new ReaderAndWriterConnection();
        MySqlConnection conn = new MySqlConnection(MySqlHelper.Conn);
            conn.Open();
            MySqlCommand cmd = new MySqlCommand();
            cmd.Connection = conn;
            MySqlTransaction tx = conn.BeginTransaction();
            cmd.Transaction = tx;
        try
        {
            //读写器连接
            int state = _Connection.Connection();
            int _WState = _Connection.WritertEPC(bean.EpcCode, win);
            if (state == BaseRequest.SUCCESS && _WState == BaseRequest.SUCCESS)
            {
                //把16进制字符串转换成ushout数组
                string date = Convert.ToDateTime(DateTime.Now).ToString(BaseRequest.DATE_TIME_FORMAT);
                string sql = "INSERT INTO reader_writer(READER_WRITER_ID,NUMBER,NAME,IP,PORT,ANTENNA_SUM,TYPE,SWEEP_TIME,CREATE_USER_ID,CREATE_TIME,ROOM_ID)" +
                            "VALUES(" + @bean.Id + ",'" + @bean.EpcCode + "','" + @bean.Name + "','" + @bean.Ip + "'," + @bean.Port + "," + @bean.AntennaSum + "," + @bean.Type + "," +
                            [email protected] + "," + @Session.UserId + ",'" + @date + "'," + @bean.RoomId + ")";
                MySqlParameter[] parameters =
                {
                    new MySqlParameter("@bean.Id",bean.Id),
                    new MySqlParameter("@bean.EpcCode",bean.EpcCode),
                    new MySqlParameter("@bean.Name",bean.Name),
                    new MySqlParameter("@bean.Ip",bean.Ip),
                    new MySqlParameter("@bean.Port",bean.Port),
                    new MySqlParameter("@bean.AntennaSum",bean.AntennaSum),
                    new MySqlParameter("@bean.Type",bean.Type),
                    new MySqlParameter("@bean.SweepTime",bean.SweepTime),
                    new MySqlParameter("@Session.UserId",Session.UserId),
                    new MySqlParameter("@date",date),
                    new MySqlParameter("@bean.RoomId",bean.RoomId),
                };
                cmd.CommandText = sql;
                if (parameters != null)
                {
                    foreach (MySqlParameter parm in parameters)
                        cmd.Parameters.Add(parm);
                }

                cmd.ExecuteNonQuery();
                cmd.Parameters.Clear();
                //string InSql = "INSERT INTO work_order(ID,STATUS,USER_ID,DATE_TIME) VALUES(" + @bean.Id + "," + @BaseRequest.INPUT_STATUS + "," +
                //[email protected] + ",'" + @date + "')";
                //MySqlParameter[] parametersIt =
                //    {
                //        new MySqlParameter("@bean.Id",bean.Id),
                //        new MySqlParameter("@BaseRequest.INPUT_STATUS",BaseRequest.INPUT_STATUS),
                //        new MySqlParameter("@Session.UserId",Session.UserId),
                //        new MySqlParameter("@date",date),
                //    };
                //cmd.CommandText = InSql;
                //if (parametersIt != null)
                //{
                //    foreach (MySqlParameter parm in parameters)
                //        cmd.Parameters.Add(parm);
                //}
                //cmd.ExecuteNonQuery();
                //cmd.Parameters.Clear();

                for (int i = 1; i < (bean.AntennaSum + 1); i++)
                {
                    string _sql = "INSERT INTO antenna (ID_CODE,READER_WRITER_ID) VALUES(" + @i + "," + @bean.Id + ") ";
                    MySqlParameter[] _Parameters =
                    {
                            new MySqlParameter("@i",i),
                        new MySqlParameter("@bean.Id",bean.Id),
                    };
                    cmd.CommandText = _sql;
                    if (_Parameters != null)
                    {
                        foreach (MySqlParameter parm in parameters)
                            cmd.Parameters.Add(parm);
                    }
                    cmd.ExecuteNonQuery();
                    cmd.Parameters.Clear();
                }
                tx.Commit();
                return BaseRequest.SUCCESS;
            }
            else
            {
                return BaseRequest.SYSTEM_EXCEPTION;
            }
        }
        catch (Exception e)
        {
            tx.Rollback();
            conn.Close();
            e.GetBaseException();
            return BaseRequest.SYSTEM_EXCEPTION;
        }
    }
 /************************************************************************/
 /* 设备信息录入,录入属原子性,要么写如标签和插入数据同时通过,要么就同时失败 .                                                                    */
 /************************************************************************/
 public static int addEquipmentService(DeviceBean bean,Window win)
 {
     ReaderAndWriterConnection _Connection = new ReaderAndWriterConnection();
     MySqlConnection conn = new MySqlConnection(MySqlHelper.Conn);
         conn.Open();
         MySqlCommand cmd = new MySqlCommand();
         cmd.Connection = conn;
         MySqlTransaction tx = conn.BeginTransaction();
         cmd.Transaction = tx;
     try
     {
         //读写器连接
         int state = _Connection.Connection();
         //返回写入标签状态(成功/失败)
         int _WState = _Connection.WritertEPC(bean.EPCCode, win);
         
         //如果连接和写入标签成功,则操作数据库存储
         if (state == BaseRequest.SUCCESS&&_WState==BaseRequest.SUCCESS) { 
         string date = Convert.ToDateTime(DateTime.Now).ToString(BaseRequest.DATE_TIME_FORMAT);
         string sql = "INSERT INTO equipment(ID,NUMBER,NAME,DEVICE_CLASS_ID,ROOMS_ID,USER_ID,STORAGE_TIME)" +
                     " VALUES(" + @bean.Id + ",'" + @bean.EPCCode + "','" + @bean.Name + "'," + @bean.Type + "," + 
                     @bean.RoomId + "," + @Session.UserId + ",'" + @date + "')";
         MySqlParameter[] parameters =
         {
             new MySqlParameter("@bean.Id",bean.Id),
             new MySqlParameter("@bean.EPCCode",bean.EPCCode),
             new MySqlParameter("@bean.Name",bean.Name),
             new MySqlParameter("@bean.Type",bean.Type),
             new MySqlParameter("@bean.RoomId",bean.RoomId),
             new MySqlParameter("@Session.UserId",Session.UserId),
             new MySqlParameter("@date",date),
             };
         cmd.CommandText = sql;
         if (parameters != null)
         {
             foreach (MySqlParameter parm in parameters)
                 cmd.Parameters.Add(parm);
         }
         cmd.ExecuteNonQuery();
         cmd.Parameters.Clear();
         string orderSql = "INSERT INTO work_order(ID,STATUS,USER_ID,DATE_TIME) " +
                                 "VALUES(" + @bean.Id + "," + @BaseRequest.INPUT_STATUS + "," + @Session.UserId + ",'" + @date + "')";
         MySqlParameter[] parametersTow =
         {
             new MySqlParameter("@bean.Id",bean.Id),
             new MySqlParameter("@BaseRequest.REPAIR_STATUS",BaseRequest.INPUT_STATUS),
             new MySqlParameter("@Session.UserId",Session.UserId),
             new MySqlParameter("@date",date),
         };
         cmd.CommandText = orderSql;
         if (parametersTow != null)
         {
             foreach (MySqlParameter parm in parameters)
                 cmd.Parameters.Add(parm);
         }
         cmd.ExecuteNonQuery();
         cmd.Parameters.Clear();
         tx.Commit();
         conn.Close();
         return BaseRequest.SUCCESS;
         }
         else
         {
             return BaseRequest.SYSTEM_EXCEPTION;
         }
         }
     catch (Exception e)
     {
         tx.Rollback();
         e.GetBaseException();
         return BaseRequest.SYSTEM_EXCEPTION;
     }
 }