using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using A8ERP;
using Sybase.DataWindow;
using TXSoft.Common;
using TXSoft.ExtPB;
using TXSoft.DataStore;


namespace A8ERP.Base
{
    public partial class W_OPEN_EDIT
    {   
        public W_OPEN_EDIT()
        {

        }
        protected string curFlag = string.Empty;
        protected string curJdbh = string.Empty; 
        protected string curFjdbh_value = string.Empty;
        protected string FunID = string.Empty;
        protected string lsh_byrule = string.Empty;
        protected string curCSFL = string.Empty; 
        public override void OnLoad()
        {
            base.OnLoad();
            string stringData1=string.Empty;        
            string curFjdbh = string.Empty;
            string tree_flag = string.Empty;
            string curJdbh_name = string.Empty;
            string curPriKey = string.Empty;
           
            if (Request["targe_dw_name"] != null)
            {
                 stringData1 = Request["targe_dw_name"].ToString();
            }
            if (Request["opFlag"]!=null)
            {
                curFlag = Request["opFlag"].ToString();
            }
            if (Request["targe_fjdbh_name"] != null)
            {
                curFjdbh = Request["targe_fjdbh_name"].ToString();
            }
            if (Request["targe_fjdbh_value"] != null)
            {
                curFjdbh_value = Request["targe_fjdbh_value"].ToString();
            }
            if (Request["targe_jdbh_value"] != null)
            {
                curJdbh = Request["targe_jdbh_value"].ToString();
            }
            if (Request["tree_flag"] != null)
            {
                tree_flag = Request["tree_flag"].ToString();
            }
            if (Request["targe_jdbh_name"] != null)
            {
                curJdbh_name = Request["targe_jdbh_name"].ToString();
            }
            if (Request["PriKey"] != null)
            {
                curPriKey = Request["PriKey"].ToString();
            }
            if (Request["FunID"] != null)
            {
                FunID = Request["FunID"].ToString();
            }
            if (Request["is_ParaT"] != null)
            {
                curCSFL = Request["is_ParaT"].ToString();
            }
            dw_edit.DataStore.DataWindowObject = stringData1;
            this.SetParm("opflag", curFlag);
            this.SetParm("tree_flag", tree_flag);
            
            if ("Add".Equals(curFlag))
            {       
                dw_edit.InsertRow(0);
                //部门分类 SJ035
                if ("SJ035".Equals(FunID) || "SJ031".Equals(FunID) || "SJ032".Equals(FunID) || "SJ018".Equals(FunID) || "SJ840".Equals(FunID) || "SJ841".Equals(FunID))
                {
                    if ("00".Equals(curFjdbh_value))
                    {
                        curCSFL = "";
                    }
                    else
                    {   
                        
                        //curFjdbh_value = curFjdbh_value.Substring(0, 4);
                        curCSFL = curFjdbh_value;
                    }
                }
                lsh_byrule = DBHelp.GetRules(FunID, curCSFL); 
                if (lsh_byrule.Length > 0 && lsh_byrule != "error" && tree_flag != "Y")
                {
                    if ("SJ841".Equals(FunID))
                    {   
                        dw_edit.SetItemDouble(1, curPriKey, Convert.ToInt16(lsh_byrule));
                    }
                    else
                    {
                        dw_edit.SetItemString(1, curPriKey, lsh_byrule);
                    }
                }
                if (tree_flag == "Y")
                {
                   
                    //lsh_byrule = DBHelp.GetRules(FunID, curFjdbh_value); 
                    dw_edit.SetItemString(1, curFjdbh, curFjdbh_value);
                    dw_edit.SetItemString(1, curJdbh_name, lsh_byrule);
                    this.SetParm(curFjdbh, curFjdbh_value);
                    string modstr = "";
                    if (curFjdbh != null && curFjdbh != "")
                    {
                            modstr = curFjdbh + ".Protect='1' " + curFjdbh + ".color='8421504' ";
                    }
                    dw_edit.Modify(modstr);
                }
            }
            else
            {
                string modstr = "";
                if (curFjdbh != null && curFjdbh != "")
                {
                    modstr = curFjdbh + ".Protect='1' " + curFjdbh + ".color='8421504' ";
                }
                if (curJdbh_name != null && curJdbh_name != "")
                {
                    modstr += curJdbh_name + ".Protect='1' " + curJdbh_name + ".color='8421504'";
                }
                if (curPriKey != null && curPriKey != "")
                {
                    modstr = curPriKey + ".Protect='1' " + curPriKey + ".color='8421504'";
                }
                dw_edit.Modify(modstr);
              
            }
            if (Request["CURGNQXSTR"] != null)
            {
                if (Request["CURGNQXSTR"].ToString().IndexOf("btn_Edit") < 0)
                {
                    this.cb_Save.Enabled = false;
                }
            }
            if (this.Page != null)
            {
                this.Page.ClientScript.RegisterClientScriptInclude("W_OPEN_EDIT", "/Base/W_OPEN_EDIT.win.js");
                this.Page.ClientScript.RegisterClientScriptInclude("MyJS_Base_NoTree", "/Scripts/MyJS_Base_NoTree.js");
                this.Page.ClientScript.RegisterClientScriptInclude("W_My_Base_NoTree", "/Base/W_My_Base_NoTree.win.js");
                this.Page.ClientScript.RegisterClientScriptInclude("W_OPEN_PRINT", "/Base/W_OPEN_PRINT.win.js");
                this.Page.ClientScript.RegisterClientScriptInclude("W_OPEN_EDIT", "/Base/W_OPEN_EDIT.win.js");
            }
        }
    }
}
