using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SLZ_4
{
    public partial class ConfigStorage : Form
    {
        STORAGE_PARAM storageParam;
        public ConfigStorage()
        {
            InitializeComponent();
        }

        public void SetConfig(ref STORAGE_PARAM pStorage)
        {
            storageParam = pStorage;
            textPath.Text = pStorage.sPath;
            checkTxt.Checked = pStorage.bTxt;
            checkCSV.Checked = pStorage.bCSV;
            checkSQL.Checked = pStorage.bSQL;
            checkExcel.Checked = pStorage.bExcel;
        }
        private void buttonPath_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folder = new FolderBrowserDialog();
            folder.ShowDialog();
            textPath.Text = folder.SelectedPath;
        }

        private void buttonSetSQL_Click(object sender, EventArgs e)
        {
            //ConfigSQL configSql = new ConfigSQL();
            //configSql.SetConfig(ref FormMain.formMain.configParam.databaseParam);
            //configSql.ShowDialog();
        }

        private void buttonSet_Click(object sender, EventArgs e)
        {
            storageParam.bTxt = checkTxt.Checked;
            storageParam.bCSV = checkCSV.Checked;
            storageParam.bSQL = checkSQL.Checked;
            storageParam.bExcel = checkExcel.Checked;
            storageParam.sPath = textPath.Text;

            if (textPath.Text.Length <= 0 && (checkTxt.Checked || checkCSV.Checked || checkExcel.Checked))
            {
                MessageBox.Show("请选择存储路径！");
                return;
            }
            FormMain.form.updateStorage(storageParam);
            Config.saveStorage(storageParam);

            MessageBox.Show("保存成功！");
        }

        private void checkSQL_CheckedChanged(object sender, EventArgs e)
        {
            //检查是否已经配置了数据库信息
            //if (checkSQL.Checked)
            //{
            //    if (FormMain.formMain.configParam.databaseParam.sServer.Length <= 0
            //        || FormMain.formMain.configParam.databaseParam.sDBName.Length <= 0
            //        || FormMain.formMain.configParam.databaseParam.sDBUser.Length <= 0
            //        || FormMain.formMain.configParam.databaseParam.sDBPassword.Length <= 0)
            //    {
            //        MessageBox.Show("请先配置数据库信息！");
            //        checkSQL.Checked = false;
            //    }
            //}
        }
    }
}
