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

namespace GcDevicePc
{
    public delegate void SaveAsMethodFile(string filename);

    public partial class SaveAsWin : Form
    {
        public event SaveAsMethodFile SaveInI;
        public SaveAsWin()
        {
            InitializeComponent();
        }

        bool VerifyName()
        {
            string strtmp;
            DirectoryInfo MethodDir = new DirectoryInfo(globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.MethodFolder);
            foreach (FileInfo file in MethodDir.GetFiles("*.ini"))
            {
                strtmp = this.newmethodname.Text + ".ini";
                if (strtmp == file.Name)
                {
                    return false;
                }
            }
            return true;
        }

        private void newmethodname_TextChanged(object sender, EventArgs e)
        {
            if (VerifyName())
            {
                this.promptlabel.Text = "文件名可用";
                this.promptlabel.ForeColor = Color.Green;
              //  this.prompt.Text = "";
            }
            else
            {
                this.promptlabel.Text = "文件名存在";
                this.promptlabel.ForeColor = Color.Red;
              //  this.prompt.Text = "ps:如文件存在，会更新原有状态";
            }

            if (this.newmethodname.Text == "")
            {
                this.promptlabel.Text = "";
            }
        }

        private void savebtn_Click(object sender, EventArgs e)
        {
            string filename = this.newmethodname.Text + ".ini";
            filename = System.IO.Path.Combine(globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.MethodFolder, filename);
            try
            {
                SaveInI(filename);
            }
            catch
            {

            }
                          
            this.Close();
        }

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



    }
}
