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;


namespace A8ERP.CaiWu.JinHuoFuKuanDan
{
    public partial class W_YW_LIST
    {
        string curpzh = string.Empty;
        string ywflag = string.Empty;
        string curJqdbm = "0";//是否精确到部门
        string curywlx = string.Empty;
        public W_YW_LIST()
        {

        }
        public override void OnLoad()
        {
            base.OnLoad();
            string yhbh = A8ERP.AppService.GetUserID();
            this.SetParm("UserId", yhbh);
            DataWindowChild dwc;
            //DataTable dt = null;
            //DBHelp db = new DBHelp();
            string qybz = "";
            //dt = db.QueryRDataTable(" select qybz from da_qj_csb where csfl='XTCS' AND csbh='SFQYYGQX' ");
            //int sfqy = dt.Rows.Count;
            //if (sfqy > 0)
            //{
            //    qybz = dt.Rows[0]["qybz"].ToString();
                
            //}
            qybz = AppService.GetXiTongCanShu("SFQYYGQX", "XTCS", "qybz");
            //db.Close();
            //dt.Dispose();
            curJqdbm = AppService.GetXiTongCanShu("gys_jqdbm", "cw_jqdbm", "qybz");
            if (Request["curpzh"] != null)
            {
                curpzh = Request["curpzh"].ToString();
                curywlx = Request["curywlx"].ToString().Substring(0, 4);
                ywflag = curpzh.Substring(0, 3);
                if (curywlx == "零售业务")
                {
                    dw_1.DataStore.DataWindowObject = "dw_yw_lingshou_hz_edit";
                    dw_2.DataStore.DataWindowObject = "dw_yw_lingshou_mx";
                    dw_1.Retrieve(curpzh);
                    dw_2.Retrieve(curpzh);
                    //A8ERP.Common.DWServiceHelp.AddReportService(dw_1);
                    string curBxModify = A8ERP.Common.DWServiceHelp.ControlBanXing();
                    dw_2.Modify(curBxModify);
                    dwc = dw_2.GetChild("spkh");
                    dwc.SetTransaction(this.AdoTransaction);
                    // dwc.Retrieve("%"); 
                    dwc = dw_2.GetChild("ysbh");
                    dwc.SetTransaction(this.AdoTransaction);

                    dwc = dw_2.GetChild("bxbh");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc = dw_2.GetChild("lsfs");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("%");
                    dwc = dw_1.GetChild("bmbh");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("%", AppService.GetUserID(), "lingshou");
                    dwc = dw_1.GetChild("dgy");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve(AppService.GetUserID(), qybz, "%");
                    dwc = dw_2.GetChild("yyyh");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve(AppService.GetUserID(), qybz, "%");
                   
                }
                else{
               
                #region 批发出库和入库业务
                //批发
                if ("PF".Equals(ywflag.Substring(0, 2)) || "PT".Equals(ywflag.Substring(0, 2)))
                {

                    dw_1.DataWindowObject = "dw_yw_pf_rkdmx_top";
                    dw_2.DataWindowObject = "dw_yw_pf_rkdmx_list";
                    dw_1.Retrieve(curpzh);
                    dw_2.Retrieve(curpzh);
                    dwc = dw_1.GetChild("cgy");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("%", yhbh, "pf");
                    dwc = dw_1.GetChild("fklx");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("FKLX");
                    dwc = dw_1.GetChild("fhlx");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("fhlx");
                    dwc = dw_1.GetChild("cgfs");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("CG_CGFS");
                    dwc = dw_1.GetChild("skfs");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("skfs");
                    sc_1.SplitterDistance = 150;
                    if ("PF".Equals(ywflag.Substring(0, 2)))
                    {
                        dw_1.Modify("title_t.Text='批发出库单'");
                    }
                    else
                    {
                        dw_1.Modify("title_t.Text='批发退货入库单'");
                    }
                    if (curJqdbm == "1")
                    {
                        dw_1.Modify("khsdjy.visible='0'  khljqk.visible='0' ");
                        dw_1.Modify("sdjy.visible='1'  ljqk.visible='1' ");
                    }
                    else
                    {
                        dw_1.Modify("sdjy.visible='0' ljqk.visible='0' ");
                        dw_1.Modify("khsdjy.visible='1' khljqk.visible='1' ");
                    }
                    Add35CmCol(true);
                }
                #endregion

                #region 连锁出库和入库业务
                //批发
                else if ("LC".Equals(ywflag.Substring(0, 2)) || "LT".Equals(ywflag.Substring(0, 2)))
                {

                    dw_1.DataWindowObject = "dw_yw_ls_rkdmx_top";
                    dw_2.DataWindowObject = "dw_yw_ls_rkdmx_list";
                    dw_1.Retrieve(curpzh);
                    dw_2.Retrieve(curpzh);
                    dwc = dw_1.GetChild("cgy");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("%", yhbh, "pf");
                    dwc = dw_1.GetChild("fklx");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("FKLX");
                    dwc = dw_1.GetChild("fhlx");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("fhlx");
                    dwc = dw_1.GetChild("cgfs");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("CG_CGFS");
                    dwc = dw_1.GetChild("skfs");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("skfs");
                    sc_1.SplitterDistance = 150;
                    if ("LC".Equals(ywflag.Substring(0, 2)))
                    {
                        dw_1.Modify("title_t.Text='连锁出库单'");
                    }
                    else
                    {
                        dw_1.Modify("title_t.Text='连锁退货入库单'");
                    }
                    if (curJqdbm == "1")
                    {
                        dw_1.Modify("khsdjy.visible='0'  khljqk.visible='0' ");
                        dw_1.Modify("sdjy.visible='1'  ljqk.visible='1' ");
                    }
                    else
                    {
                        dw_1.Modify("sdjy.visible='0' ljqk.visible='0' ");
                        dw_1.Modify("khsdjy.visible='1' khljqk.visible='1' ");
                    }
                    Add35CmCol(true);
                }
                #endregion
                #region 渠道出库和入库业务
                else if ("QC".Equals(ywflag.Substring(0, 2)) || "QT".Equals(ywflag.Substring(0, 2)))
                {

                    dw_1.DataWindowObject = "dw_yw_qd_rkdmx_top";
                    dw_2.DataWindowObject = "dw_yw_qd_rkdmx_list";
                    dw_1.Retrieve(curpzh);
                    dw_2.Retrieve(curpzh);
                    dwc = dw_1.GetChild("cgy");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("%", yhbh, "pf");
                    dwc = dw_1.GetChild("fklx");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("FKLX");
                    dwc = dw_1.GetChild("fhlx");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("fhlx");
                    dwc = dw_1.GetChild("cgfs");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("CG_CGFS");
                    dwc = dw_1.GetChild("skfs");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("skfs");
                    sc_1.SplitterDistance = 150;
                    if ("QC".Equals(ywflag.Substring(0, 2)))
                    {
                        dw_1.Modify("title_t.Text='渠道出库单'");
                    }
                    else
                    {
                        dw_1.Modify("title_t.Text='渠道退货入库单'");
                    }
                    if (curJqdbm == "1")
                    {
                        dw_1.Modify("khsdjy.visible='0'  khljqk.visible='0' ");
                        dw_1.Modify("sdjy.visible='1'  ljqk.visible='1' ");
                    }
                    else
                    {
                        dw_1.Modify("sdjy.visible='0' ljqk.visible='0' ");
                        dw_1.Modify("khsdjy.visible='1' khljqk.visible='1' ");
                    }
                    Add35CmCol(true);
                }
                #endregion

                #region 进货付款单
                //进货付款单
                else if ("FK".Equals(ywflag.Substring(0, 2)))
                {

                    dw_1.DataWindowObject = "da_cw_jhfkd_top";
                    dw_2.DataWindowObject = "da_cw_jhfkd_mx";
                    dw_1.Retrieve(curpzh);
                    dw_2.Retrieve(curpzh, curJqdbm);
                    dwc = dw_1.GetChild("gysbh");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("%", A8ERP.AppService.GetUserID());
                    dwc = dw_1.GetChild("bmbh");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("%", A8ERP.AppService.GetUserID(), "cw");

                    dwc = dw_1.GetChild("fkfs");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("skfs");       // 订单方式的下拉框。 
                    dwc = dw_1.GetChild("ywy");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("%", A8ERP.AppService.GetUserID(), "cw");
                   // dwc.Retrieve("%", A8ERP.AppService.GetUserID());
                    dwc = dw_1.GetChild("fyzh");
                    dwc.SetTransaction(this.AdoTransaction);
                    dw_1.Modify("title_t.Text='进货付款单'");

                }
                #endregion
                #region 进货费用单
                //进货费用单
                else if ("JF".Equals(ywflag.Substring(0, 2)))
                {
                    dw_1.DataWindowObject = "da_cw_jhfyd_top";
                    dw_2.DataWindowObject = "da_cw_jhfyd_mx";
                    dw_1.Retrieve(curpzh);
                    dw_2.Retrieve(curpzh, curJqdbm);
                    dwc = dw_1.GetChild("gysbh");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("%", A8ERP.AppService.GetUserID());
                    dwc = dw_1.GetChild("bmbh");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("%", A8ERP.AppService.GetUserID(), "cw");

                    dwc = dw_1.GetChild("fkfs");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("skfs");       // 订单方式的下拉框。


                    dwc = dw_1.GetChild("zdr");
                    dwc.SetTransaction(this.AdoTransaction);
                    //dwc.Retrieve("%", A8ERP.AppService.GetUserID());
                    dwc.Retrieve("%", A8ERP.AppService.GetUserID(), "cw");
                    //dwc = dw_1.GetChild("ffkm");
                    //dwc.SetTransaction(this.AdoTransaction);
                    //dwc.Retrieve("%");

                    dwc = dw_1.GetChild("fyzh");
                    dwc.SetTransaction(this.AdoTransaction);

                    dw_1.Modify("title_t.Text='进货费用单'");

                }
                #endregion
                #region  现金银行收入凭证
                //现金银行收入凭证
                else if ("SR".Equals(ywflag.Substring(0, 2)))
                {
                    if (ywflag.Substring(2, 1).Equals("X"))
                    {
                        dw_1.DataWindowObject = "da_cw_xjsr_mx_top";
                        dw_2.DataWindowObject = "da_cw_xjsr_mx_new";
                        dw_1.Retrieve(curpzh);
                        dw_2.Retrieve(curpzh);
                        dwc = dw_1.GetChild("bmbh");
                        dwc.SetTransaction(this.AdoTransaction);
                        dwc.Retrieve("%", A8ERP.AppService.GetUserID(), "cw");
                        dwc = dw_1.GetChild("xjzh");
                        dwc.SetTransaction(this.AdoTransaction);
                        dwc = dw_1.GetChild("zdr");
                        dwc.SetTransaction(this.AdoTransaction);
                        dwc.Retrieve("%", A8ERP.AppService.GetUserID(),"hy");
                        dwc = dw_1.GetChild("jbr");
                        dwc.SetTransaction(this.AdoTransaction);
                        dwc.Retrieve("%", A8ERP.AppService.GetUserID(), "hy");
                        dwc = dw_2.GetChild("km");
                        dwc.SetTransaction(this.AdoTransaction);
                        dwc.Retrieve("%");
                        dw_1.Modify("title_t.Text='现金银行收入凭证'");
                    }
                    else//老版本收入
                    {

                        dw_1.DataWindowObject = "dw_cw_xjsr_top";
                        dw_2.DataWindowObject = "dw_cw_xjsr_mx";
                        dw_1.Retrieve(curpzh);
                        dw_2.Retrieve(curpzh);
                        dwc = dw_2.GetChild("sfkm");
                        dwc.SetTransaction(this.AdoTransaction);
                        dwc.Retrieve("001");
                        dwc = dw_1.GetChild("zdr");
                        dwc.SetTransaction(this.AdoTransaction);
                        dwc.Retrieve("%", yhbh, "hy");
                        sc_1.SplitterDistance = 150;
                        if (curJqdbm == "1")
                        {
                            dw_1.Modify("khsdye.visible='0'  khbdye.visible='0' ");
                            dw_1.Modify("sdye.visible='1'  bdye.visible='1' ");
                        }
                        else
                        {
                            dw_1.Modify("sdye.visible='0' bdye.visible='0' ");
                            dw_1.Modify("khsdye.visible='1' khbdye.visible='1' ");
                        }

                    }
                }
                #endregion
                #region 支出凭证
                //支出凭证
                else if ("ZC".Equals(ywflag.Substring(0, 2)))
                {
                    if (ywflag.Substring(2, 1).Equals("X"))
                    {
                        dw_1.DataWindowObject = "da_cw_xjzc_top";
                        dw_2.DataWindowObject = "da_cw_xjzc_mx_new";
                        dw_1.Retrieve(curpzh);
                        dw_2.Retrieve(curpzh);
                        dwc = dw_1.GetChild("bmbh");
                        dwc.SetTransaction(this.AdoTransaction);
                        dwc.Retrieve("%", A8ERP.AppService.GetUserID(), "cw");
                        dwc = dw_1.GetChild("xjzh");
                        dwc.SetTransaction(this.AdoTransaction);
                        dwc = dw_1.GetChild("zdr");
                        dwc.SetTransaction(this.AdoTransaction);
                        dwc.Retrieve("%", A8ERP.AppService.GetUserID(),"hy");
                        dwc = dw_1.GetChild("jbr");
                        dwc.SetTransaction(this.AdoTransaction);
                        dwc.Retrieve("%", A8ERP.AppService.GetUserID(),"hy");
                        //dwc = dw_2.GetChild("km");
                        //dwc.SetTransaction(this.AdoTransaction);
                        //dwc.Retrieve("%");
                        if (curJqdbm == "1")
                        {
                            dw_1.Modify("gyssdye.visible='0'  gysbdye.visible='0' ");
                            dw_1.Modify("sdye.visible='1' bdye.visible='1' ");
                        }
                        else
                        {
                            dw_1.Modify("sdye.visible='0' bdye.visible='0' ");
                            dw_1.Modify("gyssdye.visible='1' gysbdye.visible='1'  ");
                        }
                        dw_1.Modify("title_t.Text='现金银行支出凭证'");
                    }
                    else
                    {
                        dw_1.DataWindowObject = "dw_cw_xjzc_top";
                        dw_2.DataWindowObject = "dw_cw_xjzc_mx";
                        dw_1.Retrieve(curpzh);
                        dw_2.Retrieve(curpzh);
                        dwc = dw_1.GetChild("bmbh");
                        dwc.SetTransaction(this.AdoTransaction);
                        dwc.Retrieve("%", A8ERP.AppService.GetUserID(), "cw");
                        dwc = dw_1.GetChild("gysbh");
                        dwc.SetTransaction(this.AdoTransaction);
                        dwc.Retrieve("%", A8ERP.AppService.GetUserID());
                        dwc = dw_2.GetChild("sfkm");
                        dwc.SetTransaction(this.AdoTransaction);
                        dwc.Retrieve("001");
                        dwc = dw_1.GetChild("zdr");
                        dwc.SetTransaction(this.AdoTransaction);
                        dwc.Retrieve("%", yhbh,"cw");
                        dwc = dw_2.GetChild("zczh");
                        dwc.SetTransaction(this.AdoTransaction);
                        dwc.Retrieve(dw_1.GetItemString(1, "bmbh"));
                        sc_1.SplitterDistance = 150;
                        if (curJqdbm == "1")
                        {
                            dw_1.Modify("gyssdye.visible='0'  gysbdye.visible='0' ");
                            dw_1.Modify("sdye.visible='1' bdye.visible='1' ");
                        }
                        else
                        {
                            dw_1.Modify("sdye.visible='0' bdye.visible='0' ");
                            dw_1.Modify("gyssdye.visible='1' gysbdye.visible='1'  ");
                        }
                    }
                }
                #endregion
                #region 销货收款单
                else if ("XS".Equals(ywflag.Substring(0, 2)))
                {
                    dw_1.DataWindowObject = "da_cw_xhskd_top";
                    dw_2.DataWindowObject = "da_cw_xhskd_mx";
                    dw_1.Retrieve(curpzh);
                    dw_2.Retrieve(curpzh, curJqdbm);
                    dwc = dw_1.GetChild("khbh");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("%", A8ERP.AppService.GetUserID());
                    dwc = dw_1.GetChild("bmbh");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("%", A8ERP.AppService.GetUserID(), "cw");

                    dwc = dw_1.GetChild("skfs");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("skfs");       // 订单方式的下拉框。 
                    dwc = dw_1.GetChild("ywy");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("%", A8ERP.AppService.GetUserID(), "cw");
                    dwc = dw_1.GetChild("fyzh");
                    dwc.SetTransaction(this.AdoTransaction);
                    dw_1.Modify("title_t.Text='销货收款单'");
                }
                #endregion
                #region 销货费用单
                else if ("XF".Equals(ywflag.Substring(0, 2)))
                {
                    dw_1.DataWindowObject = "da_cw_xhfyd_top";
                    dw_2.DataWindowObject = "da_cw_xhfyd_mx";
                    dw_1.Retrieve(curpzh);
                    dw_2.Retrieve(curpzh);
                    dwc = dw_1.GetChild("khbh");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("%", A8ERP.AppService.GetUserID());
                    dwc = dw_1.GetChild("bmbh");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("%", A8ERP.AppService.GetUserID(), "cw");

                    dwc = dw_1.GetChild("fkfs");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("skfs");

                    dwc = dw_1.GetChild("zdr");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("%", A8ERP.AppService.GetUserID(), "cw");

                    dwc = dw_1.GetChild("fyzh");
                    dwc.SetTransaction(this.AdoTransaction);

                    dwc = dw_2.GetChild("sfkm");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("%");
                    dw_1.Modify("title_t.Text='销货费用单'");
                }
                #endregion
                #region 现金银行凭证
                else if ("TT".Equals(ywflag.Substring(0, 2)))
                {

                    dw_1.DataWindowObject = "dw_cw_xjyhzhtzd_edit";
                    //dw_1.DataWindowObject = "dw_cw_xjyhzhtzd_list";
                    //dw_1.Retrieve(curpzh);
                    dw_1.Retrieve(curpzh);
                    dw_2.Visible = false;
                    dwc = dw_1.GetChild("bmbh");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("%", A8ERP.AppService.GetUserID(), "cw");

                    dwc = dw_1.GetChild("tzlx");
                    dwc.SetTransaction(this.AdoTransaction);
                    dwc.Retrieve("xjyh_tzlx");

                    dwc = dw_1.GetChild("tzyhzh");
                    dwc.SetTransaction(this.AdoTransaction);

                    dwc = dw_1.GetChild("zryhzh");
                    dwc.SetTransaction(this.AdoTransaction);
                    dw_1.Modify("title_t.Text='销货费用单'");
                }
                #endregion
                }

            }

            ////增加尺寸
            //if (ywflag.Substring(0, 2) != "TT" && ywflag.Substring(0, 2) != "ZC" && ywflag.Substring(0, 2) != "SR" && ywflag.Substring(0, 2) != "XS" && ywflag.Substring(0, 2) != "XF" && ywflag.Substring(0, 2) != "JF" && ywflag.Substring(0, 2) != "FK")
            //{
            //    Common.DWServiceHelp.Add35CmCol(dw_2, false);

            //}

            dw_1.Modify("DataWindow.Readonly=yes");
            dw_2.Modify("DataWindow.Readonly=yes");

        }

        void Add35CmCol(bool isShow)
        {
            if (isShow)
                Common.DWServiceHelp.Add35CmCol(dw_2, false);
        }
    }
}
