using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Core.Mes.ClientFrameWork;
using Core.Mes.IBaseInterface;
using System.Data;
using System.Runtime.InteropServices;
using Core.XgMes.Client.JGKC.TurnoffSendManager;

namespace Core.XgMes.Client.JGKC.MaterialManager
{
    public partial class AccpetSheet : Mes.ClientFrameWork.FrmBase
    {
        public AccpetSheet()
        {
            InitializeComponent();
        }

        private void Cmb_wzdm_TextChanged(object sender, EventArgs e)
        {
           
        }
      



      


        private void Cmb_wzdm_DoubleClick(object sender, EventArgs e)
        {
            
        }

        private void Cmb_wzdm_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
        {
            FrmMaterialDaioage metaterial = new FrmMaterialDaioage();
            metaterial.StartPosition = FormStartPosition.CenterParent;
            metaterial.ShowDialog();
            Cmb_wzdm.Text = metaterial.strwzdm;
            txt_WZMC.Text = metaterial.strwzmc;
            txt_GGXH.Text = metaterial.strgg;
            txt_JLDW.Text = metaterial.strjldw;
            txt_CZ.Text = metaterial.strcz;
            txt_DZ.Text = metaterial.strdz;
            Cmb_CKDM.Text = metaterial.strckcode;
            cmb_StorageLB.Text = metaterial.strcklb;
            txt_CKMC.Text = metaterial.strckmc;

        }

        private void Cmb_CKDM_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
        {
            FrmDepotDialog depot = new FrmDepotDialog();
            depot.StartPosition = FormStartPosition.CenterParent;
            depot.ShowDialog();
            Cmb_CKDM.Text = depot.strckdm;
            cmb_StorageLB.Text = depot.strcklb;
            txt_CKMC.Text = depot.stckmc;

        }

        private void Cmd_GFCode_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
        {
            FrmProvlderDialog provlder = new FrmProvlderDialog();
            provlder.StartPosition = FormStartPosition.CenterParent;
            provlder.ShowDialog();
            Cmd_GFCode.Text = provlder.strgfdm;
            txt_GYMC.Text = provlder.strgfmc;
        }

