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

namespace ControlSystem
{
    public partial class FrmHelp :  WeifenLuo.WinFormsUI.Docking.DockContent
    {
        DBOperator dbo = CStaticClass.dbo;
        DBOperator dboM = CStaticClass.dboM;

        string[] bars = new string[60];
        public FrmHelp()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FrmSystemInit.FormInstance.ShowDialog();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FrmLaneTest.FormInstance.ShowDialog();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //if (CStaticClass.testapplyin == 0)
            //{
            //    CStaticClass.testapplyin = 1;
            //}
            //else
            //{
            //    CStaticClass.testapplyin = 0;
            //}
            if (CStaticClass.StopTestLane == true)
            {
                CStaticClass.StopTestLane = false;
               // this.button3.Text = "开始巷道测试中";
            }
            else
            {
                CStaticClass.StopTestLane = true;
               // this.button3.Text = "停止巷道测试";
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
          //  CStaticClass.testapplyin = 0;
        }

        private void button5_Click(object sender, EventArgs e)
        {
           // CStaticClass.tuopanapplyin = 0;
        }

     

        private void button8_Click(object sender, EventArgs e)
        {
            //string qw5 = string.Empty;
            //DataView dv = dbo.ExceSQL("select * from TESTjxdl").Tables[0].DefaultView;
            //int listid = 0;
            
            //for (int i = 0; i < dv.Count; i++)
            //{
            //   qw5 = dv[i]["QW5"].ToString();
            //   DataView dvm= dboM.ExceSQL("select * from STORAGE_MAIN where STOCK_BARCODE ='" + qw5 + "'").Tables[0].DefaultView;
            //   if (dvm.Count > 0)
            //   {
            //       listid = Convert.ToInt32(dvm[0]["STORAGE_ID"]);
            //       dbo.ExceSQL("update TESTjxdl set LIST_id =" + listid + "where QW5 ='" + qw5 + "'");
            //   }
            //   if (i % 1000 == 0)
            //   {
            //       MessageBox.Show("做完一千");
            //   }
                
            //}
            //MessageBox.Show("全部做完");
            
        }

        private void button9_Click(object sender, EventArgs e)
        {
            //string qw5 = string.Empty;
            //DataView dv = dbo.ExceSQL("select * from JXDLHELLO where LIST_id is not null").Tables[0].DefaultView;
            //int listid = 0;
            //int LISTID2 = 0;

            //for (int i = 0; i < dv.Count; i++)
            //{
            //    listid =Convert.ToInt32( dv[i]["LIST_id"]);
            //    DataView dvm = dboM.ExceSQL("select * from STORAGE_LIST where STORAGE_ID  ="+listid+"").Tables[0].DefaultView;
            //    if (dvm.Count > 0)
            //    {
            //        LISTID2 = Convert.ToInt32(dvm[0]["STORAGE_LIST_ID"]);
            //        dbo.ExceSQL("update JXDLHELLO set LIST_ID2 =" + LISTID2 + "where LIST_id ='" + listid + "'");
            //    }
            //    if (i % 1000 == 0)
            //    {
            //        MessageBox.Show("做完一千");
            //    }

            //}
            //MessageBox.Show("全部做完");
        }

        private void button10_Click(object sender, EventArgs e)
        {
            //DataView dv = dboM.ExceSQL("select * from STORAGE_DETAIL").Tables[0].DefaultView;
            //if (dv.Count > 0)
            //{
            //    for (int i = 0; i < dv.Count; i++)
            //    {
            //        string boxbarcode = dv[i]["BOX_BARCODE"].ToString().Trim();
            //        string manbarcode = dv[i]["STORAGE_DETAIL_REMARK"].ToString().Trim();
            //        int STORAGE_DETAIL_ID = Convert.ToInt32(dv[i]["STORAGE_DETAIL_ID"]);
            //        dboM.ExceSQL("update STORAGE_DETAIL set BOX_BARCODE ='" + boxbarcode + "' ,STORAGE_DETAIL_REMARK='" + manbarcode + "' where STORAGE_DETAIL_ID =" + STORAGE_DETAIL_ID);
            //        if (i % 1000 == 0)
            //        {
            //            MessageBox.Show("做完一千");
            //        }

            //    }
            //    MessageBox.Show("全部做完");
            //}
        }

