using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using GcDevicePc.Common;

namespace GcDevicePc
{
    public partial class SaveWin : Form
    {
        private string filefolder;
        private int filetype;  //0-配置 1-方法 2-批处理

        public SaveWin()
        {
            InitializeComponent();
        }

        public SaveWin(String StartFolder, int flag)
        {
            InitializeComponent();

            this.filefolder = StartFolder;
            this.filetype = flag;
        }

        private bool VerifyName()
        {
            string strtmp;
            DirectoryInfo MethodDir = new DirectoryInfo(this.filefolder);
            foreach (FileInfo file in MethodDir.GetFiles("*.ini"))
            {
                strtmp = this.usefilename.Text + ".ini";
                if (strtmp == file.Name)
                {
                    return false;
                }
            }
            return true;
        }

        private void usefilename_TextChanged(object sender, EventArgs e)
        {
            if (VerifyName())
            {
                this.warninfo.Text = "文件名可用";
                this.warninfo.ForeColor = Color.Green;
            }
            else
            {
                this.warninfo.Text = "文件名存在";
                this.warninfo.ForeColor = Color.Red;
            }

            if (this.usefilename.Text == "")
            {
                this.warninfo.Text = "";
            }
        }

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

        private void addfile_Click(object sender, EventArgs e)
        {
            if (filetype == 2)
            {
                if (!String.IsNullOrEmpty(this.usefilename.Text))
                {
                    RunTableHelper addfile = new RunTableHelper(filefolder, this.usefilename.Text + ".ini");
                    addfile.SaveRunTable();
                }
            }

        }

        
    }
}
