using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace yinLouSys
{
    public partial class frmSet : Form
    {
        private int _execFlag = 0;


        public int ExecFlag
        {
            get { return _execFlag; }
            set { _execFlag = value; }
        }

        public frmSet()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (lstTx.SelectedIndex >= 0)
            {
                lstTx.Items.RemoveAt(lstTx.SelectedIndex);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if ("" == txtName.Text)
            {
                MessageBox.Show("名称不能为空", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtName.Focus();
                return;
            }

            if(lstTx.Items.Contains(txtName.Text))
            {
                MessageBox.Show("您输入的名称已经存在", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtName.Focus();
                return;
            }

            lstTx.Items.Add(txtName.Text);
            txtName.Text = "";
            txtName.Focus();
            
        }

        private void frmSet_Load(object sender, EventArgs e)
        {
            try
            {
                object obj = code.SQLHelp.ExecuteScalar("select isnull(s_values,'') from tab_setting where s_name='套系'", null);
                if (obj != null && obj.ToString().Trim() != "")
                {
                    string[] list = obj.ToString().Split('|');

                    lstTx.Items.Clear();
                    for (int i = 0; i < list.Length; i++)
                    {
                        lstTx.Items.Add(list[i]);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                string temp = "";

                for (int i = 0; i < lstTx.Items.Count; i++)
                {
                    temp += lstTx.Items[i].ToString() + "|";
                }

                if ("" != temp)
                {
                    temp = temp.Substring(0, temp.Length - 1);
                    code.SQLHelp.ExecuteNoResult("update tab_setting set s_values='" + temp + "'  where s_name='套系'");
                    MessageBox.Show("设置成功", "系统消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    _execFlag = 1;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("您没有添加套系信息", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}