private void Submit_Add(object sender, RoutedEventArgs e)
        {
            DeviceBean bean = new DeviceBean();
            EquipmentClass equipClass = new EquipmentClass();
            bean.Id = int.Parse(this.ID.Content.ToString());
            ComboBoxItem typeItem = (ComboBoxItem)this.typeBox.SelectedItem;
            ComboBoxItem roomItem = (ComboBoxItem)this.roomBox.SelectedItem;
            if (typeItem.Tag.ToString().Equals(""))
            {
                MessageBox.Show("请选择设备类别!");
                return;
            }
            if (this.equipName.Text.Equals("") || this.equipName.Text == null)
            {
                MessageBox.Show("请输入设备名称!");
                return;
            }
            if (roomItem.Tag.ToString().Equals(""))
            {

                MessageBox.Show("请选择设备所属机房!");
                return;
            }
            int state = 0;
            this.add.IsEnabled = false;
            bean.Name = this.equipName.Text;
            bean.RoomId = (int)roomItem.Tag;
            bean.Type = (int)typeItem.Tag;
            bean.Id = int.Parse(this.ID.Content.ToString());
            bean.EPCCode = this.numberStr.Text;
            state = equipClass.addEquipment(bean, this);
            this.add.IsEnabled = true;
            if (state == BaseRequest.SUCCESS)
            {
                //EquipmentClass equitment = new EquipmentClass();
                //DataSet set = equitment.comingEquipment();
                //NewEquipment equipments = DeviceMigrationsFactory.NewEquipment;
                //DeviceMigrationsFactory.NewEquipment.page.ShowPages(DeviceMigrationsFactory.NewEquipment.comingGrild, set, BaseRequest.PAGE_SIZE);
                //JXMessageBox.Show(Window.GetWindow(this), "已成功录入设备信息!", MsgImage.Success);
                //Close_Add(DeviceMigrationsFactory.AddEquipment, new RoutedEventArgs());

            }
            else
            {
                JXMessageBox.Show(Window.GetWindow(this), "未知错误,请联系管理员!", MsgImage.Error);
            }
        }
Example #2
0
 /************************************************************************/
 /* 设备信息录入,录入属原子性,要么写如标签和插入数据同时通过,要么就同时失败 .                                                                    */
 /************************************************************************/
 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;
     }
 }
Example #3
0
 //添加设备
 public int addEquipment(DeviceBean bean, Window win)
 {
     return(MyTransaction.addEquipmentService(bean, win));
 }
Example #4
0
 //添加设备
 public int addEquipment(DeviceBean bean, Window win)
 {
   
        return MyTransaction.addEquipmentService(bean,win);
     
 }