        private void button11_Click(object sender, EventArgs e)
        {
            //DataView dv = dboM.ExceSQL("select * from MANAGE_DETAIL").Tables[0].DefaultView;
            //if (dv.Count > 0)
            //{
            //    for (int i = 0; i < dv.Count; i++)
            //    {
            //        string boxbarcode = dv[i]["BOX_BARCODE"].ToString().Trim();
            //        string manbarcode = dv[i]["MANAGE_DETAIL_REMARK"].ToString().Trim();
            //        int STORAGE_DETAIL_ID = Convert.ToInt32(dv[i]["MANAGE_DETAIL_ID"]);
            //        dboM.ExceSQL("update MANAGE_DETAIL set BOX_BARCODE ='" + boxbarcode + "' ,MANAGE_DETAIL_REMARK='" + manbarcode + "' where MANAGE_DETAIL_ID =" + STORAGE_DETAIL_ID);
            //        if (i % 1000 == 0)
            //        {
            //            MessageBox.Show("做完一千");
            //        }

            //    }
            //    MessageBox.Show("全部做完");
            //}

        }

        private void button12_Click(object sender, EventArgs e)
        {
           // string boxbarcode = string.Empty;
           // int list_id = 0;
           // int count = 40000;
           // DataView dvm = dboM.ExceSQL("select STOCK_BARCODE,STORAGE_LIST_ID from V_STORAGE_LIST where ENTRY_TIME <('2013-01-17') and GOODS_NAME ='周转箱'").Tables[0].DefaultView;
           //if (dvm.Count > 0)
           //{
           //    for (int i = 0; i < dvm.Count; i++)
           //    {
           //        boxbarcode = dvm[i]["STOCK_BARCODE"].ToString();
           //        list_id = Convert.ToInt32(dvm[i]["STORAGE_LIST_ID"]);
           //        dboM.ExceSQL("insert into STORAGE_DETAIL (STORAGE_DETAIL_ID,STORAGE_LIST_ID,BOX_BARCODE,GOODS_BARCODE,STORAGE_DETAIL_REMARK) values (" + count + "," + list_id + ",'" + boxbarcode + "','" + boxbarcode + "','" + boxbarcode + "')");
           //        count += 1;

           //    }
           //    MessageBox.Show("成功");
           //}
        }

        private void button13_Click(object sender, EventArgs e)
        {
            //string cellstr = string.Empty;
            //string cell_code = string.Empty;
            //DataView dvm = dboM.ExceSQL("select distinct CELL_CODE ,goods_id from V_STORAGE_LIST  order by GOODS_ID ").Tables[0].DefaultView;
            //if (dvm.Count > 0)
            //{
            //    for (int i = 0; i < dvm.Count; i++)
            //    {
            //        cell_code = dvm[i]["CELL_CODE"].ToString();
            //        DataView dvmore = dboM.ExceSQL("select * from V_STORAGE_LIST where CELL_CODE = '" + cell_code + "' order by ENTRY_TIME").Tables[0].DefaultView;
            //      if (dvmore.Count > 1)
            //      {
            //          int STORAGE_ID = Convert.ToInt32(dvmore[0]["STORAGE_ID"]);
            //          int STORAGE_LIST_ID = Convert.ToInt32(dvmore[0]["STORAGE_LIST_ID"]);
            //          dboM.ExceSQL("delete from storage_main where STORAGE_ID ="+STORAGE_ID);
            //          dboM.ExceSQL("delete from storage_list where STORAGE_LIST_ID ="+STORAGE_LIST_ID);
            //          dboM.ExceSQL("delete from storage_detail where STORAGE_LIST_ID =" + STORAGE_LIST_ID);
            //      }
            //    }
            //    MessageBox.Show("完成");
            //}

            string strtemp = "delete from t_bak_manage_task where fendtime <'" + DateTime.Now.AddMonths(-2).ToString("yyyy-MM-dd HH:mm:ss") + "'";
        }

        private void button14_Click(object sender, EventArgs e)
        {
           // FrmLogin.FormInstance.ShowDialog();
            FrmConfigManage.FormInstance.ShowDialog();
        }

        private void button15_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("是否清空叠盘机的组垛信息，清空后必须重新组垛?", "操作提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
            {
                dbo.ExceSQL("update T_Base_PLC_Ask set F_BarCode ='" + string.Empty + "' where F_DeviceIndex =14021");
                MessageBox.Show("完成清除");
            }
        }

