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

namespace LYFZ.Software.MainBusiness.CameraControlBook.SuperSmallForm
{
    public partial class A_SetProcessAlertSuperSmallForm : LYFZ.Software.UI.CameraControlBook.SuperSmallForm.A_SetProcessAlertSuperSmallForm
    {
        LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
        LYFZ.BLL.BLL_ErpSystemConfigure sgbll = new BLL.BLL_ErpSystemConfigure();
        public A_SetProcessAlertSuperSmallForm()
        {

        }

        /// <summary>
        /// 是否保存
        /// </summary>
        public bool IsSaveed = false;
        /// <summary>
        /// 窗体加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected override void A_SetProcessAlertSuperSmallForm_Shown(object sender, EventArgs e)
        {
            DataTable dt = sgbll.GetProcessMonitorInterfaceManagement();
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    ((CheckBoxEx)((Panel)this.flowLayoutPanel2.Controls["panel_" + dt.Columns[i].ColumnName.Trim()]).Controls["chk_" + dt.Columns[i].ColumnName.Trim()]).Checked = Convert.ToBoolean(dt.Rows[0][i]);
                }
            }
        }
        /// <summary>
        /// 窗体加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected override void A_SetProcessAlertSuperSmallForm_Load(object sender, EventArgs e)
        {
            string ExecuteSql = orbll.GetView_CustomReturnExecuteSql("tb_ErpSystemConfigure", StrWhere: " Sconfig_Code = 'ProcessMonitor_NoShot'", ShowColumnName: "Sconfig_Value");
            ExecuteSql += ";" + orbll.GetView_CustomReturnExecuteSql("tb_ErpSystemConfigure", StrWhere: " Sconfig_Code = 'ProcessMonitor_NoShotIn'", ShowColumnName: "Sconfig_Value");
            ExecuteSql += ";" + orbll.GetView_CustomReturnExecuteSql("tb_ErpSystemConfigure", StrWhere: " Sconfig_Code = 'ProcessMonitor_NoRepair'", ShowColumnName: "Sconfig_Value");
            ExecuteSql += ";" + orbll.GetView_CustomReturnExecuteSql("tb_ErpSystemConfigure", StrWhere: " Sconfig_Code = 'ProcessMonitor_NoSelected'", ShowColumnName: "Sconfig_Value");
            ExecuteSql += ";" + orbll.GetView_CustomReturnExecuteSql("tb_ErpSystemConfigure", StrWhere: " Sconfig_Code = 'ProcessMonitor_NoSelected2'", ShowColumnName: "Sconfig_Value");
            ExecuteSql += ";" + orbll.GetView_CustomReturnExecuteSql("tb_ErpSystemConfigure", StrWhere: " Sconfig_Code = 'ProcessMonitor_NoDesign'", ShowColumnName: "Sconfig_Value");
            ExecuteSql += ";" + orbll.GetView_CustomReturnExecuteSql("tb_ErpSystemConfigure", StrWhere: " Sconfig_Code = 'ProcessMonitor_NoLook'", ShowColumnName: "Sconfig_Value");
            ExecuteSql += ";" + orbll.GetView_CustomReturnExecuteSql("tb_ErpSystemConfigure", StrWhere: " Sconfig_Code = 'ProcessMonitor_NoSend'", ShowColumnName: "Sconfig_Value");
            ExecuteSql += ";" + orbll.GetView_CustomReturnExecuteSql("tb_ErpSystemConfigure", StrWhere: " Sconfig_Code = 'ProcessMonitor_NoBack'", ShowColumnName: "Sconfig_Value");
            ExecuteSql += ";" + orbll.GetView_CustomReturnExecuteSql("tb_ErpSystemConfigure", StrWhere: " Sconfig_Code = 'ProcessMonitor_NoPickup'", ShowColumnName: "Sconfig_Value");
            ExecuteSql += ";" + orbll.GetView_CustomReturnExecuteSql("tb_ErpSystemConfigure", StrWhere: " Sconfig_Code = 'ProcessMonitor_NoSend2'", ShowColumnName: "Sconfig_Value");
            ExecuteSql += ";" + orbll.GetView_CustomReturnExecuteSql("tb_ErpSystemConfigure", StrWhere: " Sconfig_Code = 'ProcessMonitor_NoPickup2'", ShowColumnName: "Sconfig_Value");
            ExecuteSql += ";" + orbll.GetView_CustomReturnExecuteSql("tb_ErpSystemConfigure", StrWhere: " Sconfig_Code = 'ProcessMonitor_SelectNotRefinement'", ShowColumnName: "Sconfig_Value");
            ExecuteSql += ";" + orbll.GetView_CustomReturnExecuteSql("tb_ErpSystemConfigure", StrWhere: " Sconfig_Code = 'ProcessMonitor_RefinementNotDesign'", ShowColumnName: "Sconfig_Value");

            DataSet dtSet = orbll.GetView_Custom(ExecuteSql);

            this.txtNoShot.Text = dtSet.Tables["ds"].Rows[0]["Sconfig_Value"].ToString().Trim();
            this.txtNoShotIn.Text = dtSet.Tables["ds1"].Rows[0]["Sconfig_Value"].ToString().Trim();
            this.txtNoRepair.Text = dtSet.Tables["ds2"].Rows[0]["Sconfig_Value"].ToString().Trim();
            this.txtNoSelected.Text = dtSet.Tables["ds3"].Rows[0]["Sconfig_Value"].ToString().Trim();
            this.txtNoSelected2.Text = dtSet.Tables["ds4"].Rows[0]["Sconfig_Value"].ToString().Trim();
            this.txtNoDesign.Text = dtSet.Tables["ds5"].Rows[0]["Sconfig_Value"].ToString().Trim();
            this.txtNoLook.Text = dtSet.Tables["ds6"].Rows[0]["Sconfig_Value"].ToString().Trim();
            this.txtNoBack.Text = dtSet.Tables["ds7"].Rows[0]["Sconfig_Value"].ToString().Trim();
            this.txtNoSend.Text = dtSet.Tables["ds8"].Rows[0]["Sconfig_Value"].ToString().Trim();
            this.txtNoPickup.Text = dtSet.Tables["ds9"].Rows[0]["Sconfig_Value"].ToString().Trim();
            this.txtNoSend2.Text = dtSet.Tables["ds10"].Rows[0]["Sconfig_Value"].ToString().Trim();
            this.txtNoPickup2.Text = dtSet.Tables["ds11"].Rows[0]["Sconfig_Value"].ToString().Trim();
            if (dtSet.Tables["ds12"].Rows.Count>0)
            {
                this.txtSelectNotRefinement.Text = dtSet.Tables["ds12"].Rows[0]["Sconfig_Value"].ToString().Trim();
            }
            else
            {
                this.txtSelectNotRefinement.Text = "1";
            }

            if (dtSet.Tables["ds13"].Rows.Count > 0)
            {
                this.txtRefinementNotDesign.Text = dtSet.Tables["ds13"].Rows[0]["Sconfig_Value"].ToString().Trim();
            }
            else
            {
                this.txtRefinementNotDesign.Text = "1";
            }

            
        }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected override void butnSave_Click(object sender, EventArgs e)
        {
            DateTime StrTime = SDateTime.Now;
            string StrUserID = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
            List<LYFZ.Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
            LYFZ.Model.Model_ErpSystemConfigure model = null;
            model = sgbll.GetModel("Sconfig_Code", "ProcessMonitor_NoShot");
            model.Sconfig_Value = this.txtNoShot.Text;
            model.Sconfig_CreateDatetime = StrTime;
            model.Sconfig_CreateName = StrUserID;
            clist.Add(sgbll.GetUpdateCommandInfo(model));

            model = sgbll.GetModel("Sconfig_Code", "ProcessMonitor_NoShotIn");
            model.Sconfig_Value = this.txtNoShotIn.Text;
            model.Sconfig_CreateDatetime = StrTime;
            model.Sconfig_CreateName = StrUserID;
            clist.Add(sgbll.GetUpdateCommandInfo(model));

            model = sgbll.GetModel("Sconfig_Code", "ProcessMonitor_NoRepair");
            model.Sconfig_Value = this.txtNoRepair.Text;
            model.Sconfig_CreateDatetime = StrTime;
            model.Sconfig_CreateName = StrUserID;
            clist.Add(sgbll.GetUpdateCommandInfo(model));

            model = sgbll.GetModel("Sconfig_Code", "ProcessMonitor_NoSelected");
            model.Sconfig_Value = this.txtNoSelected.Text;
            model.Sconfig_CreateDatetime = StrTime;
            model.Sconfig_CreateName = StrUserID;
            clist.Add(sgbll.GetUpdateCommandInfo(model));

            model = sgbll.GetModel("Sconfig_Code", "ProcessMonitor_NoSelected2");
            model.Sconfig_Value = this.txtNoSelected2.Text;
            model.Sconfig_CreateDatetime = StrTime;
            model.Sconfig_CreateName = StrUserID;
            clist.Add(sgbll.GetUpdateCommandInfo(model));

            model = sgbll.GetModel("Sconfig_Code", "ProcessMonitor_SelectNotRefinement");
            model.Sconfig_Value = this.txtSelectNotRefinement.Text;
            model.Sconfig_CreateDatetime = StrTime;
            model.Sconfig_CreateName = StrUserID;
            clist.Add(sgbll.GetUpdateCommandInfo(model));

            model = sgbll.GetModel("Sconfig_Code", "ProcessMonitor_RefinementNotDesign");
            model.Sconfig_Value = this.txtRefinementNotDesign.Text;
            model.Sconfig_CreateDatetime = StrTime;
            model.Sconfig_CreateName = StrUserID;
            clist.Add(sgbll.GetUpdateCommandInfo(model));

            model = sgbll.GetModel("Sconfig_Code", "ProcessMonitor_NoDesign");
            model.Sconfig_Value = this.txtNoDesign.Text;
            model.Sconfig_CreateDatetime = StrTime;
            model.Sconfig_CreateName = StrUserID;
            clist.Add(sgbll.GetUpdateCommandInfo(model));

            model = sgbll.GetModel("Sconfig_Code", "ProcessMonitor_NoSend2");
            model.Sconfig_Value = this.txtNoSend2.Text;
            model.Sconfig_CreateDatetime = StrTime;
            model.Sconfig_CreateName = StrUserID;
            clist.Add(sgbll.GetUpdateCommandInfo(model));

            model = sgbll.GetModel("Sconfig_Code", "ProcessMonitor_NoLook");
            model.Sconfig_Value = this.txtNoLook.Text;
            model.Sconfig_CreateDatetime = StrTime;
            model.Sconfig_CreateName = StrUserID;
            clist.Add(sgbll.GetUpdateCommandInfo(model));

            model = sgbll.GetModel("Sconfig_Code", "ProcessMonitor_NoSend");
            model.Sconfig_Value = this.txtNoSend.Text;
            model.Sconfig_CreateDatetime = StrTime;
            model.Sconfig_CreateName = StrUserID;
            clist.Add(sgbll.GetUpdateCommandInfo(model));

            model = sgbll.GetModel("Sconfig_Code", "ProcessMonitor_NoBack");
            model.Sconfig_Value = this.txtNoBack.Text;
            model.Sconfig_CreateDatetime = StrTime;
            model.Sconfig_CreateName = StrUserID;
            clist.Add(sgbll.GetUpdateCommandInfo(model));

            model = sgbll.GetModel("Sconfig_Code", "ProcessMonitor_NoPickup");
            model.Sconfig_Value = this.txtNoPickup.Text;
            model.Sconfig_CreateDatetime = StrTime;
            model.Sconfig_CreateName = StrUserID;
            clist.Add(sgbll.GetUpdateCommandInfo(model));

            model = sgbll.GetModel("Sconfig_Code", "ProcessMonitor_NoPickup2");
            model.Sconfig_Value = this.txtNoPickup2.Text;
            model.Sconfig_CreateDatetime = StrTime;
            model.Sconfig_CreateName = StrUserID;
            clist.Add(sgbll.GetUpdateCommandInfo(model));

           

            List<string> mlist = new List<string>();
            mlist.Add("NoShot_" + this.chk_NoShot.Checked.ToString());
            mlist.Add("NoShotIn_" + this.chk_NoShotIn.Checked.ToString());
            mlist.Add("NoRepair_" + this.chk_NoRepair.Checked.ToString());
            mlist.Add("NoSelected_" + this.chk_NoSelected.Checked.ToString());
            mlist.Add("NoSelected2_" + this.chk_NoSelected2.Checked.ToString());
            mlist.Add("SelectNotRefinement_" + this.chk_SelectNotRefinement.Checked.ToString());
            mlist.Add("RefinementNotDesign_" + this.chk_RefinementNotDesign.Checked.ToString());
            mlist.Add("NoDesign_" + this.chk_NoDesign.Checked.ToString());
            mlist.Add("NoSend2_" + this.chk_NoSend2.Checked.ToString());
            mlist.Add("NoLook_" + this.chk_NoLook.Checked.ToString());
            mlist.Add("NoSend_" + this.chk_NoSend.Checked.ToString());
            mlist.Add("NoBack_" + this.chk_NoBack.Checked.ToString());
            mlist.Add("NoPickup_" + this.chk_NoPickup.Checked.ToString());
            mlist.Add("NoPickup2_" + this.chk_NoPickup2.Checked.ToString());

           

            int IntFalseCount = 0;
            for (int i = 0; i < mlist.Count; i++)
            {
                string[] StrArray = mlist[i].Trim().Split('_');
                if (!Convert.ToBoolean(StrArray[1]))
                { IntFalseCount++; }
            }
            if (IntFalseCount == mlist.Count)
            { MessageBoxCustom.Show("界面设置必须有一项为显示!"); return; }

            if (MessageBoxCustom.Show("确定要保存吗?", "温馨提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
            { return; }

            if (LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist) <= 0)
            { MessageBoxCustom.Show("保存失败!"); return; }
            else
            {
                IsSaveed = true;
                sgbll.UpdateProcessMonitorInterfaceManagement(mlist);
                MessageBoxCustom.Show("保存成功!");
                return;
            }
        }
        /// <summary>
        /// 关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected override void butnColse_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}