        private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
        {
            switch (e.Tool.Key)
            {
                case "Add":
                    Add("ADD");
                    break;
                case "Query":
                    DoQuery();
                    break;
                case "UPDATE":
                    Add("UPDATE");
                    break;
                    break;
                case "Del":
                    Add("Del");
                    break;
                case "Export":
                    Export();
                    break;
                case "Close":
                    this.Close();
                    break;

                    
            }
        }
        private void gd_CK_AfterRowActivate(object sender, EventArgs e)
        {
            try
            {
                if (this.gd_CK.Rows.Count > 0)
                {

       



                    this.txt_BH.Text = Comm.ObjToStr(this.gd_CK.ActiveRow.Cells["PICKING_NO"].Value); //1 领料单号
                    this.Cmb_CKDM.Text = Comm.ObjToStr(this.gd_CK.ActiveRow.Cells["STORAGE_CODE"].Value); //3 仓库代码
                    this.cmb_StorageLB.Text = Comm.ObjToStr(this.gd_CK.ActiveRow.Cells["STORAGE_STYLE"].Value);//4 仓库类别
                    this.txt_CKMC.Text = Comm.ObjToStr(this.gd_CK.ActiveRow.Cells["ISSUE_STORE"].Value);//5 仓库名称
                    this.txt_ylbz.Text = Comm.ObjToStr(this.gd_CK.ActiveRow.Cells["PICKING_NAME"].Value);//6 领料班组
                    this.Cmb_wzdm.Text = Comm.ObjToStr(this.gd_CK.ActiveRow.Cells["MATERIAL_CODE"].Value);//7 物资代码
                    this.txt_WZMC.Text = Comm.ObjToStr(this.gd_CK.ActiveRow.Cells["MATERIAL_NAME"].Value);//8 物资名称
                    this.txt_GGXH.Text = Comm.ObjToStr(this.gd_CK.ActiveRow.Cells["SPET"].Value);//9 规格型号
                    this.txt_JLDW.Text = Comm.ObjToStr(this.gd_CK.ActiveRow.Cells["UNIT"].Value);//10 计量单位
                    this.txt_CZ.Text = Comm.ObjToStr(this.gd_CK.ActiveRow.Cells["MATERIAL"].Value);//11 材质
                    this.txt_DZ.Text = Comm.ObjToStr(this.gd_CK.ActiveRow.Cells["WEIGHT"].Value);//12 单重
                    this.txt_PlanR.Text = Comm.ObjToStr(this.gd_CK.ActiveRow.Cells["SCHEDULER"].Value);///13 计划人
                    this.txt_qlsl.Text = Comm.ObjToStr(this.gd_CK.ActiveRow.Cells["PLEASE_NUM"].Value);///14 请领数量
                    this.txt_Price.Text = Comm.ObjToStr(this.gd_CK.ActiveRow.Cells["REAL_NUM"].Value);//15 实发数量
                    this.txt_Price.Text = Comm.ObjToStr(this.gd_CK.ActiveRow.Cells["PRICE"].Value);//16 单价
                    this.txt_Moneny.Text = Comm.ObjToStr(this.gd_CK.ActiveRow.Cells["MONERY"].Value);//17 金额
                    this.txt_YR.Text = Comm.ObjToStr(this.gd_CK.ActiveRow.Cells["PICKING_RECODER"].Value);//19 领料人
                    this.Cmd_GFCode.Text = Comm.ObjToStr(this.gd_CK.ActiveRow.Cells["GF_CODE"].Value);///20 供方代码
                    this.txt_GYMC.Text = Comm.ObjToStr(this.gd_CK.ActiveRow.Cells["GF_NAME"].Value);///21供方名称
                    this.txt_Remark.Text = Comm.ObjToStr(this.gd_CK.ActiveRow.Cells["REMARK"].Value);///22 备注



                    
 


                 
                   
        








                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
        }






        private void chk_AllowFilter_CheckedChanged(object sender, System.EventArgs e)
        {
            if (this.chk_AllowFilter.Checked)
            {
                this.gd_CK.DisplayLayout.Override.AllowRowFiltering = Infragistics.Win.DefaultableBoolean.True;
            }
            else
            {
                this.gd_CK.DisplayLayout.Override.AllowRowFiltering = Infragistics.Win.DefaultableBoolean.False;

            }

        }
	
        private void Export()
        {
            if (this.gd_CK.Rows.Count > 0)
            {
                Comm.ExPortExcel(this.gd_CK, this.excelExporter);
            }
            else
            {
                MessageBox.Show("无领料单信息数据，不能导出！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

        }
        private void Add(string strMode)
        {
            try
            {
                string strerr = "";

                System.Collections.ArrayList MetarilInfo = new ArrayList();


                if (strMode == "UPDATE")
                {
                    if (txt_BH.Text.Trim().ToString() == "")
                    {
                        MessageBox.Show("领料单号不能为空");
                        return;
                    }
                }
                MetarilInfo.Add(Comm.ObjToStr(this.txt_BH.Text.Trim().ToString()));//1 领料单号
                MetarilInfo.Add(Comm.ObjToStr(Convert.ToDateTime( this.date_YS.Value.ToString().Trim()).ToString("yyyyMMdd")));//2 发料日期
                MetarilInfo.Add(Comm.ObjToStr(this.Cmb_CKDM.Text.ToString().Trim()));//3 仓库代码
                MetarilInfo.Add(Comm.ObjToStr(this.cmb_StorageLB.Text.Trim().ToString()));//4 仓库类别
                MetarilInfo.Add(Comm.ObjToStr(this.txt_CKMC.Text.Trim().ToString()));//5 仓库名称
                MetarilInfo.Add(Comm.ObjToStr(this.txt_ylbz.Text.Trim().ToString()));//6 领料班组



                MetarilInfo.Add(Comm.ObjToStr(this.Cmb_wzdm.Text.Trim().ToString()));//7 物资代码
                MetarilInfo.Add(Comm.ObjToStr(this.txt_WZMC.Text.Trim().ToString()));//8 物资名称
                MetarilInfo.Add(Comm.ObjToStr(this.txt_GGXH.Text.Trim().ToString()));//9 规格型号
                MetarilInfo.Add(Comm.ObjToStr(this.txt_JLDW.Text.Trim().ToString()));//10 计量单位
                MetarilInfo.Add(Comm.ObjToStr(this.txt_CZ.Text.Trim().ToString()));//11 材质
                MetarilInfo.Add(Comm.ObjToStr(this.txt_DZ.Text.Trim().ToString()));//12 单重
                MetarilInfo.Add(Comm.ObjToStr(this.txt_PlanR.Text.Trim().ToString()));//13 计划人


                MetarilInfo.Add(Comm.ObjToStr(this.txt_qlsl.Text.Trim().ToString()));//14 请领数量
                MetarilInfo.Add(Comm.ObjToStr(this.txt_YSS.Text.Trim().ToString()));//15 实发数量
                MetarilInfo.Add(Comm.ObjToStr(this.txt_Price.Text.Trim().ToString()));//16 单价
                MetarilInfo.Add(Comm.ObjToStr(this.txt_Moneny.Text.Trim().ToString()));//17 金额
                MetarilInfo.Add(Comm.ObjToStr(Convert.ToDateTime(this.date_td.Value.ToString().Trim()).ToString("yyyyMMdd")));//18 填单日期
                MetarilInfo.Add(Comm.ObjToStr(txt_YR.Text.Trim().ToString()));//19 领料人


                MetarilInfo.Add(Comm.ObjToStr(this.Cmd_GFCode.Text.Trim().ToString()));//20 供方代码
                MetarilInfo.Add(Comm.ObjToStr(this.txt_GYMC.Text.Trim().ToString()));//21供方名称
                
                MetarilInfo.Add(Comm.ObjToStr(this.txt_Remark.Text.Trim().ToString()));//22 备注
        




                MetarilInfo.Add(ClientCommon._UserInfo.UserName.ToString());//23 操作人
                MetarilInfo.Add(strMode);//19 操作模式
         
           


                object obj = Core.Mes.ClientFrameWork.ClientCommon._RemotingHelp.ExecuteMethod("BJZWWLStuff", "Core.XgMes.Server.JGKC.MaterialManager.Metarial",
                    "PickingSheetAdd", new object[] { MetarilInfo }, out strerr);
                if (obj != null && obj.ToString() == "1")
                {
                    MessageBox.Show("新增成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    DoQuery();
                }
                else
                {
                    MessageBox.Show(strerr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex)
            {
            }
        }
        private void DoQuery()
        {
            string strWhere = "";
            string sql = "";
            if (chk_Time.Checked)
            {
                strWhere += " AND  ISSUE_DATE >='" + Convert.ToDateTime(dte_BeginTime.Value.ToString()).ToString("yyyyMMdd") + "' AND ISSUE_DATE <='" + Convert.ToDateTime(dte_EndTime.Value.ToString()).ToString("yyyyMMdd") + "'";
            }
            if (Chk_CKLB.Checked && txt_ckm.Text.Trim().Length>0)
            {
                strWhere += " AND STORAGE_STYLE LIKE '" + txt_ckm.Text.Trim().ToString() + "%' ";
            }
            if (Chk_WZDM.Checked && txt_wzdm.Text.Trim().Length > 0)
            {
                strWhere += " AND MATERIAL_CODE LIKE '" + txt_wzdm.Text.Trim().ToString() + "%' ";
            }
            if (chk_wzmc.Checked && txt_wz.Text.Trim().Length > 0)
            {
                strWhere += " AND MATERIAL_NAME LIKE '" + txt_wz.Text.Trim().ToString() + "%' ";
            }
            if (chk_Spet.Checked && txt_Spet.Text.Trim().Length > 0)
            {
                strWhere += " AND SPET LIKE '" + txt_Spet.Text.Trim().ToString() + "%' ";
            }

            string err = "";
            sql = "select PICKING_NO,ISSUE_DATE,STORAGE_CODE,STORAGE_STYLE,ISSUE_STORE,PICKING_NAME,MATERIAL_CODE,MATERIAL_NAME, SPET,"
                         + "UNIT,MATERIAL, WEIGHT,SCHEDULER,PLEASE_NUM,REAL_NUM,PRICE, MONERY,FILLING_DATE, PICKING_RECODER,GF_CODE,GF_NAME,RECODER,INPUT_DATE,REMARK     "
                         + " from PICKING_MANAGER where isvalid='1' ";
 
                           
            DataSet ds = (DataSet)ClientCommon._RemotingHelp.ExecuteMethod("BJZWStuff", "Core.XgMes.Server.JGKC.SteelPlateManager.Common", "GetDataSet", new object[] { sql }, out err);
            if (err == "")
            {
                gd_CK.DataSource = ds;
            }
        }

        private void AccpetSheet_Load(object sender, EventArgs e)
        {
            dte_BeginTime.DateTime = DateTime.Now;
            dte_EndTime.DateTime = DateTime.Now;
            date_YS.DateTime = DateTime.Now;
            date_td.DateTime = DateTime.Now;
        }

        private void Chk_CKLB_CheckedChanged(object sender, EventArgs e)
        {
            txt_ckm.Enabled = Chk_CKLB.Checked;
        }

        private void Chk_WZDM_CheckedChanged(object sender, EventArgs e)
        {
            txt_wzdm.Enabled = Chk_WZDM.Checked;
        }

        private void Cmb_CKDM_KeyDown(object sender, KeyEventArgs e)
        {
            
            string err = "";
            string sql = "SELECT BB.MATERIAL_CODE,BB.MATERIAL_NAME,BB.SPEC,BB.MATERIAL,BB.SUBSTANCE,BB.UNITS,CC.DEPOTID,CC.DEPOTNAME,AA.STOCK_CODE FROM MATERIAL_CODE_MANAGE BB,KCJ_STORESMAGNAGER AA,KCJ_DEPOTMAGAGER CC  WHERE BB.MATERIAL_CODE=AA.MATERIALCODE(+) AND AA.STOCK_CODE=CC.DEPOT_LB(+)  "
                        + " AND CC.DEPOTID  like '" + Cmb_CKDM.Text.ToString().Trim() + "' "
                        + " ORDER BY TO_NUMBER(BB.SORT_CODE)  ASC ";
            DataSet ds = (DataSet)ClientCommon._RemotingHelp.ExecuteMethod("BJZWStuff", "Core.XgMes.Server.JGKC.SteelPlateManager.Common", "GetDataSet", new object[] { sql }, out err);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (err == "")
                {
                    Cmb_wzdm.Text = ds.Tables[0].Rows[0]["MATERIAL_CODE"].ToString();
                    txt_WZMC.Text = ds.Tables[0].Rows[0]["MATERIAL_NAME"].ToString();
                    txt_GGXH.Text = ds.Tables[0].Rows[0]["SPEC"].ToString();
                    txt_JLDW.Text = ds.Tables[0].Rows[0]["UNITS"].ToString();
                    txt_CZ.Text = ds.Tables[0].Rows[0]["MATERIAL"].ToString();
                    txt_DZ.Text = ds.Tables[0].Rows[0]["SUBSTANCE"].ToString();
                    Cmb_CKDM.Text = ds.Tables[0].Rows[0]["DEPOTID"].ToString();
                    cmb_StorageLB.Text = ds.Tables[0].Rows[0]["STOCK_CODE"].ToString();
                    txt_CKMC.Text = ds.Tables[0].Rows[0]["DEPOTNAME"].ToString();

                }
            }
            else
            {


                txt_WZMC.Text = "";
                txt_GGXH.Text = "";
                txt_JLDW.Text = "";
                txt_CZ.Text = "";
                txt_DZ.Text = "";
            
                cmb_StorageLB.Text = "";
                txt_CKMC.Text = "";

            }
        }

        private void Cmb_wzdm_KeyDown(object sender, KeyEventArgs e)
        {
           
            string err = "";
            string sql = "SELECT BB.MATERIAL_CODE,BB.MATERIAL_NAME,BB.SPEC,BB.MATERIAL,BB.SUBSTANCE,BB.UNITS,CC.DEPOTID,CC.DEPOTNAME,AA.STOCK_CODE FROM MATERIAL_CODE_MANAGE BB,KCJ_STORESMAGNAGER AA,KCJ_DEPOTMAGAGER CC  WHERE BB.MATERIAL_CODE=AA.MATERIALCODE(+) AND AA.STOCK_CODE=CC.DEPOT_LB(+)  "
                        + " AND BB.MATERIAL_CODE  like '" + Cmb_wzdm.Text.ToString().Trim() + "' "
                        + " ORDER BY TO_NUMBER(BB.SORT_CODE)  ASC ";
            DataSet ds = (DataSet)ClientCommon._RemotingHelp.ExecuteMethod("BJZWStuff", "Core.XgMes.Server.JGKC.SteelPlateManager.Common", "GetDataSet", new object[] { sql }, out err);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (err == "")
                {
                    Cmb_wzdm.Text = ds.Tables[0].Rows[0]["MATERIAL_CODE"].ToString();
                    txt_WZMC.Text = ds.Tables[0].Rows[0]["MATERIAL_NAME"].ToString();
                    txt_GGXH.Text = ds.Tables[0].Rows[0]["SPEC"].ToString();
                    txt_JLDW.Text = ds.Tables[0].Rows[0]["UNITS"].ToString();
                    txt_CZ.Text = ds.Tables[0].Rows[0]["MATERIAL"].ToString();
                    txt_DZ.Text = ds.Tables[0].Rows[0]["SUBSTANCE"].ToString();
                    Cmb_CKDM.Text = ds.Tables[0].Rows[0]["DEPOTID"].ToString();
                    cmb_StorageLB.Text = ds.Tables[0].Rows[0]["STOCK_CODE"].ToString();
                    txt_CKMC.Text = ds.Tables[0].Rows[0]["DEPOTNAME"].ToString();

                }
            }
            else
            {


                txt_WZMC.Text = "";
                txt_GGXH.Text = "";
                txt_JLDW.Text = "";
                txt_CZ.Text = "";
                txt_DZ.Text = "";
                Cmb_CKDM.Text = "";
                cmb_StorageLB.Text = "";
                txt_CKMC.Text = "";

            }
        }

        private void chk_wzmc_CheckedChanged(object sender, EventArgs e)
        {
            txt_wz.Enabled = chk_wzmc.Checked;
        }

        private void chk_Spet_CheckedChanged(object sender, EventArgs e)
        {
            txt_Spet.Enabled=chk_Spet.Checked  ;
        }
    }
}