Beispiel #1
0
        //public void  SetOperations(DataType.DataColumnType dct,System.Windows.Forms.ComboBox cmbOper)
        //{
        //    cmbOper.Items.Clear();
        //  ///= > < like between
        //    switch (dct)
        //    {
        //        case DataType.DataColumnType.Number:
        //            cmbOper.Items.Add("=");
        //            cmbOper.Items.Add(">");
        //            cmbOper.Items.Add("<");
        //            cmbOper.Items.Add("like");
        //            cmbOper.Items.Add("between");

        //            break;
        //        case DataType.DataColumnType.Text:
        //            cmbOper.Items.Add("=");
        //            cmbOper.Items.Add("like");
        //            break;
        //        case  DataType.DataColumnType.DateTime:
        //            cmbOper.Items.Add("=");
        //            cmbOper.Items.Add(">");
        //            cmbOper.Items.Add("<");
        //            cmbOper.Items.Add("between");
        //            break;
        //        default:
        //            //System.Windows.Forms.MessageBox.Show("数据类型异常");
        //             cmbOper.Items.Add("=");
        //            break;
        //    }
        //}
        public void SetOperations(string masterTblname, string colName, System.Windows.Forms.DataGridViewComboBoxCell cmbOper)
        {
            string[] operNumber         = { "=", "<", ">", "<=", ">=", "between" };
            string[] operDateTime       = { "=", "<", ">", "<=", ">=", "between" };
            string[] operText           = { "=", "like" };
            string[] operDefault        = { "=" };
            DataType.DataColumnType dct = GetDataColumnType(masterTblname, colName);
            if (cmbOper != null)
            {
                cmbOper.Items.Clear();
            }
            else
            {
                cmbOper = new System.Windows.Forms.DataGridViewComboBoxCell();
            }
            ///= > < like between
            switch (dct)
            {
            case DataType.DataColumnType.Number:
                //cmbOper.Items.Add("=");
                //cmbOper.Items.Add(">");
                //cmbOper.Items.Add("<");
                //cmbOper.Items.Add("like");
                //cmbOper.Items.Add("between");
                cmbOper.Items.AddRange(operNumber);
                break;

            case DataType.DataColumnType.Text:
                //cmbOper.Items.Add("=");
                //cmbOper.Items.Add("like");
                cmbOper.Items.AddRange(operText);
                break;

            case DataType.DataColumnType.DateTime:
                //cmbOper.Items.Add("=");
                //cmbOper.Items.Add(">");
                //cmbOper.Items.Add("<");
                //cmbOper.Items.Add("between");
                cmbOper.Items.AddRange(operDateTime);
                break;

            default:
                //System.Windows.Forms.MessageBox.Show("数据类型异常");
                cmbOper.Items.AddRange(operDefault);
                break;
            }
        }
