using CasunCommon.BaseUI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PMSUI
{
    public partial class CSystemResetForm : CasunForm
    {
        public CSystemResetForm()
        {
            InitializeComponent();
        }

        private void btSystemReset_Click(object sender, EventArgs e)
        {
            //string strMsg = CLanguageManager.LanguageChange("注意初始化后")
            //    + "，"
            //    + CLanguageManager.LanguageChange("所有任务都将删除")
            //    + "，"
            //    + CLanguageManager.LanguageChange("系统将会强制关闭")
            //    + "！";
            //if (MessageBox.Show(strMsg, CLanguageManager.LanguageChange("初始化"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
            //{
            //    CShareData.gs_StopAllThreadFlag = true;
            //    int n;
            //    int Ret = SystemReset(out n);

            //    string strOptLog = string.Format("{0}：time={1},{2}{3}{6}，{4}{5}{6}！"
            //        , CLanguageManager.LanguageChange("系统初始化")
            //        , DateTime.Now
            //        , CLanguageManager.LanguageChange("转存数据")
            //        , n
            //        , CLanguageManager.LanguageChange("删除数据")
            //        , Ret
            //        , CLanguageManager.LanguageChange("条")
            //        );
            //    COperateLog.Instance.InsertOperaterLogAsync(UserID, strOptLog, DateTime.Now);
            //    Process[] process = Process.GetProcesses();
            //    Process currentProcess = Process.GetCurrentProcess();
            //    for (int i = 0; i < process.Count(); i++)
            //    {
            //        if (process[i].ProcessName == currentProcess.ProcessName)
            //        {
            //            process[i].Kill();
            //        }
            //    }
            //    //this.Close();
            //}
        }

        public int SystemReset(out int n)
        {
            n = 0;
            ////List<CasunModelDB.Model.PMS_mid_TaskDataVo> TaskDataList = CasunModelDB.CDBManager.Instance.PMS_mid_TaskData.GetModelList("");
            //List <PmsCoreDB.Model.PMS_mid_TaskBook> TaskDataList = 
            //if (TaskDataList != null && TaskDataList.Count > 0)
            //{
            //    n = TaskDataList.Count;
            //    foreach (CasunModelDB.Model.PMS_mid_TaskDataVo staskData in TaskDataList)
            //    {
            //        PmsCoreDB.DBHost.Instance.TaskBook.trans
            //        CasunModelDB.CDBManager.Instance.TransformTaskDataToHis(staskData.TaskID);
            //    }
            //}
            //else
            //{
            //    n = 0;
            //}


            //List<CasunModelDB.Model.PMS_mid_TaskBookVo> TaskBookList = CasunModelDB.CDBManager.Instance.PMS_mid_TaskBook.GetModelList("");
            //if (TaskBookList != null && TaskBookList.Count > 0)
            //{
            //    foreach (CasunModelDB.Model.PMS_mid_TaskBookVo staskBook in TaskBookList)
            //    {
            //        CasunModelDB.CDBManager.Instance.TransformTaskBookToHis(staskBook.BookID);
            //    }
            //}

            //// 因为表TaskStepBook的 主键是GUID 所以可以这样删除
            //string strSql = " insert into PMS_his_HistoryTaskStepBook select * from PMS_mid_TaskStepBook";
            //if (CasunModelDB.DbHelperSQL.ExecuteSql(strSql) > 0)
            //{
            //    strSql = " delete from PMS_mid_TaskStepBook";
            //    CasunModelDB.DbHelperSQL.ExecuteSql(strSql);
            //}




            return n;
        }

        private void btDeleteRegionTask_Click(object sender, EventArgs e)
        {

        }

        private void CSystemResetForm_Load(object sender, EventArgs e)
        {
            CasunUILib.ButtonHelps(btHelps);

            gp_Opt.Location = new Point(btHelps.Location.X, gp_Opt.Location.Y);

            //CasunUILib.GroupBoxReadModel(gp_Read, PermissionLevel);
            CasunUILib.GroupBoxReadWriteModel(gp_Opt, PermissionLevel);
        }

        private void btHelps_Click(object sender, EventArgs e)
        {
            MessageBox.Show(PMSUI.Config.CConfigManager.gs_FormHelpConfig.GetFormHelp(this.Name));

        }
    }
}
