using System; 
 | 
using System.Collections.Generic; 
 | 
using System.ComponentModel; 
 | 
using System.Data; 
 | 
using System.Drawing; 
 | 
using System.Text; 
 | 
using System.Windows.Forms; 
 | 
  
 | 
namespace Pub_Control 
 | 
{ 
 | 
    public partial class frm_S_BillQueryCondition_Base : Form 
 | 
    { 
 | 
        public frm_S_BillQueryCondition_Base() 
 | 
        { 
 | 
            InitializeComponent(); 
 | 
        } 
 | 
        const int IDCol = 0; 
 | 
        const int BracketLCol = 1; 
 | 
        const int FieldNameCol = 2; 
 | 
        const int ControlCol = 3; 
 | 
        const int ConditionCol = 4; 
 | 
        const int BracketRCol = 5; 
 | 
        const int RelationCol = 6; 
 | 
        const int FindCol = 7; 
 | 
        // 
 | 
        public string SqlStr = ""; 
 | 
        public string FieldsArray = ""; 
 | 
        private string mvarViewName = ""; 
 | 
        private int CopyRow = 0; 
 | 
        private string CopyField = ""; 
 | 
        private string CopyDataType = ""; 
 | 
        private bool Copyed; 
 | 
        public Pub_Class.ClsPub.Enum_OKTag OKTag; 
 | 
        public string ModName; 
 | 
        public string ViewName; 
 | 
        Pub_Class.ClsSqlHelper oCn = new Pub_Class.ClsSqlHelper(); 
 | 
        // 
 | 
        Clsxt_ICSchemeMain oItem = new Clsxt_ICSchemeMain(); 
 | 
        public Pub_Class.ClsPub.Enum_BillStatus BillStatus; 
 | 
        //当前选中方案ID 
 | 
        Int64 HInterID = 0; 
 | 
        // 
 | 
        public void SetViewName(string sViewName,bool b) 
 | 
        { 
 | 
            string[] tArray; 
 | 
            DataSet Ds = new DataSet(); 
 | 
            int j; 
 | 
            if (Pub_Class.ClsPub.isStrNull(sViewName).Length == 0) 
 | 
            { 
 | 
                return; 
 | 
            } 
 | 
            mvarViewName = sViewName; 
 | 
            Ds = oCn.RunProcReturn("select column_name,data_type from information_schema.columns where table_name ='" + ViewName.Trim() + "' order by  ORDINAL_POSITION", "information"); 
 | 
            grdCondition.RowCount = 1; 
 | 
            for (int i = 0; i < Ds.Tables[0].Rows.Count; i++) 
 | 
            { 
 | 
                //grid1 
 | 
                grdCondition.RowCount = i + 1; 
 | 
                grdCondition.Rows[i].Cells[FieldNameCol].Value = Ds.Tables[0].Rows[i]["column_name"].ToString().Trim(); 
 | 
                grdCondition.Rows[i].Cells[IDCol].Value = Ds.Tables[0].Rows[i]["data_type"].ToString().Trim(); 
 | 
                // 
 | 
                DataGridViewComboBoxCell sCellRel = new DataGridViewComboBoxCell(); 
 | 
                sCellRel.FlatStyle = FlatStyle.System; 
 | 
                sCellRel.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing; 
 | 
                sCellRel.DropDownWidth = 10; 
 | 
                sCellRel.Items.Add("并且"); 
 | 
                sCellRel.Items.Add("或者"); 
 | 
                grdCondition.Rows[i].Cells[RelationCol] = sCellRel; 
 | 
                grdCondition.Rows[i].Cells[6].Value = "并且"; 
 | 
                // 
 | 
                DataGridViewComboBoxCell sCellCom = new DataGridViewComboBoxCell(); 
 | 
                sCellCom.FlatStyle = FlatStyle.System; 
 | 
                sCellCom.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing; 
 | 
                sCellCom.DropDownWidth = 10; 
 | 
                sCellCom.Items.Add(" "); 
 | 
                sCellCom.Items.Add("="); 
 | 
                sCellCom.Items.Add(">"); 
 | 
                sCellCom.Items.Add(">="); 
 | 
                sCellCom.Items.Add("<"); 
 | 
                sCellCom.Items.Add("<="); 
 | 
                sCellCom.Items.Add("<>"); 
 | 
                sCellCom.Items.Add("包含"); 
 | 
                sCellCom.Items.Add("左包含"); 
 | 
                sCellCom.Items.Add("右包含"); 
 | 
                grdCondition.Rows[i].Cells[ControlCol] = sCellCom; 
 | 
                // 
 | 
                if (Ds.Tables[0].Rows[i]["column_name"].ToString().Trim().ToUpper().Substring(0, 1) == "H")//H开头的列隐藏 
 | 
                { 
 | 
                    grdCondition.Rows[i].Visible = false;  
 | 
                } 
 | 
                 
 | 
                // 
 | 
                DataGridViewCheckBoxCell sCell = new DataGridViewCheckBoxCell(); 
 | 
                sCell.ThreeState = false; 
 | 
                sCell.Value = 1; 
 | 
  
 | 
            } 
 | 
            if (!b) 
 | 
            { 
 | 
                Sub_GetSchemeInfo(); 
 | 
            } 
 | 
  
 | 
        } 
 | 
  
 | 
        //读取方案信息 
 | 
        private void Sub_GetSchemeInfo()  //Lock 
 | 
        { 
 | 
            //当前选中方案,若没有选中则为 默认方案,若不存在默认方案则自动新增 
 | 
            if (HInterID == 0) 
 | 
            { 
 | 
                if (oItem.ShowDefault(this.ModName)) 
 | 
                { 
 | 
                    HInterID = oItem.HInterID; 
 | 
                } 
 | 
                else//不存在则 生成默认方案 
 | 
                { 
 | 
                    return; 
 | 
                } 
 | 
            } 
 | 
            if (!oItem.ShowBill(HInterID, ref Pub_Class.ClsPub.sExeReturnInfo)) 
 | 
                return; 
 | 
            //foreach (Clsxt_ICSchemeSub oSub in oItem.DetailColl) 
 | 
            //{ 
 | 
            //    //循环控件,找到则赋值 
 | 
            //    foreach (Control ct in this.tabPage1.Controls) 
 | 
            //    { 
 | 
            //        if (oSub.HKey.Trim().ToLower() == ct.Name.Trim().ToLower()) 
 | 
            //        { 
 | 
            //            if (ct.Name.Trim().ToLower().Substring(0, 3) == "txt" || ct.Name.Trim().ToLower().Substring(0, 3) == "cmb") 
 | 
            //            { 
 | 
            //                ct.Text = oSub.HValue.Trim(); 
 | 
            //            } 
 | 
            //        } 
 | 
            //    } 
 | 
            //    foreach (Control ct in this.panel8.Controls) 
 | 
            //    { 
 | 
            //        if (oSub.HKey.Trim().ToLower() == ct.Name.Trim().ToLower()) 
 | 
            //        { 
 | 
            //            if (ct.Name.Trim().ToLower().Substring(0, 3) == "txt" || ct.Name.Trim().ToLower().Substring(0, 3) == "cmb") 
 | 
            //            { 
 | 
            //                ct.Text = oSub.HValue.Trim(); 
 | 
            //            } 
 | 
            //        } 
 | 
            //    } 
 | 
            //} 
 | 
            //得到3个GRID 
 | 
            try 
 | 
            { 
 | 
                Pub_Class.ClsSqlHelper oCn2 = new Pub_Class.ClsSqlHelper(); 
 | 
                DataSet DSet; 
 | 
                for (int i = 0; i < grdCondition.RowCount; i++) 
 | 
                { 
 | 
                    DSet = oCn2.RunProcReturn("select * from Xt_grdCondition where HUserID='" + Pub_Class.ClsPub.CurUserName + "' and HBillName='" + ViewName.Trim() + "' and HRow=" + i, "Xt_grdCondition"); 
 | 
                    if (Pub_Class.ClsPub.isInt(DSet.Tables[0].Rows.Count) != 0) 
 | 
                    { 
 | 
                        grdCondition.Rows[i].Cells[0].Value = DSet.Tables[0].Rows[0]["HIDCol"]; 
 | 
                        grdCondition.Rows[i].Cells[1].Value = DSet.Tables[0].Rows[0]["HBracketLCol"]; 
 | 
                        grdCondition.Rows[i].Cells[2].Value = DSet.Tables[0].Rows[0]["HFieldNameCol"]; 
 | 
                        grdCondition.Rows[i].Cells[3].Value = DSet.Tables[0].Rows[0]["HControlCol"]; 
 | 
                        grdCondition.Rows[i].Cells[4].Value = DSet.Tables[0].Rows[0]["HConditionCol"]; 
 | 
                        grdCondition.Rows[i].Cells[5].Value = DSet.Tables[0].Rows[0]["HBracketRCol"]; 
 | 
                        grdCondition.Rows[i].Cells[6].Value = DSet.Tables[0].Rows[0]["HRelationCol"]; 
 | 
                    } 
 | 
                } 
 | 
            } 
 | 
            catch (Exception e) 
 | 
            { 
 | 
                return; 
 | 
            } 
 | 
        } 
 | 
  
 | 
        // 
 | 
        private bool Sub_DeleteSchemeInfo() 
 | 
        { 
 | 
            MessageBox.Show("此功能有待完善!"); 
 | 
            return false; 
 | 
        } 
 | 
  
 | 
        //保存方案 
 | 
        private bool Sub_SaveSchemeInfo()  //Lock 
 | 
        { 
 | 
            //保存当前选中方案,若没有选中则为 默认方案 
 | 
            if (HInterID == 0) 
 | 
            { 
 | 
                if (oItem.ShowDefault(this.ViewName)) 
 | 
                { 
 | 
                    HInterID = oItem.HInterID; 
 | 
                    BillStatus = Pub_Class.ClsPub.Enum_BillStatus.BillStatus_Modify; 
 | 
                } 
 | 
                else//不存在则 生成默认方案 
 | 
                { 
 | 
                    BillStatus = Pub_Class.ClsPub.Enum_BillStatus.BillStatus_AddNew; 
 | 
                } 
 | 
            } 
 | 
            else 
 | 
            { 
 | 
                BillStatus = Pub_Class.ClsPub.Enum_BillStatus.BillStatus_Modify; 
 | 
            } 
 | 
            //加载到类 
 | 
            oItem.HBillName = ModName; 
 | 
            oItem.HBillType = oItem.MvarItemKey; 
 | 
            oItem.HStopflag = false; 
 | 
            oItem.HUserCode = Pub_Class.ClsPub.CurUserName; 
 | 
            // 
 | 
            oItem.DetailColl.Clear(); 
 | 
            //foreach (Control ct in this.tabPage1.Controls) 
 | 
            //{ 
 | 
            //    Clsxt_ICSchemeSub oSub = new Clsxt_ICSchemeSub(); 
 | 
            //    if (ct.Name.Trim().ToLower().Substring(0, 3) == "txt" || ct.Name.Trim().ToLower().Substring(0, 3) == "cmb") 
 | 
            //    { 
 | 
            //        oSub.HKey = ct.Name.Trim(); 
 | 
            //        oSub.HValue = ct.Text.Trim(); 
 | 
            //        oSub.HInterID = this.HInterID; 
 | 
            //        oItem.DetailColl.Add(oSub); 
 | 
            //    } 
 | 
            //} 
 | 
            //foreach (Control ct in this.panel8.Controls) 
 | 
            //{ 
 | 
            //    Clsxt_ICSchemeSub oSub = new Clsxt_ICSchemeSub(); 
 | 
            //    if (ct.Name.Trim().ToLower().Substring(0, 3) == "txt" || ct.Name.Trim().ToLower().Substring(0, 3) == "cmb") 
 | 
            //    { 
 | 
            //        oSub.HKey = ct.Name.Trim(); 
 | 
            //        oSub.HValue = ct.Text.Trim(); 
 | 
            //        oSub.HInterID = this.HInterID; 
 | 
            //        oItem.DetailColl.Add(oSub); 
 | 
            //    } 
 | 
            //} 
 | 
            // 
 | 
            if (BillStatus == Pub_Class.ClsPub.Enum_BillStatus.BillStatus_Modify) 
 | 
            { 
 | 
                if (!oItem.ModifyBill(HInterID, ref  Pub_Class.ClsPub.sExeReturnInfo)) 
 | 
                    return false; 
 | 
            } 
 | 
            else if (BillStatus == Pub_Class.ClsPub.Enum_BillStatus.BillStatus_AddNew) 
 | 
            { 
 | 
                oItem.HName = "默认方案"; 
 | 
                if (!oItem.AddBill(ref Pub_Class.ClsPub.sExeReturnInfo, HInterID)) 
 | 
                    return false; 
 | 
            } 
 | 
            else 
 | 
            { 
 | 
                return false; 
 | 
            } 
 | 
            //保存3个GRID 
 | 
            try 
 | 
            { 
 | 
                Pub_Class.ClsSqlHelper oCn1 = new Pub_Class.ClsSqlHelper(); 
 | 
                oCn1.RunProc("delete Xt_grdCondition where HUserID='" + Pub_Class.ClsPub.CurUserName + "' and HBillName='" + ViewName.Trim() + "'"); 
 | 
                for (int i = 0; i < grdCondition.RowCount; i++) 
 | 
                { 
 | 
  
 | 
                    oCn1.RunProc("Insert Into Xt_grdCondition   " + 
 | 
                    "(HUserID,HBillName,HRow,HIDCol,HBracketLCol,HFieldNameCol,HControlCol" + 
 | 
                    ",HConditionCol,HBracketRCol,HRelationCol" + 
 | 
                    ") " + 
 | 
                    " values('" + Pub_Class.ClsPub.CurUserName + "','" + ViewName.Trim() + "'," + i + 
 | 
                    ",'" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[0].Value) + "'" + 
 | 
                    ",'" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[1].Value) + "'" + 
 | 
                    ",'" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[2].Value) + "'" + 
 | 
                    ",'" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[3].Value) + "'" + 
 | 
                    ",'" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[4].Value).Replace("'", "''") + "'" + 
 | 
                    ",'" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[5].Value).Replace("'", "''") + "'" + 
 | 
                    ",'" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[6].Value) + "')"); 
 | 
                } 
 | 
                return true; 
 | 
            } 
 | 
            catch (Exception e) 
 | 
            { 
 | 
                return false; 
 | 
            } 
 | 
  
 | 
        } 
 | 
  
 | 
        private void cmdCancel_Click(object sender, EventArgs e) 
 | 
        { 
 | 
            this.Tag = "CANCEL"; 
 | 
            SetViewName(mvarViewName,false); 
 | 
            this.Visible = false; 
 | 
        } 
 | 
  
 | 
        private void cmdOk_Click(object sender, EventArgs e) 
 | 
        { 
 | 
            Sub_SaveSchemeInfo(); 
 | 
            if (GetSql()) 
 | 
            { 
 | 
                this.Tag = "OK"; 
 | 
                this.Visible = false; 
 | 
            } 
 | 
        } 
 | 
        // 
 | 
        private void initGrid() 
 | 
        { 
 | 
            grdCondition.RowTemplate.Height = 18; 
 | 
            grdCondition.RowTemplate.MinimumHeight = 18; 
 | 
            grdCondition.ColumnHeadersHeight = 35; 
 | 
            grdCondition.RowHeadersVisible = false; 
 | 
            grdCondition.ColumnHeadersVisible = true; 
 | 
            grdCondition.ColumnCount = 7; 
 | 
            grdCondition.RowCount = 1; 
 | 
            grdCondition.EnableHeadersVisualStyles = false; 
 | 
            grdCondition.AllowUserToAddRows = false;             //是否允许自增--否 
 | 
            grdCondition.AllowUserToDeleteRows = false;          //是否允许删除--否  
 | 
            grdCondition.AllowUserToResizeColumns = true;         //允许调整列宽--是 
 | 
            grdCondition.AllowUserToResizeRows = false;           //允许调整行高--否 
 | 
            grdCondition.AllowUserToOrderColumns = false; 
 | 
            grdCondition.GridColor = Color.LightGray; 
 | 
            grdCondition.Columns[BracketLCol].HeaderText = "左括号"; 
 | 
            grdCondition.Columns[FieldNameCol].HeaderText = "字段名称"; 
 | 
            grdCondition.Columns[ControlCol].HeaderText = "比较关系"; 
 | 
            grdCondition.Columns[ConditionCol].HeaderText = "数值"; 
 | 
            grdCondition.Columns[BracketRCol].HeaderText = "右括号"; 
 | 
            grdCondition.Columns[RelationCol].HeaderText = "逻辑"; 
 | 
            // 
 | 
            grdCondition.EditMode = DataGridViewEditMode.EditOnEnter;      //编辑模式 
 | 
            grdCondition.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; 
 | 
            grdCondition.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; 
 | 
            grdCondition.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; //允许用户调整列宽 
 | 
            grdCondition.Columns[IDCol].Visible = false; 
 | 
  
 | 
            grdCondition.Columns[BracketLCol].Width = 50; 
 | 
            grdCondition.Columns[FieldNameCol].Width = 120; 
 | 
            grdCondition.Columns[ControlCol].Width = 60; 
 | 
            grdCondition.Columns[ConditionCol].Width = 90; 
 | 
            grdCondition.Columns[BracketRCol].Width = 50; 
 | 
            grdCondition.Columns[RelationCol].Width = 50; 
 | 
            for (int i = 0; i < grdCondition.ColumnCount; i++) 
 | 
            { 
 | 
                grdCondition.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; 
 | 
            } 
 | 
        } 
 | 
  
 | 
        private void frm_S_BillQueryCondition_Base_Load(object sender, EventArgs e) 
 | 
        { 
 | 
            initGrid(); 
 | 
        } 
 | 
  
 | 
        private void timer1_Tick(object sender, EventArgs e) 
 | 
        { 
 | 
            timer1.Enabled = false; 
 | 
            SetViewName(ViewName,false); 
 | 
        } 
 | 
  
 | 
        
 | 
        private string CHStoENG(string sCHS) 
 | 
        { 
 | 
            switch (sCHS) 
 | 
            { 
 | 
                case "包含": 
 | 
                    return "LIKE"; 
 | 
                case "左包含": 
 | 
                    return "LIKEL"; 
 | 
                case "右包含": 
 | 
                    return "LIKER"; 
 | 
                case "并且": 
 | 
                    return "AND"; 
 | 
                case "或者": 
 | 
                    return "OR"; 
 | 
                default: 
 | 
                    return sCHS; 
 | 
  
 | 
            } 
 | 
        } 
 | 
  
 | 
        //private void grdMain_BeforeEdit(object sender, AxVSFlex7._IVSFlexGridEvents_BeforeEditEvent e) 
 | 
        //{ 
 | 
        //    string tStr = ""; 
 | 
        //    if (e.col == 2 || e.col == 1 || e.col == 5) 
 | 
        //    { 
 | 
        //        e.cancel = true; 
 | 
        //        return; 
 | 
        //    } 
 | 
        //    if (e.col == 3) 
 | 
        //    { 
 | 
        //        switch (grdCondition.get_TextMatrix(e.row, IDCol).ToUpper().Trim()) 
 | 
        //        { 
 | 
        //            case "NVARCHAR": 
 | 
        //                tStr = " " + 
 | 
        //                    "|=" + 
 | 
        //                    "|>" + 
 | 
        //                    "|>=" + 
 | 
        //                    "|<" + 
 | 
        //                    "|<=" + 
 | 
        //                    "|<>" + 
 | 
        //                    "|包含" + 
 | 
        //                    "|左包含" + 
 | 
        //                    "|右包含"; 
 | 
        //                break; 
 | 
        //            case "CHAR": 
 | 
        //                tStr = " " + 
 | 
        //                    "|=" + 
 | 
        //                    "|>" + 
 | 
        //                    "|>=" + 
 | 
        //                    "|<" + 
 | 
        //                    "|<=" + 
 | 
        //                    "|<>" + 
 | 
        //                    "|包含" + 
 | 
        //                    "|左包含" + 
 | 
        //                    "|右包含"; 
 | 
        //                break; 
 | 
        //            case "VARCHAR": 
 | 
        //                tStr = " " + 
 | 
        //                    "|=" + 
 | 
        //                    "|>" + 
 | 
        //                    "|>=" + 
 | 
        //                    "|<" + 
 | 
        //                    "|<=" + 
 | 
        //                    "|<>" + 
 | 
        //                    "|包含" + 
 | 
        //                    "|左包含" + 
 | 
        //                    "|右包含"; 
 | 
        //                break; 
 | 
        //            case "BIT": 
 | 
        //                tStr = " " + 
 | 
        //                    "|=" + 
 | 
        //                    "|<>"; 
 | 
        //                break; 
 | 
        //            default: 
 | 
        //                tStr = " " + 
 | 
        //                    "|=" + 
 | 
        //                    "|>" + 
 | 
        //                    "|>=" + 
 | 
        //                    "|<" + 
 | 
        //                    "|<=" + 
 | 
        //                    "|<>" + 
 | 
        //                    "|包含" + 
 | 
        //                    "|左包含" + 
 | 
        //                    "|右包含"; 
 | 
        //                break; 
 | 
        //        } 
 | 
        //        grdCondition.set_ColComboList(3, tStr); 
 | 
        //        return; 
 | 
        //    } 
 | 
        //    if (e.col == 6) 
 | 
        //    { 
 | 
        //        tStr = "并且|或者"; 
 | 
        //        grdCondition.set_ColComboList(6, tStr); 
 | 
        //        return; 
 | 
        //    } 
 | 
        //    return; 
 | 
        //} 
 | 
  
 | 
        //private void grdMain_ValidateEdit(object sender, AxVSFlex7._IVSFlexGridEvents_ValidateEditEvent e) 
 | 
        //{ 
 | 
        //    if (e.col == 4) 
 | 
        //    { 
 | 
        //        switch (grdCondition.get_TextMatrix(e.row, IDCol).Trim().ToUpper()) 
 | 
        //        { 
 | 
        //            case "MONEY": 
 | 
        //                //if (Pub_Class.ClsPub.IsNumeric(grdCondition.EditText) == false) 
 | 
        //                //{ 
 | 
        //                    e.cancel = true; 
 | 
        //                //} 
 | 
        //                break; 
 | 
        //            case "INT": 
 | 
        //                //if (Pub_Class.ClsPub.IsNumeric(grdCondition.EditText) == false) 
 | 
        //                //{ 
 | 
        //                    e.cancel = true; 
 | 
        //                //} 
 | 
        //                break; 
 | 
        //            case "FLOAT": 
 | 
        //                //if (Pub_Class.ClsPub.IsNumeric(grdCondition.EditText) == false) 
 | 
        //                //{ 
 | 
        //                    e.cancel = true; 
 | 
        //                //} 
 | 
        //                break; 
 | 
        //            default: 
 | 
  
 | 
        //                break; 
 | 
  
 | 
        //        } 
 | 
        //    } 
 | 
        //} 
 | 
        // 
 | 
        private bool GetSql()  //Lock 
 | 
        { 
 | 
            string tSql = ""; 
 | 
            string tFilter = ""; 
 | 
            string sEngCondi = ""; 
 | 
            string sLinkCondi = ""; 
 | 
            FieldsArray = tSql; 
 | 
            //得到显示项目 
 | 
            string HeadSql = ""; 
 | 
            HeadSql = ""; 
 | 
            // 
 | 
            tSql = "select Top 5000 * " + HeadSql + " from " + mvarViewName.Trim() + " Where 1=1 "; 
 | 
            for (int i = 0; i < grdCondition.RowCount; i++) 
 | 
            { 
 | 
                sEngCondi = CHStoENG(Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[3].Value)); 
 | 
                sLinkCondi = CHStoENG(Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[6].Value));  // and or 
 | 
                if (sEngCondi.Trim().Length != 0) 
 | 
                { 
 | 
                    switch (sEngCondi.Trim().ToUpper()) 
 | 
                    { 
 | 
                        case "LIKE": 
 | 
                            tFilter = tFilter + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[1].Value) + " " + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[2].Value) + " LIKE '%" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[4].Value).Trim().Replace("'", "''") + "%' " + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[5].Value) + " " + sLinkCondi.Trim() + " "; 
 | 
                            break; 
 | 
                        case "LIKEL": 
 | 
                            tFilter = tFilter + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[1].Value) + " " + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[2].Value) + " LIKE '" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[4].Value).Trim().Replace("'", "''") + "%' " + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[5].Value) + " " + sLinkCondi.Trim() + " "; 
 | 
                            break; 
 | 
                        case "LIKER": 
 | 
                            tFilter = tFilter + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[1].Value) + " " + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[2].Value) + " LIKE '%" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[4].Value).Trim().Replace("'", "''") + "' " + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[5].Value) + " " + sLinkCondi.Trim() + " "; 
 | 
                            break; 
 | 
                        default: 
 | 
                            switch (Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[0].Value).Trim().ToUpper()) 
 | 
                            { 
 | 
                                case "BIT": 
 | 
                                    tFilter = tFilter + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[1].Value) + " " + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[2].Value) + sEngCondi + " " + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[4].Value).Trim() + "  " + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[5].Value) + " " + sLinkCondi.Trim() + " "; 
 | 
                                    break; 
 | 
                                case "MONEY": 
 | 
                                    tFilter = tFilter + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[1].Value) + " " + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[2].Value) + sEngCondi + "" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[4].Value) + " " + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[5].Value) + " " + sLinkCondi.Trim() + " "; 
 | 
                                    break; 
 | 
                                case "DECIMAL": 
 | 
                                    tFilter = tFilter + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[1].Value) + " " + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[2].Value) + sEngCondi + "" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[4].Value) + " " + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[5].Value) + " " + sLinkCondi.Trim() + " "; 
 | 
                                    break; 
 | 
                                default: 
 | 
                                    tFilter = tFilter + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[1].Value) + " " + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[2].Value) + sEngCondi + "'" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[4].Value) + "' " + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[5].Value) + " " + sLinkCondi.Trim() + " "; 
 | 
                                    break; 
 | 
                            } 
 | 
                            break; 
 | 
                    } 
 | 
                } 
 | 
                else 
 | 
                { 
 | 
                    if (Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[1].Value).Trim().Length != 0 || Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[5].Value).Trim().Length != 0) 
 | 
                    { 
 | 
                        MessageBox.Show("第" + i.ToString() + "行没有条件,不应该有括号出现,请取消此括号!", "提示"); 
 | 
                        return false; 
 | 
                    } 
 | 
                } 
 | 
            } 
 | 
            if (tFilter.Trim().Length != 0) 
 | 
            { 
 | 
                tFilter = tFilter.Substring(0, tFilter.Trim().Length - 3); 
 | 
                SqlStr = tSql + " AND " + tFilter; 
 | 
            } 
 | 
            else 
 | 
            { 
 | 
                SqlStr = tSql; 
 | 
            } 
 | 
            return true; 
 | 
        } 
 | 
  
 | 
        //加括号 
 | 
        private void cmdBracket_Click(object sender, EventArgs e) 
 | 
        { 
 | 
            int BRow = -1, ERow = 0; 
 | 
            if (grdCondition.SelectedCells == null || grdCondition.SelectedCells.Count == 0) 
 | 
            { 
 | 
  
 | 
                return; 
 | 
            } 
 | 
            //找最大行,最小行 
 | 
            for (int i = 0; i < grdCondition.SelectedCells.Count; i++) 
 | 
            { 
 | 
                if (grdCondition.SelectedCells[i].RowIndex > ERow) 
 | 
                { 
 | 
                    ERow = grdCondition.SelectedCells[i].RowIndex; 
 | 
                } 
 | 
                if (BRow == -1) 
 | 
                { 
 | 
                    BRow = grdCondition.SelectedCells[i].RowIndex; 
 | 
                } 
 | 
                else 
 | 
                { 
 | 
                    if (grdCondition.SelectedCells[i].RowIndex < BRow) 
 | 
                    { 
 | 
                        BRow = grdCondition.SelectedCells[i].RowIndex; 
 | 
                    } 
 | 
                } 
 | 
            } 
 | 
            // 
 | 
            if (BRow != -1) 
 | 
            { 
 | 
                grdCondition.Rows[BRow].Cells[BracketLCol].Value = Pub_Class.ClsPub.isStrNull(grdCondition.Rows[BRow].Cells[BracketLCol].Value) + "("; 
 | 
                grdCondition.Rows[ERow].Cells[BracketRCol].Value = Pub_Class.ClsPub.isStrNull(grdCondition.Rows[ERow].Cells[BracketRCol].Value) + ")"; 
 | 
            } 
 | 
        } 
 | 
        //减括号 
 | 
        private void cmdUNBracket_Click(object sender, EventArgs e) 
 | 
        { 
 | 
            int BRow = -1, ERow = 0; 
 | 
            if (grdCondition.SelectedCells == null || grdCondition.SelectedCells.Count == 0) 
 | 
            { 
 | 
  
 | 
                return; 
 | 
            } 
 | 
            //找最大行,最小行 
 | 
            for (int i = 0; i < grdCondition.SelectedCells.Count; i++) 
 | 
            { 
 | 
                if (grdCondition.SelectedCells[i].RowIndex > ERow) 
 | 
                { 
 | 
                    ERow = grdCondition.SelectedCells[i].RowIndex; 
 | 
                } 
 | 
                if (BRow == -1) 
 | 
                { 
 | 
                    BRow = grdCondition.SelectedCells[i].RowIndex; 
 | 
                } 
 | 
                else 
 | 
                { 
 | 
                    if (grdCondition.SelectedCells[i].RowIndex < BRow) 
 | 
                    { 
 | 
                        BRow = grdCondition.SelectedCells[i].RowIndex; 
 | 
                    } 
 | 
                } 
 | 
            } 
 | 
            // 
 | 
            if (Pub_Class.ClsPub.isStrNull(grdCondition.Rows[BRow].Cells[BracketLCol].Value) != "" && Pub_Class.ClsPub.isStrNull(grdCondition.Rows[ERow].Cells[BracketRCol].Value) != "") 
 | 
            { 
 | 
                string s; 
 | 
                s = Pub_Class.ClsPub.isStrNull(grdCondition.Rows[BRow].Cells[BracketLCol].Value); 
 | 
                grdCondition.Rows[BRow].Cells[BracketLCol].Value = s.Substring(0, s.Length - 1); 
 | 
                s = ""; 
 | 
                s = Pub_Class.ClsPub.isStrNull(grdCondition.Rows[ERow].Cells[BracketRCol].Value); 
 | 
                grdCondition.Rows[ERow].Cells[BracketRCol].Value = s.Substring(0, s.Length - 1); 
 | 
            } 
 | 
            else 
 | 
            { 
 | 
                if (Pub_Class.ClsPub.isStrNull(grdCondition.Rows[BRow].Cells[BracketLCol].Value) == "") 
 | 
                { 
 | 
                    MessageBox.Show("选择的第一行没有括号!", "提示"); 
 | 
                } 
 | 
                else 
 | 
                { 
 | 
                    MessageBox.Show("选择的最后一行没有括号!", "提示"); 
 | 
                } 
 | 
            } 
 | 
        } 
 | 
        //复制 
 | 
        private void cmdCopy_Click(object sender, EventArgs e) 
 | 
        { 
 | 
            if (grdCondition.CurrentRow != null) 
 | 
            { 
 | 
                CopyField = Pub_Class.ClsPub.isStrNull(grdCondition.Rows[grdCondition.CurrentRow.Index].Cells[FieldNameCol].Value); 
 | 
                CopyDataType = Pub_Class.ClsPub.isStrNull(grdCondition.Rows[grdCondition.CurrentRow.Index].Cells[IDCol].Value); 
 | 
                cmdPaste.Enabled = true; 
 | 
            } 
 | 
        } 
 | 
        //黏贴 
 | 
        private void cmdPaste_Click(object sender, EventArgs e) 
 | 
        { 
 | 
            grdCondition.Rows.Insert(grdCondition.CurrentRow.Index, 1); 
 | 
            // 
 | 
            grdCondition.Rows[grdCondition.CurrentRow.Index - 1].Cells[IDCol].Value = CopyDataType; 
 | 
            grdCondition.Rows[grdCondition.CurrentRow.Index - 1].Cells[FieldNameCol].Value = CopyField; 
 | 
            // 
 | 
            DataGridViewComboBoxCell sCellRel = new DataGridViewComboBoxCell(); 
 | 
            sCellRel.FlatStyle = FlatStyle.System; 
 | 
            sCellRel.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing; 
 | 
            sCellRel.DropDownWidth = 10; 
 | 
            sCellRel.Items.Add("并且"); 
 | 
            sCellRel.Items.Add("或者"); 
 | 
            grdCondition.Rows[grdCondition.CurrentRow.Index - 1].Cells[RelationCol] = sCellRel; 
 | 
            grdCondition.Rows[grdCondition.CurrentRow.Index - 1].Cells[RelationCol].Value = "并且"; 
 | 
            // 
 | 
            DataGridViewComboBoxCell sCellCom = new DataGridViewComboBoxCell(); 
 | 
            sCellCom.FlatStyle = FlatStyle.System; 
 | 
            sCellCom.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing; 
 | 
            sCellCom.DropDownWidth = 10; 
 | 
            sCellCom.Items.Add(" "); 
 | 
            sCellCom.Items.Add("="); 
 | 
            sCellCom.Items.Add(">"); 
 | 
            sCellCom.Items.Add(">="); 
 | 
            sCellCom.Items.Add("<"); 
 | 
            sCellCom.Items.Add("<="); 
 | 
            sCellCom.Items.Add("<>"); 
 | 
            sCellCom.Items.Add("包含"); 
 | 
            sCellCom.Items.Add("左包含"); 
 | 
            sCellCom.Items.Add("右包含"); 
 | 
            grdCondition.Rows[grdCondition.CurrentRow.Index - 1].Cells[ControlCol] = sCellCom; 
 | 
            // 
 | 
        } 
 | 
        //删除 
 | 
        private void cmdDelete_Click(object sender, EventArgs e) 
 | 
        { 
 | 
            if (grdCondition.CurrentRow != null) 
 | 
            { 
 | 
                //if (ClsPub.isStrNull(grdCondition.get_TextMatrix(grdCondition.Row, BracketLCol)) != "" 
 | 
                //    || ClsPub.isStrNull(grdCondition.get_TextMatrix(grdCondition.Row, BracketRCol)) != "") 
 | 
                //{ 
 | 
                //    MessageBox.Show("被删除行不能有括号!", "提示"); 
 | 
                //    return; 
 | 
                //} 
 | 
                grdCondition.Rows.RemoveAt(grdCondition.CurrentRow.Index); 
 | 
            } 
 | 
        } 
 | 
        //恢复 
 | 
        private void cmdRestore_Click(object sender, EventArgs e) 
 | 
        { 
 | 
            SetViewName(ViewName,true); 
 | 
        } 
 | 
  
 | 
  
 | 
          
 | 
  
 | 
        public virtual void Sub_GridKeyView(int sKeyCode, int sRow, int sCol, DataGridView grdCondition, DataGridViewTextBoxEditingControl oEdit) 
 | 
        { 
 | 
            // 
 | 
        } 
 | 
  
 | 
        DataGridViewTextBoxEditingControl EditingControl; 
 | 
        private void grdCondition_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) 
 | 
        { 
 | 
            if (grdCondition.CurrentCell.ColumnIndex != ControlCol &&  
 | 
                grdCondition.CurrentCell.ColumnIndex != ConditionCol && 
 | 
                grdCondition.CurrentCell.ColumnIndex != RelationCol ) 
 | 
            { 
 | 
                e.Cancel = true; 
 | 
            } 
 | 
            else 
 | 
            { 
 | 
                // 
 | 
            } 
 | 
        } 
 | 
  
 | 
        private void EditingControl_KeyDown(object sender, KeyEventArgs e) 
 | 
        { 
 | 
            //业务处理  
 | 
            Sub_GridKeyView(e.KeyValue, grdCondition.CurrentRow.Index, grdCondition.CurrentCell.ColumnIndex, grdCondition, EditingControl); 
 | 
        } 
 | 
  
 | 
          
 | 
        private void grdCondition_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) 
 | 
        { 
 | 
            if (grdCondition.CurrentCell != null) 
 | 
            { 
 | 
                if (e.Control is DataGridViewTextBoxEditingControl) 
 | 
                { 
 | 
                    this.EditingControl = (DataGridViewTextBoxEditingControl)e.Control; 
 | 
                    //增加委托处理  
 | 
                    this.EditingControl.KeyDown += new KeyEventHandler(this.EditingControl_KeyDown); 
 | 
                } 
 | 
  
 | 
            } 
 | 
        } 
 | 
  
 | 
        private void grdCondition_CellEndEdit(object sender, DataGridViewCellEventArgs e) 
 | 
        { 
 | 
            if (this.EditingControl != null) 
 | 
            { 
 | 
                EditingControl.KeyDown -= new KeyEventHandler(this.EditingControl_KeyDown); 
 | 
                this.EditingControl = null; 
 | 
            } 
 | 
        } 
 | 
  
 | 
        private void grdCondition_KeyDown(object sender, KeyEventArgs e) 
 | 
        { 
 | 
            Sub_GridKeyView(e.KeyValue, grdCondition.CurrentRow.Index, grdCondition.CurrentCell.ColumnIndex, grdCondition, EditingControl); 
 | 
        } 
 | 
    } 
 | 
} 
 |