Beispiel #2
0
        // private void cbmColName_SelectedIndexChanged(object sender, EventArgs e)
        // {
        //1.根据选定的参数名称类型判定运算符号哪些显示
        //2.根据选择的运算符号决定显示的文本框个数及样式
        //3.在界面添加查询按钮,在触发查询按钮的时候组合高级查询条件
        //if (this.cbmColName.SelectedIndex == -1)
        //{
        //    return;
        //}
        //  MessageBox.Show(this.cbmColName.SelectedValue.ToString());
        // ObjectParams.NewInstance.SetOperations(ObjectParams.NewInstance.GetDataColumnType(MasterTableName, this.cbmColName.Text), this.cmbOper);
        // }

        //private void dgvExtandCols_CellContentClick(object sender, DataGridViewCellEventArgs e)
        //{
        //    //MessageBox.Show(e.ColumnIndex.ToString());
        //    //if (e.ColumnIndex == 4 && e.RowIndex != -1 && !dgvExtandCols.Rows[e.RowIndex].IsNewRow)
        //    //{

        //    //    String oper = dgvExtandCols.Rows[e.RowIndex].Cells["operation"].Value.ToString();
        //    //    if (oper != "between")
        //    //    {
        //    //       DataGridViewTextBoxCell txtbox=dgvExtandCols.Rows[e.RowIndex].Cells["val2"] as DataGridViewTextBoxCell;
        //    //       txtbox.ReadOnly = true;
        //    //    }

        //    //}
        //}

        //private void dgvExtandCols_CellClick(object sender, DataGridViewCellEventArgs e)
        //{
        //   // MessageBox.Show(e.ColumnIndex.ToString());
        //    if (e.ColumnIndex == 4 && e.RowIndex != -1 && !dgvExtandCols.Rows[e.RowIndex].IsNewRow && dgvExtandCols.Rows[e.RowIndex].Cells["operation"].Value.ToString()!="")
        //    {

        //        String oper = dgvExtandCols.Rows[e.RowIndex].Cells["operation"].Value.ToString();
        //        MessageBox.Show(oper);
        //        if (oper != "between")
        //        {
        //            DataGridViewTextBoxCell txtbox = dgvExtandCols.Rows[e.RowIndex].Cells["val2"] as DataGridViewTextBoxCell;
        //            txtbox.Value = "";
        //            txtbox.ReadOnly = true;
        //        }

        //    }
        //}

        //private void dgvExtandCols_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        //{
        //    if (e.ColumnIndex == 4 && e.RowIndex != -1 && !dgvExtandCols.Rows[e.RowIndex].IsNewRow && dgvExtandCols.Rows[e.RowIndex].Cells["operation"].Value.ToString() != "")
        //    {

        //        String oper = dgvExtandCols.Rows[e.RowIndex].Cells["operation"].Value.ToString();
        //        //MessageBox.Show(oper);
        //        if (oper != "between")
        //        {
        //            DataGridViewTextBoxCell txtbox = dgvExtandCols.Rows[e.RowIndex].Cells["val2"] as DataGridViewTextBoxCell;
        //            txtbox.Value = "";
        //            txtbox.ReadOnly = true;
        //        }

        //    }
        //}

        //private void dgvExtandCols_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        //{
        //    if (e.ColumnIndex == 4 && e.RowIndex != -1 && !dgvExtandCols.Rows[e.RowIndex].IsNewRow && dgvExtandCols.Rows[e.RowIndex].Cells["operation"].Value.ToString() != "")
        //    {

        //        String oper = dgvExtandCols.Rows[e.RowIndex].Cells["operation"].Value.ToString();
        //        //MessageBox.Show(oper);
        //        if (oper != "between")
        //        {
        //            DataGridViewTextBoxCell txtbox = dgvExtandCols.Rows[e.RowIndex].Cells["val2"] as DataGridViewTextBoxCell;
        //            txtbox.Value = "";
        //            txtbox.ReadOnly = true;
        //        }

        //    }
        //}

        private void dgvExtandCols_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex != -1 && !dgvExtandCols.Rows[e.RowIndex].IsNewRow && dgvExtandCols.Rows[e.RowIndex].Cells["operation"].Value.ToString() != "")
            {
                DataGridViewTextBoxCell txtboxval2 = dgvExtandCols.Rows[e.RowIndex].Cells["val2"] as DataGridViewTextBoxCell;
                DataGridViewTextBoxCell txtboxval1 = dgvExtandCols.Rows[e.RowIndex].Cells["val1"] as DataGridViewTextBoxCell;
                String oper = dgvExtandCols.Rows[e.RowIndex].Cells["operation"].Value.ToString();
                DataType.DataColumnType colDataType    = (DataType.DataColumnType)Enum.Parse(typeof(DataType.DataColumnType), dgvExtandCols.Rows[e.RowIndex].Cells["PARAMS_DATA_TYPE"].Value.ToString(), false);
                DataGridViewRow         currentDataRow = dgvExtandCols.Rows[e.RowIndex];
                string key   = currentDataRow.Cells["TARGET_COLNAME"].Value.ToString();
                string value = "";
                //if (e.ColumnIndex == 4)
                switch (e.ColumnIndex)
                {
                case 4:
                    //String oper = dgvExtandCols.Rows[e.RowIndex].Cells["operation"].Value.ToString();
                    //DataGridViewTextBoxCell txtboxval2 = dgvExtandCols.Rows[e.RowIndex].Cells["val2"] as DataGridViewTextBoxCell;
                    //DataGridViewTextBoxCell txtboxval1 = dgvExtandCols.Rows[e.RowIndex].Cells["val1"] as DataGridViewTextBoxCell;
                    //MessageBox.Show(oper);
                    if (oper != "between")
                    {
                        txtboxval2.Style.BackColor = Color.Gray;
                        txtboxval2.Value           = "";
                        txtboxval2.ReadOnly        = true;
                        // txtboxval1.Style.BackColor = Color.AliceBlue;
                        txtboxval1.Style.BackColor = Color.White;
                        txtboxval1.Value           = "";
                        txtboxval1.ReadOnly        = false;
                        //  txtboxval1.S
                    }
                    else
                    {
                        //txtboxval2.Style.BackColor = Color.AliceBlue;
                        txtboxval2.Style.BackColor = Color.White;
                        txtboxval2.ReadOnly        = false;

                        //txtboxval1.Style.BackColor = Color.AliceBlue;
                        txtboxval1.Style.BackColor = Color.White;
                        txtboxval1.ReadOnly        = false;
                    }
                    break;

                case 5:
                {
                    if (oper == "")
                    {
                        if (dicadvanceQueryString != null)
                        {
                            if (dicadvanceQueryString.ContainsKey(key))
                            {
                                dicadvanceQueryString.Remove(key);
                            }
                        }
                        return;
                    }

                    if (oper == "between")
                    {
                        if (txtboxval1.Value.ToString() == "" && txtboxval2.Value.ToString() == "")
                        {
                            if (dicadvanceQueryString != null)
                            {
                                if (dicadvanceQueryString.ContainsKey(key))
                                {
                                    dicadvanceQueryString.Remove(key);
                                }
                            }
                            return;
                        }

                        if (txtboxval1.Value.ToString() == "" || txtboxval2.Value.ToString() == "")
                        {
                            //// MessageBox.Show("请输入范围的起始值.", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                            // if (txtboxval1.Value.ToString() == "")
                            // {
                            //     this.dgvExtandCols.CurrentCell = dgvExtandCols.Rows[e.RowIndex].Cells["val1"];
                            //     this.dgvExtandCols.BeginEdit(true);
                            // }
                            // else
                            // {
                            //     this.dgvExtandCols.CurrentCell = dgvExtandCols.Rows[e.RowIndex].Cells["val2"];
                            //     this.dgvExtandCols.BeginEdit(true);
                            // }
                            if (dicadvanceQueryString != null)
                            {
                                if (dicadvanceQueryString.ContainsKey(key))
                                {
                                    dicadvanceQueryString.Remove(key);
                                }
                            }
                            return;
                        }
                    }
                    else
                    {
                        if (txtboxval1.Value.ToString() == "")
                        {
                            if (dicadvanceQueryString != null)
                            {
                                if (dicadvanceQueryString.ContainsKey(key))
                                {
                                    dicadvanceQueryString.Remove(key);
                                }
                            }
                            return;
                        }
                    }



                    if (oper == "like")
                    {
                        switch (colDataType)
                        {
                        case DataType.DataColumnType.DateTime:
                            //value = new StringBuilder().Append(" ").Append(oper).Append(" ").Append("'").Append(txtboxval1.Value.ToString()).Append("' AND '").Append(txtboxval2.Value.ToString()).Append("'").ToString();
                            break;

                        case DataType.DataColumnType.Number:

                            //value = new StringBuilder().Append(" ").Append(oper).Append(" ").Append(txtboxval1.Value.ToString()).Append(" AND ").Append(txtboxval2.Value.ToString()).Append("").ToString();
                            break;

                        case DataType.DataColumnType.Text:
                            value = new StringBuilder().Append(" ").Append(oper).Append(" '%").Append(txtboxval1.Value.ToString()).Append("%'").ToString();
                            break;
                        }
                    }
                    else
                    {
                        if (oper != "between")
                        {
                            //value = "'" +oper+ txtboxval1 .Value.ToString()+ "'";
                            //value = new StringBuilder().Append(oper).Append("'").Append(txtboxval1.Value.ToString()).Append("'").ToString();
                            switch (colDataType)
                            {
                            case DataType.DataColumnType.DateTime:
                                value = new StringBuilder().Append(" ").Append(oper).Append("'").Append(txtboxval1.Value.ToString()).Append("'").ToString();
                                break;

                            case DataType.DataColumnType.Number:

                                value = new StringBuilder().Append(" ").Append(oper).Append(txtboxval1.Value.ToString()).ToString();
                                break;

                            case DataType.DataColumnType.Text:
                                value = new StringBuilder().Append(" ").Append(oper).Append("'").Append(txtboxval1.Value.ToString()).Append("'").ToString();
                                break;
                            }
                        }
                        else
                        {
                            switch (colDataType)
                            {
                            case DataType.DataColumnType.DateTime:
                                value = new StringBuilder().Append(" ").Append(oper).Append(" ").Append("'").Append(txtboxval1.Value.ToString()).Append("' AND '").Append(txtboxval2.Value.ToString()).Append("'").ToString();
                                break;

                            case DataType.DataColumnType.Number:

                                value = new StringBuilder().Append(" ").Append(oper).Append(" ").Append(txtboxval1.Value.ToString()).Append(" AND ").Append(txtboxval2.Value.ToString()).Append("").ToString();
                                break;

                            case DataType.DataColumnType.Text:
                                break;
                            }
                        }
                    }
                    if (dicadvanceQueryString != null)
                    {
                        if (dicadvanceQueryString.ContainsKey(key))
                        {
                            //foreach (KeyValuePair<string, string> item in DicadvanceQueryString)
                            //{
                            //    if (item.Key == key)
                            //    {
                            //       // item.Value = value;
                            //    }
                            //    DicadvanceQueryString[key] = value;
                            //}
                            dicadvanceQueryString[key] = value;
                            //foreach(Dictionary<string,string>.Enumerator item in DicadvanceQueryString.GetEnumerator())
                            //{

                            //}
                            // DicadvanceQueryString.GetEnumerator();
                            //for(Dictionary dir in DicadvanceQueryString)
                            //{
                            //}
                            //Dictionary myDictionary = new Dictionary();
                        }
                        else
                        {
                            dicadvanceQueryString.Add(key, value);
                        }
                    }
                    else
                    {
                        dicadvanceQueryString.Add(key, value);
                    }
                    break;
                }

                case 6:      //默认为between
                {
                    if (oper == "between")
                    {
                        if (txtboxval1.Value.ToString() == "" && txtboxval2.Value.ToString() == "")
                        {
                            if (dicadvanceQueryString != null)
                            {
                                if (dicadvanceQueryString.ContainsKey(key))
                                {
                                    dicadvanceQueryString.Remove(key);
                                }
                            }
                            return;
                        }

                        if (txtboxval1.Value.ToString() == "" || txtboxval2.Value.ToString() == "")
                        {
                            if (dicadvanceQueryString != null)
                            {
                                if (dicadvanceQueryString.ContainsKey(key))
                                {
                                    dicadvanceQueryString.Remove(key);
                                }
                            }
                            return;
                        }
                        switch (colDataType)
                        {
                        case DataType.DataColumnType.DateTime:
                            value = new StringBuilder().Append(" ").Append(oper).Append(" ").Append("'").Append(txtboxval1.Value.ToString()).Append("' AND '").Append(txtboxval2.Value.ToString()).Append("'").ToString();
                            break;

                        case DataType.DataColumnType.Number:

                            value = new StringBuilder().Append(" ").Append(oper).Append(" ").Append(txtboxval1.Value.ToString()).Append(" AND ").Append(txtboxval2.Value.ToString()).Append("").ToString();
                            break;

                        case DataType.DataColumnType.Text:
                            break;
                        }
                        if (dicadvanceQueryString != null)
                        {
                            if (dicadvanceQueryString.ContainsKey(key))
                            {
                                dicadvanceQueryString[key] = value;
                            }
                            else
                            {
                                dicadvanceQueryString.Add(key, value);
                            }
                        }
                        else
                        {
                            dicadvanceQueryString.Add(key, value);
                        }
                    }
                    break;
                }
                }
            }
        }