using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Data;
using System.Data.SqlClient;

using Sybase.DataWindow;
using TXSoft.Common;
using TXSoft.ExtPB;
using TXSoft.DataStore;
using A8ERP;
using System.Text.RegularExpressions;
using A8ERP.Common;
using A8erp.Cache;

namespace A8ERP.CaiGou.Base
{
    public partial class W_CaiGou_PeiHuoDan
    {

         protected string dw_yw_cg_list = string.Empty;     




         protected string tableNameHz = string.Empty;
         protected string tableNameMx = string.Empty;
         protected string flag = "CZ";
         protected string cg_fs_dwChild = string.Empty;
         protected string dw_yw_cg_top_title = string.Empty; // 入（退）标题
         protected string dw_yw_cg_top_title_init_djlx = string.Empty;// 入（退）默认值 
         protected bool isHaveKc = true;
         protected string curFormPzh = "";//外边凭证反调
         protected string curQTPzh = "";


        //wf



         public W_CaiGou_PeiHuoDan()
        {
                 
        }

        public override void OnLoad()
        {
            
            base.OnLoad();
            
            
                ttToolStripMenuItem.Visible = true;
            
            #region 外来凭证打开
            if (Request["curFormPzh"] != null)
            {
                curFormPzh = Request["curFormPzh"].ToString();
            }
            this.SetParm("curFormPzh", curFormPzh);
            #endregion

            if (Request["curQTPzh"] != null)
            {
                curQTPzh = Request["curQTPzh"].ToString();
                this.SetParm("curQTPzh", curQTPzh);
            }
            this.SetParm("tableNameHz", "yw_cg_tzdhz");
            this.SetParm("tableNameMx", "yw_cg_tzdmx");
        

            if (string.IsNullOrEmpty(cg_fs_dwChild))
            {
                cg_fs_dwChild = "CG_DDFS";
            }

            dw_hz.DataStore.DataWindowObject = "dw_yw_cg_phdhz_list_cx";
            dw_mx_top.DataStore.DataWindowObject = "dw_yw_cg_phdmx_top";
            dw_mx.DataStore.DataWindowObject = "dw_yw_cg_phdmx_list";
            base.Dw_UserPerMission = dw_mx;
            #region 每页显示条数&查询天数

            string curDayAndPageSize = DBHelp.GetDayAndPageSize(this.FunctionID,"DB");

            string curPageSize = curDayAndPageSize.Split('#')[1];
            this.dw_hz.PageSize = Convert.ToInt32(curPageSize);

            // 查询天数
            string seldays = curDayAndPageSize.Split('#')[0];
            this.SetParm("seldays", seldays.ToString());

            
            this.tabpage_1.Text="采购通知单明细";
            this.tabpage_2.Text = "采购通知单汇总";
            dw_yw_cg_top_title = "采购通知单";
            #endregion

            if (!string.IsNullOrEmpty(dw_yw_cg_top_title))
            {
                this.SetParm("dw_yw_cg_top_title_value", dw_yw_cg_top_title);
            }
            if (string.IsNullOrEmpty(dw_yw_cg_top_title_init_djlx))
            {
                dw_yw_cg_top_title_init_djlx = "3";  
            }
            this.SetParm("dw_yw_cg_top_title_init_djlx_value", dw_yw_cg_top_title_init_djlx); 
            //dw_hz.Retrieve(dw_yw_cg_top_title_init_djlx, A8ERP.AppService.GetUserID());
            string yhbh = A8ERP.AppService.GetUserID();
            this.SetParm("curYhbh", yhbh);
            this.SetParm("curQxlx", "ls");
            //dw_ls_flda.Retrieve("X");

            DataWindowChild dwc = dw_mx.GetChild("spkh");
            //dwc.SetTransaction(this.AdoTransaction);
            //dwc.Retrieve("%");

            DataWindowChild idwc_ys_child = dw_mx.GetChild("ysbh");
            dwc.SetTransaction(this.AdoTransaction);

            dwc = dw_mx.GetChild("bxbh");
            dwc.SetTransaction(this.AdoTransaction);

            dwc = dw_mx_top.GetChild("gysbh");
            dwc.SetTransaction(this.AdoTransaction);
            dwc.Retrieve("%", yhbh);

            dwc = dw_mx_top.GetChild("xxly");
            dwc.SetTransaction(this.AdoTransaction);
            dwc.Retrieve("XXLY");

            dwc = dw_mx_top.GetChild("bmbh");
            dwc.SetTransaction(this.AdoTransaction);
            dwc.Retrieve("%", yhbh, "cg");

            dwc = dw_mx_top.GetChild("cgfs");
            dwc.SetTransaction(this.AdoTransaction);
            dwc.Retrieve(cg_fs_dwChild);       // 订单方式的下拉框。

            dwc = dw_mx_top.GetChild("cgy");
            dwc.SetTransaction(this.AdoTransaction);
            dwc.Retrieve("%", yhbh, "cg");

            dwc = dw_mx.GetChild("rklx");
            dwc.SetTransaction(this.AdoTransaction);
            dwc.Retrieve("rklx");

            dw_tmjqfs.Retrieve();//条码扫描截取方式。。  
            string FormatPzhAndValue = AppService.GetYwFormatBH(AppService.GetUserID(), this.FunctionID);
            if (FormatPzhAndValue != null && FormatPzhAndValue != "")
            {
                this.SetParm("format_pzh", FormatPzhAndValue.Split('&')[0].ToString());
                AppService.GetYwFormat(dw_hz, FormatPzhAndValue.Split('&')[1].ToString());
            }

            

            this.SetParm("flag", flag);
            this.SetParm("curUserId", AppService.GetUserID().ToString());
            this.SetParm("curBmbhAndBmmc", new DBHelp().GetCurrBusinessDefaultBmbhAndBmmc(this.FunctionID));
            this.SetParm("RowAndCol", AppService.Get35HangAndLie());// 35列的表头的行和列
            string curRowAndCol = Common.DWServiceHelp.GetCmBtRowAndCol();
            this.SetParm("curRowAndCol", curRowAndCol);
            this.SetParm("curJqm", AppService.GetJqm());
            this.SetParm("curUserGroupId", AppService.GetUser().GroupId);//权限组
            //this.SetParm("zxgMrbm")

              if ("CZ".Equals(flag))
             {
                 ddlb_2.Visible = true;
             }

              ddlb_2.Text = "未入库";


             #region  处理标题35列

             if ("1".Equals(AppService.GetDbSfxsRfkc()))
             {
                 Common.DWServiceHelp.Add35CmColShowDbRfkc(dw_mx, isHaveKc);
             }
             else
             {
                 Common.DWServiceHelp.Add35CmCol(dw_mx, isHaveKc);
             }
             
             #endregion

             double jqd = 0;
             string csmc = AppService.GetXiTongCanShu("CG", "YW_JQD", "csmc");
             string jqw = AppService.GetXiTongCanShu("CG", "YW_JQD", "bzxx");



             if (csmc == "0")
             {
                 jqd = Convert.ToDouble(jqw) * 0.1;
             }
             else if (csmc == "1")
             {
                 jqd = Convert.ToDouble(jqw) * 0.01;
             }
             else if (csmc == "2")
             {
                 jqd = Convert.ToDouble(jqw) * 0.001;
             }
             else if (csmc == "3")
             {
                 jqd = Convert.ToDouble(jqw) * 0.0001;
             }

             string bxshow = "";
             object bzqybz = CacheHelp.GetDataTable("DA_SP_BXBT").Rows[0]["qybz"];

             if (bzqybz != null)
             {
                 bxshow = CacheHelp.GetDataTable("DA_SP_BXBT").Rows[0]["qybz"].ToString();
             }
             this.SetParm("curJqd", jqd.ToString());
             this.SetParm("curJqw", csmc.ToString());
             this.SetParm("bxshow", bxshow.ToString());
            
             //来源于首页
             string curBmbh = Request["curParam"];
             string curGysbh = Request["curParam1"];
             this.SetParm("curBmbh", curBmbh);
             this.SetParm("curGysbh", curGysbh);



             //--------------------打印----------------------------
             this.SetParm("curFunctionId", this.FunctionID);
             this.SetParm("cur35ColString", A8ERP.Common.DWServiceHelp.GetCMByString1());
             dw_print.AllowCreate = true;
             dw_print.AllowRetrieve = true;
             dw_print.AllowSetFullState = true;
             dw_proxy.AllowCreate = true;
             dw_proxy.AllowRetrieve = true;
             dw_proxy.AllowSetFullState = true;

             var curJson = (AppService.GetSpCmzJson());

             this.SetParm("curJson", curJson);
             //--------------------打印结束-------------------------
            if (this.Page != null)
            {
                this.Page.ClientScript.RegisterClientScriptInclude("W_CaiGou_PeiHuoDan", "/CaiGou/Base/W_CaiGou_PeiHuoDan.win.js?JSV=" + AppService.GetJSVesion());
              
                this.Page.ClientScript.RegisterClientScriptInclude("OpenWindowQueryBase", "/DangAn/Base/OpenWindowQueryBase.win.js?JSV=" + AppService.GetJSVesion());
                this.Page.ClientScript.RegisterClientScriptInclude("OpenWindowSimpleChoseBase", "/DangAn/Base/OpenWindowSimpleChoseBase.win.js?JSV=" + AppService.GetJSVesion());
                this.Page.ClientScript.RegisterClientScriptInclude("W_CaiGou_ChaXun", "/CaiGou/Base/W_CaiGou_ChaXun.win.js?JSV=" + AppService.GetJSVesion());
                this.Page.ClientScript.RegisterClientScriptInclude("W_HYHKDR", "/import/W_HYHKDR.win.js?JSV=" + AppService.GetJSVesion());
                this.Page.ClientScript.RegisterClientScriptInclude("W_TXTDR", "/import/W_TXTDR.win.js?JSV=" + AppService.GetJSVesion());
                this.Page.ClientScript.RegisterClientScriptInclude("W_ScanImport", "/DangAn/ScanImport/W_ScanImport.win.js?JSV=" + AppService.GetJSVesion());
                //this.Page.ClientScript.RegisterClientScriptInclude("W_PiFaMaiDuanTiXing_List", "/PiFa/PiFaBase/W_PiFaMaiDuanTiXing_List.win.js?JSV=" + AppService.GetJSVesion());
                this.Page.ClientScript.RegisterClientScriptInclude("W_DB_Cysl_list", "/PiFa/PiFaBase/W_DB_Cysl_list.win.js");
                this.Page.ClientScript.RegisterClientScriptInclude("W_PiFa_Lsrkd", "/PiFa/PiFaBase/W_PiFa_Lsrkd.win.js?JSV=" + AppService.GetJSVesion());
                this.Page.ClientScript.RegisterClientScriptInclude("W_QD_PH_FenJian_List", "/PiFa/PiFaBase/W_QD_PH_FenJian_List.win.js?JSV=" + AppService.GetJSVesion());
                this.Page.ClientScript.RegisterClientScriptInclude("W_PH_FenJian_List", "/CaiGou/Base/W_PH_FenJian_List.win.js?JSV=" + AppService.GetJSVesion());
                this.Page.ClientScript.RegisterClientScriptInclude("W_PH_HeJia_List", "/CaiGou/Base/W_PH_HeJia_List.win.js?JSV=" + AppService.GetJSVesion());
                this.Page.ClientScript.RegisterClientScriptInclude("W_KC_Dj_PIC", "/KuCun/TongJiFenXi/W_KC_Dj_PIC.win.js?JSV=" + AppService.GetJSVesion());

            }
            this.IsRegisterScriptFile = false;
            //设置业务基础价格取价方式
            if (!"ERROR".Equals(AppService.GetQjfs()))
                this.SetParm("QJFS", AppService.GetQjfs()); 
          

            this.SetParm("GnqxStr", this.GnqxStr);// 权限传到前台给右键使用。
            if (this.GnqxStr != null)
            {
                //修改权限
                if ((this.GnqxStr).ToString().IndexOf("btn_Edit") < 0)
                {
                    this.btn_Save.Visible = false;
                }
                //单据复制权限
                if ((this.GnqxStr).ToString().IndexOf("rbn_djfz") < 0)
                {
                    this.rbn_djfz.Enabled = false;
                }
                //单据粘贴权限
                if ((this.GnqxStr).ToString().IndexOf("rbn_djzt") < 0)
                {
                    this.rbn_djzt.Enabled = false;
                }
                //单据导出权限
                if ((this.GnqxStr).ToString().IndexOf("rbn_dcel") < 0)
                {
                    this.btn_Export.Enabled = false;
                }
                //excel导入权限
                if ((this.GnqxStr).ToString().IndexOf("rbn_drcel") < 0)
                {
                    this.rbn_drcel.Enabled = false;
                }
            }
            string curjgqx = base.ColumnQxStr;
            if (curjgqx.IndexOf("jj") != -1)
            {
                dw_mx.Modify("jsjze.visible='0' jj.visible='0' ");
                dw_hz.Modify("zjje.visible='0'  ");
            }
            if (curjgqx.IndexOf("zkl") != -1)
            {
                dw_mx.Modify("zkl.visible='0'  ");
            }
            dw_hz.ClickHeaderSort = true;
            dw_mx.ExportProcessSparse = false;
            A8ERP.Common.DWServiceHelp.AddReportService(dw_hz);
        }
    }

}
