예제 #1
0
 /// <summary>
 /// 修改
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void button_save_Click(object sender, EventArgs e)
 {
     if (this.dataGridView1.SelectedCells.Count != 0)
     {
         int    r    = this.dataGridView1.SelectedCells[0].RowIndex;
         string name = this.input_name.Text;
         string btn  = this.input_btn.Text;
         for (int i = 0; i < buttons.Count; i++)
         {
             if (i != r)
             {
                 if (!string.IsNullOrWhiteSpace(name) && name == buttons[i].name)
                 {
                     this.input_name.Text = buttons[r].name;
                     MessageBox.Show("级别名称重复,请重新输入。");
                     return;
                 }
             }
         }
         if (btn.Length > 1 || (btn.Length == 1 && !Regex.IsMatch(btn, "^[0-9a-zA-Z]+$")))
         {
             this.input_btn.Text = buttons[r].btn;
             MessageBox.Show("快捷键只能设置一个数字或字母");
             return;
         }
         else
         {
             for (int i = 0; i < buttons.Count; i++)
             {
                 if (i != r)
                 {
                     if (!string.IsNullOrWhiteSpace(btn) && btn == buttons[i].btn)
                     {
                         this.input_btn.Text = buttons[r].btn;
                         MessageBox.Show("快捷键重复,请重新输入。");
                         return;
                     }
                 }
             }
         }
         LabelItem labelItem = new LabelItem();
         labelItem.id         = (int)this.dataGridView1.Rows[r].Cells["id"].Value;
         labelItem.name       = name;
         labelItem.btn        = btn;
         labelItem.life_cycle = 1;
         if (DbUtil.updateLabelItem(labelItem))
         {
             this.dataSource_labels();
             MessageBox.Show("操作成功");
         }
         else
         {
             MessageBox.Show("操作失败");
         }
     }
     else
     {
         MessageBox.Show("请选择一条数据");
     }
 }
예제 #2
0
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void button_del_Click(object sender, EventArgs e)
 {
     if (this.dataGridView1.SelectedCells.Count != 0)
     {
         int       r         = this.dataGridView1.SelectedCells[0].RowIndex;
         LabelItem labelItem = new LabelItem();
         labelItem.id         = (int)this.dataGridView1.Rows[r].Cells["id"].Value;
         labelItem.name       = this.input_name.Text;
         labelItem.btn        = this.input_btn.Text;
         labelItem.life_cycle = -1;
         if (DbUtil.updateLabelItem(labelItem))
         {
             this.dataSource_labels();
             MessageBox.Show("操作成功");
         }
         else
         {
             MessageBox.Show("操作失败");
         }
     }
     else
     {
         MessageBox.Show("请选择一条数据");
     }
 }
예제 #3
0
        /// <summary>
        /// 查询按钮list
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static List <LabelItem> queryButtons(string sql)
        {
            List <LabelItem> buttons = new List <LabelItem>();
            MySqlConnection  conn    = new MySqlConnection(Conn);

            try
            {
                //打开连接
                conn.Open();

                #region//查询数据
                MySqlCommand    cmd    = new MySqlCommand(sql, conn);
                MySqlDataReader reader = cmd.ExecuteReader();
                try
                {
                    while (reader.Read())
                    {
                        if (reader.HasRows)
                        {
                            LabelItem bi1 = new LabelItem();
                            bi1.id   = reader.GetInt32(0);
                            bi1.name = reader.GetString(1);
                            bi1.btn  = reader.GetString(2);
                            buttons.Add(bi1);
                        }
                    }
                    return(buttons);
                }
                catch (Exception)
                {
                    return(buttons);
                }
                finally
                {
                    reader.Close();
                }
                #endregion
            }
            catch (Exception ex)
            {
                return(buttons);
            }
            finally
            {
                //调用Close方法即使关闭连接
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
        }
예제 #4
0
        private void button_add_Click(object sender, EventArgs e)
        {
            string name = this.input_name.Text;
            string btn  = this.input_btn.Text;

            for (int i = 0; i < buttons.Count; i++)
            {
                if (!string.IsNullOrWhiteSpace(name) && name == buttons[i].name)
                {
                    this.input_name.Text = "";
                    MessageBox.Show("级别名称重复,请重新输入。");
                    return;
                }
            }
            if (btn.Length > 1 || (btn.Length == 1 && !Regex.IsMatch(btn, "^[0-9a-zA-Z]+$")))
            {
                this.input_btn.Text = "";
                MessageBox.Show("快捷键只能设置一个数字或字母");
                return;
            }
            else
            {
                for (int i = 0; i < buttons.Count; i++)
                {
                    if (!string.IsNullOrWhiteSpace(btn) && btn == buttons[i].btn)
                    {
                        this.input_btn.Text = "";
                        MessageBox.Show("快捷键重复,请重新输入。");
                        return;
                    }
                }
            }
            LabelItem labelItem = new LabelItem();

            labelItem.name       = name;
            labelItem.btn        = btn;
            labelItem.life_cycle = 1;
            if (DbUtil.insertLabelItem(labelItem))
            {
                this.dataSource_labels();
                MessageBox.Show("操作成功");
            }
            else
            {
                MessageBox.Show("操作失败");
            }
        }
예제 #5
0
        /// <summary>
        /// 修改标签
        /// </summary>
        /// <param name="weights"></param>
        /// <returns></returns>
        public static bool updateLabelItem(LabelItem lableItem)
        {
            MySqlConnection conn = new MySqlConnection(Conn);

            try
            {
                //打开连接
                conn.Open();

                StringBuilder strSql = new StringBuilder();
                strSql.AppendFormat(@"update t_labels set name='{0}',btn='{1}',life_cycle='{2}' where id={3}",
                                    lableItem.name,
                                    lableItem.btn,
                                    lableItem.life_cycle,
                                    lableItem.id);

                MySqlCommand cmd_insert = new MySqlCommand(strSql.ToString(), conn);
                try
                {
                    cmd_insert.ExecuteNonQuery();
                    return(true);
                }
                catch (Exception ex)
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
            finally
            {
                //调用Close方法即使关闭连接
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
        }
예제 #6
0
        /// <summary>
        /// 新增标签
        /// </summary>
        /// <param name="labelItem"></param>
        /// <returns></returns>
        public static bool insertLabelItem(LabelItem labelItem)
        {
            MySqlConnection conn = new MySqlConnection(Conn);

            try
            {
                //打开连接
                conn.Open();

                #region//插入数据
                StringBuilder strSql = new StringBuilder();
                strSql.AppendFormat(@"insert into t_labels (name, btn, life_cycle) values('{0}', '{1}', '{2}')",
                                    labelItem.name,
                                    labelItem.btn,
                                    labelItem.life_cycle);
                MySqlCommand cmd_insert = new MySqlCommand(strSql.ToString(), conn);
                try
                {
                    cmd_insert.ExecuteNonQuery();
                    return(true);
                }
                catch (Exception ex)
                {
                    return(false);
                }
                #endregion
            }
            catch (Exception ex)
            {
                return(false);
            }
            finally
            {
                //调用Close方法即使关闭连接
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
        }