public static bool CreateClient(Client client)
        {
            try
            {
                SQLiteConnection conn = new SQLiteConnection("Data Source=settings.db;");
                conn.Open();
                SQLiteCommand cmd = conn.CreateCommand();
                cmd.CommandText = "INSERT INTO clientlist(region, locale, name, gamefolder) VALUES(@region, @locale, @name, @gamefolder)";
                cmd.Parameters.Add(new SQLiteParameter("region", client.Region));
                cmd.Parameters.Add(new SQLiteParameter("locale", client.Locale));
                cmd.Parameters.Add(new SQLiteParameter("name", client.Name));
                cmd.Parameters.Add(new SQLiteParameter("gamefolder", client.GameFolder));

                int i = cmd.ExecuteNonQuery();
                conn.Close();
                return i == 1;
            }
            catch (SQLiteException se)
            {
                MessageBox.Show(se.Message + " \n\n" + se.Source + "\n\n" + se.StackTrace + "\n\n" + se.Data);
                return false;
            }
            catch (ArgumentException ae)
            {
                MessageBox.Show(ae.Message + " \n\n" + ae.Source + "\n\n" + ae.StackTrace + "\n\n" + ae.Data);
                return false;
            }
            catch (Exception ex)
            {
                //Do any logging operation here if necessary  
                MessageBox.Show(ex.Message + "\n\n" + ex.Source + "\n\n" + ex.StackTrace + "\n\n" + ex.Data);
                return false;
            }
        }
 public static bool UpdateClient(Client client, String locale)
 {
     try
     {
         SQLiteConnection conn = new SQLiteConnection("Data Source=settings.db;");
         conn.Open();
         SQLiteCommand cmd = conn.CreateCommand();
         cmd.CommandText = "UPDATE clientlist SET region=@region, name=@name, gamefolder=@gamefolder, locale=@locale WHERE locale=@original_locale";
         cmd.Parameters.Add(new SQLiteParameter("region", client.Region));
         cmd.Parameters.Add(new SQLiteParameter("name", client.Name));
         cmd.Parameters.Add(new SQLiteParameter("locale", client.Locale));
         cmd.Parameters.Add(new SQLiteParameter("gamefolder", client.GameFolder));
         cmd.Parameters.Add(new SQLiteParameter("original_locale", locale));
         int i = cmd.ExecuteNonQuery();
         conn.Close();
         return i == 1;
     }
     catch (SQLiteException se)
     {
         MessageBox.Show(se.Message + " \n\n" + se.Source + "\n\n" + se.StackTrace + "\n\n" + se.Data);
         return false;
     }
     catch (ArgumentException ae)
     {
         MessageBox.Show(ae.Message + " \n\n" + ae.Source + "\n\n" + ae.StackTrace);
         return false;
     }
     catch (Exception ex)
     {
         //Do any logging operation here if necessary  
         MessageBox.Show(ex.Message);
         return false;
     }
 }
        private void Button_Submit_Click(object sender, EventArgs e)
        {
            String folder = TextBox_GameFolder.Text;
            String path = folder + "\\StarCraft II.exe";

            //首先判断有没有选择语言
            if (LanguageList.SelectedIndex == -1)
            {
                MessageBox.Show("尚未选择语言!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                Client client = new Client(LanguageList.SelectedItem.ToString(), TextBox_GameFolder.Text);
                try
                {
                    switch (editMode)
                    {
                        case EditMode.Add:

                            //再检查是不是已创建过该语言的客户端
                            if (Client.IsExsit(LanguageList.SelectedItem.ToString()))
                            {
                                MessageBox.Show("该语言的客户端已经创建过!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }

                            //再检查有没有StarCraft II.exe文件
                            else if (!File.Exists(path))
                            {
                                MessageBox.Show("未找到" + path + "!请检查该目录!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                            else if (ClientDAL.CreateClient(client))
                            {
                                MessageBox.Show("客户端编辑成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                this.Close();
                            }
                            break;
                        case EditMode.Edit:
                            //检查有没有StarCraft II.exe文件
                            if (!File.Exists(path))
                            {
                                MessageBox.Show("未找到" + path + "!请检查该目录!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                            else if (ClientDAL.UpdateClient(client, originalClient.Locale))
                            {
                                MessageBox.Show("客户端编辑成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                this.Close();
                            }
                            break;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + " \n\n" + ex.Source + "\n\n" + ex.StackTrace + "\n\n" + ex.Data, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

        }
 public EditClient(Client client)
 {
     InitializeComponent();
     this.Text = "编辑客户端";
     editMode = EditMode.Edit;
     originalClient = client;
     for (int i = 0; i < Program.languageList.Length; i++)
     {
         if ((client.Region + " - " + client.Name + " - " + client.Locale) == Program.languageList[i])
         {
             this.LanguageList.SelectedIndex = i;
         }
     }
     this.TextBox_GameFolder.Text = client.GameFolder;
 }
 public static Client GetClientByClientListItem(String item)
 {
     String locale = Client.GetLocaleFromClientListItem(item);
     String[] clientStr = ClientDAL.GetClientDataReader(locale);
     if (clientStr != null)
     {
         Client client = new Client();
         client.Name = clientStr[0];
         client.Locale = clientStr[1];
         client.Region = clientStr[2];
         client.GameFolder = clientStr[3];
         return client;
     }
     else return null;
 }