Пример #1
0
        private void FindRoutine()
        {
            gvwProgram.BeginUpdate();
            try
            {
                if (txtSearch.Text.Trim() == "")
                {
                    return;
                }

                //Creating Temp. Table
                DataTable Tempdtbl = new DataTable("TEMPTABLE");
                Tempdtbl = dtbl.Copy();
                dtbl.Rows.Clear();


                DataRowCollection CollSearchRow = Tempdtbl.Rows;
                bool   boolFound    = false;
                string strCellVal   = "";
                int    intMaxColCtr = 0;
                string strFindText  = txtSearch.Text.Trim();

                if (strFindText.EndsWith(".00"))
                {
                    strFindText = strFindText.Substring(0, strFindText.Length - 3);
                }
                if (strFindText.EndsWith(".0"))
                {
                    strFindText = strFindText.Substring(0, strFindText.Length - 2);
                }

                if (chk_AdvanceSearch.Checked)
                {
                    intMaxColCtr = Tempdtbl.Columns.Count - 1;
                }
                else
                {
                    intMaxColCtr = 3;
                }

                for (int intRowCtr = 0; intRowCtr <= CollSearchRow.Count - 1; intRowCtr++)
                {
                    DataRow SearchRow = CollSearchRow[intRowCtr];
                    boolFound  = false;
                    strCellVal = "";
                    for (int intColCtr = 1; intColCtr <= intMaxColCtr; intColCtr++)
                    {
                        strCellVal = SearchRow[intColCtr].ToString().Trim().ToUpper();
                        if (chk_Anywhere.Checked)
                        {
                            if (strCellVal.IndexOf(strFindText.ToUpper()) >= 0)
                            {
                                boolFound = true;
                                break;
                            }
                        }
                        else
                        {
                            if (strCellVal.StartsWith(strFindText.ToUpper()))
                            {
                                boolFound = true;
                                break;
                            }
                        }
                    }
                    if (boolFound)
                    {
                        boolFetch = false;
                        object[] obj = new object[dtbl.Columns.Count];
                        for (int i = 0; i < dtbl.Columns.Count; i++)
                        {
                            obj[i] = CollSearchRow[intRowCtr][i];
                        }
                        dtbl.Rows.Add(obj);
                    }
                }
                dtbl.AcceptChanges();
            }
            finally
            {
                gvwProgram.EndUpdate();
            }
        }
Пример #2
0
        /// <summary>
        /// 设置表格列属性
        /// </summary>
        private void SetColumns()
        {
            Grid.EndEdit();
            gvSource.BeginUpdate();
            gvSource.OptionsView.ShowFooter           = cbSum.Checked;
            gvSource.OptionsView.ShowGroupPanel       = cbGroup.Checked;
            gvSource.OptionsView.ColumnAutoWidth      = cbAuto.Checked;
            gvSource.OptionsCustomization.AllowFilter = cbFilter.Checked;
            gvSource.OptionsView.AllowCellMerge       = ckMerge.Checked;

            gvSource.GroupSummary.Clear();

            foreach (DataGridViewRow dvRow in Grid.Rows)
            {
                DevExpress.XtraGrid.Columns.GridColumn gc = gvSource.Columns.ColumnByFieldName(dvRow.Cells["F_ColumnName"].Value.ToString());
                if (gc != null)
                {
                    gc.Visible = Convert.ToBoolean(dvRow.Cells["F_Visible"].Value);

                    if (Convert.ToBoolean(dvRow.Cells["F_Merge"].Value) == true)
                    {
                        gc.OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.True;
                    }
                    else
                    {
                        gc.OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.False;
                    }

                    gc.Caption = dvRow.Cells["F_ColumnCaption"].Value.ToString();

                    if (!dvRow.Cells["F_Format"].Value.Equals(DBNull.Value))
                    {
                        gc.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom;
                        if (dvRow.Cells["F_Format"].Value == null)
                        {
                            gc.DisplayFormat.FormatString = "";
                        }
                        else
                        {
                            gc.DisplayFormat.FormatString = dvRow.Cells["F_Format"].Value.ToString();
                        }
                    }

                    if (Convert.ToBoolean(dvRow.Cells["F_Edit"].Value) == true)
                    {
                        gc.AppearanceCell.BackColor = Color.White;
                        gc.OptionsColumn.AllowFocus = true;
                        gc.OptionsColumn.AllowEdit  = true;
                    }
                    else
                    {
                        gc.AppearanceCell.BackColor = Color.FromArgb(192, 255, 192);
                        gc.OptionsColumn.AllowFocus = false;
                        gc.OptionsColumn.AllowEdit  = false;
                    }



                    switch (dvRow.Cells["F_SumType"].Value.ToString())
                    {
                    case "合计":
                        gc.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;
                        break;

                    case "统计":
                        gc.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Count;
                        break;

                    case "平均":
                        gc.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Average;
                        break;

                    case "最大值":
                        gc.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Max;
                        break;

                    case "最小值":
                        gc.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Min;
                        break;

                    case "自定义":
                        gc.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Custom;
                        break;

                    case "(无)":
                        gc.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.None;
                        break;
                    }
                    if (dvRow.Cells["F_FootFormat"].Value != DBNull.Value)
                    {
                        gc.SummaryItem.DisplayFormat = dvRow.Cells["F_FootFormat"].Value.ToString();
                    }

                    if (dvRow.Cells["F_GroupType"].Value.ToString() != "(无)")
                    {
                        GridGroupSummaryItem Gi = new GridGroupSummaryItem();
                        switch (dvRow.Cells["F_GroupType"].Value.ToString())
                        {
                        case "合计":
                            Gi.SummaryType = DevExpress.Data.SummaryItemType.Sum;
                            break;

                        case "统计":
                            Gi.SummaryType = DevExpress.Data.SummaryItemType.Count;
                            break;

                        case "平均":
                            Gi.SummaryType = DevExpress.Data.SummaryItemType.Average;
                            break;

                        case "最大值":
                            Gi.SummaryType = DevExpress.Data.SummaryItemType.Max;
                            break;

                        case "最小值":
                            Gi.SummaryType = DevExpress.Data.SummaryItemType.Min;
                            break;

                        case "自定义":
                            Gi.SummaryType = DevExpress.Data.SummaryItemType.Custom;
                            break;

                        case "(无)":
                            Gi.SummaryType = DevExpress.Data.SummaryItemType.None;
                            break;
                        }
                        Gi.DisplayFormat = dvRow.Cells["F_GroupFormat"].Value.ToString();
                        Gi.ShowInGroupColumnFooterName = dvRow.Cells["F_ColumnName"].Value.ToString();
                        Gi.FieldName = dvRow.Cells["F_ColumnName"].Value.ToString();
                        gvSource.GroupSummary.Add(Gi);

                        if (dvRow.Cells["F_ColumnName"].Value.ToString() == "F_Select")
                        {
                            gc.OptionsColumn.AllowEdit = true;
                        }
                    }
                }
            }
            gvSource.EndUpdate();
        }