        private void button16_Click(object sender, EventArgs e)
        {
           // if (MessageBox.Show("是否验证？", "操作提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
           // {
           //     return;
           // }
           //DataView dvv= dboM.ExceSQL("select distinct(n.BOX_BARCODE) from STORAGE_DETAIL n").Tables[0].DefaultView;
           //string record = string.Empty;
           //string boxbarcode = string.Empty;
           //if (dvv.Count > 0)
           //{
           //    for (int i = 0; i < dvv.Count; i++)
           //    {
           //        boxbarcode = dvv[i]["BOX_BARCODE"].ToString();
           //       DataView dvs= dboM.ExceSQL("select * from STORAGE_DETAIL n where  n.BOX_BARCODE ='"+boxbarcode+"'").Tables[0].DefaultView;
           //       if (dvs.Count > 12)
           //       {
           //           record += boxbarcode + "-----";
           //       }
                  
           //    }

           //    MessageBox.Show(record);
           //}

          //  DataView dv = dbo.ExceSQL("select * from T_Base_Route where F_StartDevice =12026 and F_EndDevice >12207 and F_RouteKind =2").Tables[0].DefaultView;
          //for (int i = 0; i < dv.Count; i++)
          //{
          //  //  string sqltest ="SELECT * FROM T_Base_Route_Device WHERE   (F_DeviceIndex =19001 or F_DeviceIndex =16001 ) and F_RouteID =" + Convert.ToInt32(dv[i]["F_RouteID"])+" order by F_SerialNumber";
          //    DataView dvv = dbo.ExceSQL("SELECT * FROM T_Base_Route_Device WHERE   (F_DeviceIndex =19001 or F_DeviceIndex =16001 ) and F_RouteID =" + Convert.ToInt32(dv[i]["F_RouteID"])+" order by F_SerialNumber").Tables[0].DefaultView;
          //    if (dvv.Count == 2)
          //    {
          //        dbo.ExceSQL("update T_Base_Route_Device  set F_DeviceOrder =1 ,F_DeviceIndex =16001 where F_RouteID ="+Convert.ToInt32(dv[i]["F_RouteID"])+" and F_SerialNumber = "+Convert.ToInt32 (dvv[0]["F_SerialNumber"]));
          //        dbo.ExceSQL("update T_Base_Route_Device  set F_DeviceOrder =-1 ,F_DeviceIndex =19001 where F_RouteID =" + Convert.ToInt32(dv[i]["F_RouteID"]) + " and F_SerialNumber = " + Convert.ToInt32(dvv[1]["F_SerialNumber"]));
          //    }
          //}
          //MessageBox.Show("更新完毕");

            DataView DV = dbo.ExceSQL("SELECT * FROM T_Base_Route_Device WHERE F_DeviceIndex =12207 ORDER BY F_RouteID").Tables[0].DefaultView;
            for (int i = 0; i < DV.Count; i++)
            {
                DataView dvv = dbo.ExceSQL("SELECT * FROM T_Base_Route_Device WHERE F_DeviceIndex =12207 and F_RouteID=" + Convert.ToInt32(DV[i]["F_RouteID"])).Tables[0].DefaultView;
                if (dvv.Count == 2)
                {
                    dbo.ExceSQL("delete from T_Base_Route_Device  WHERE F_RouteDeviceIndex  = " + Convert.ToInt32(dvv[1]["F_RouteDeviceIndex"]));
                }
            }
            MessageBox.Show("ok");
        }

        private void button17_Click(object sender, EventArgs e)
        {
            //if (MessageBox.Show("是否停止12026条码扫描任务申请？", "操作提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
            //{
            //    return;
            //}
            //CStaticClass.stopplcask = true;
          
            

            
        }

        private void textBox11_TextChanged(object sender, EventArgs e)
        {

        
        }

        private void button18_Click(object sender, EventArgs e)
        {
          //  StringBuilder sb = new StringBuilder();
          //DataView dv=  dboM.ExceSQL("select * from record_detail where record_list_id =9704").Tables[0].DefaultView;
          //if (dv.Count > 0)
          //{
          //    for (int i = 0; i < dv.Count; i++)
          //    {
          //        bars[i] = dv[i]["goods_barcode"].ToString();
          //        sb.Append(bars[i]).Append("**");
          //    }
              
          //}
          //string s = sb.ToString();
          //this.button18.Enabled = false;
        }

        
        private void button18_Click_1(object sender, EventArgs e)
        {
           // CStaticClass.stopplcask = false;
           
        }

        private void button19_Click(object sender, EventArgs e)
        {
            FrmBarcode.Formstatnce.ShowDialog();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            CStaticClass.isDisassembleTask = true;
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
           // FrmSystemInit.FormInstance.ShowDialog();
            FrmBarcode.Formstatnce.ShowDialog();
        }

        private void button3_Click_1(object sender, EventArgs e)
        {
                  if (CStaticClass.StopTestLane == true)
            {
                CStaticClass.StopTestLane = false;
                this.button3.Text = "开始巷道测试中";
            }
            else
            {
                CStaticClass.StopTestLane = true;
                this.button3.Text = "停止巷道测试";
            }
        }

        private void button4_Click_1(object sender, EventArgs e)
        {
            FrmConfigManage.FormInstance.ShowDialog();
        }

        private void button5_Click_1(object sender, EventArgs e)
        {
           // dbo.ExceSQL ("select * from t_mon")
        }




    }
}