Exemple #1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (m_DataView == null)
            {
                return;
            }

            DataTable dt = m_DataView;

            string[] colNames = Enum.GetNames(m_EnumOfSheetData);

            string strFilter = "1=1";

            for (int i = 0; i < shtQueryList.RowCount; i++)
            {
                bool        bCheck = Convert.ToBoolean(shtQueryList.Cells[i, (int)eCol.Checkbox].Value);
                eColumnType eType  = (eColumnType)Enum.Parse(typeof(eColumnType), shtQueryList.Cells[i, (int)eCol.ColumnType].Value.ToString(), true);
                if (bCheck)
                {
                    switch (eType)
                    {
                    case eColumnType.Number:

                        if (!(string.Empty.Equals(shtQueryList.Cells[i, (int)eCol.Value1].Text)))
                        {
                            strFilter += " AND " + colNames[Convert.ToInt32(shtQueryList.Cells[i, (int)eCol.ColumnIndex].Value)] + " >= " + shtQueryList.Cells[i, (int)eCol.Value1].Value.ToString();
                        }
                        if (!(string.Empty.Equals(shtQueryList.Cells[i, (int)eCol.Value2].Text)))
                        {
                            strFilter += " AND " + colNames[Convert.ToInt32(shtQueryList.Cells[i, (int)eCol.ColumnIndex].Value)] + " <= " + shtQueryList.Cells[i, (int)eCol.Value2].Value.ToString();
                        }

                        break;

                    case eColumnType.DateTime:

                        if (!(string.Empty.Equals(shtQueryList.Cells[i, (int)eCol.Value1].Text)))
                        {
                            strFilter += " AND " + colNames[Convert.ToInt32(shtQueryList.Cells[i, (int)eCol.ColumnIndex].Value)] + " >= '" + shtQueryList.Cells[i, (int)eCol.Value1].Value.ToString() + "'";
                        }
                        if (!(string.Empty.Equals(shtQueryList.Cells[i, (int)eCol.Value2].Text)))
                        {
                            strFilter += " AND " + colNames[Convert.ToInt32(shtQueryList.Cells[i, (int)eCol.ColumnIndex].Value)] + " <= '" + shtQueryList.Cells[i, (int)eCol.Value2].Value.ToString() + "'";
                        }

                        break;

                    case eColumnType.String:


                        if (!(string.Empty.Equals(shtQueryList.Cells[i, (int)eCol.Value1].Text)))
                        // Modified by Pongthorn S. @ 2012-05-18
                        //strFilter += " AND " + colNames[Convert.ToInt32(shtQueryList.Cells[i, (int)eCol.ColumnIndex].Value)] + " LIKE '%" + shtQueryList.Cells[i, (int)eCol.Value1].Value.ToString() + "%'";
                        {
                            if (shtQueryList.Cells[i, (int)eCol.ColumnName].Text != DataDefine.MASTER_NO_FIELD_NAME)
                            {
                                strFilter += " AND " + colNames[Convert.ToInt32(shtQueryList.Cells[i, (int)eCol.ColumnIndex].Value)] + " LIKE '%" + shtQueryList.Cells[i, (int)eCol.Value1].Value.ToString().Replace("'", "''") + "%'";
                            }
                            else
                            {
                                strFilter += " AND " + colNames[Convert.ToInt32(shtQueryList.Cells[i, (int)eCol.ColumnIndex].Value)] + " >= " + FilterNumbers(shtQueryList.Cells[i, (int)eCol.Value1].Value.ToString());

                                if (!(string.Empty.Equals(shtQueryList.Cells[i, (int)eCol.Value2].Text)))
                                {
                                    strFilter += " AND " + colNames[Convert.ToInt32(shtQueryList.Cells[i, (int)eCol.ColumnIndex].Value)] + " <= " + FilterNumbers(shtQueryList.Cells[i, (int)eCol.Value2].Value.ToString());
                                }
                            }
                        }

                        break;
                    }
                }
            }

            DataRow[] results;
            try
            {
                results = dt.Select(strFilter);
            }
            catch (Exception)
            {
                MessageBox.Show("Filter value is not correct.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            //DataRow[] results = dt.Select(strFilter);
            DataTable dtFilter = dt.Clone();

            //populate new destination table
            foreach (DataRow dr in results)
            {
                dtFilter.ImportRow(dr);
            }

            m_SheetViewData.DataSource = dtFilter;

            ////SortInfo[] si = new SortInfo[3];
            ////si[0] = new SortInfo(2, true);
            ////si[1] = new SortInfo(1, true);
            ////shtView.SortRows(0, shtView.RowCount, si);



            //SortInfo[] si = new SortInfo[shtQueryList.RowCount];

            ////ทำให้มันเรียง priority ก่อน
            //shtQueryList.SortRows((int)eCol.Priority, true, true);

            //int iCountSortInfo = 0;

            //for (int i = 0; i < shtQueryList.RowCount; i++)
            //{
            //    bool blCheck = Convert.ToBoolean(shtQueryList.Cells[i, (int)eCol.Checkbox].Value);

            //    if (blCheck)
            //    {
            //        bool blAscending = Convert.ToBoolean(shtQueryList.Cells[i, (int)eCol.Sorting].Value);
            //        int iColIndex = Convert.ToInt32(shtQueryList.Cells[i, (int)eCol.ColumnIndex].Value);
            //        si[iCountSortInfo] = new SortInfo(iColIndex, blAscending);
            //        iCountSortInfo++;
            //    }
            //}


            //m_SortingInfo = si;
            ////m_SheetViewData.SortRows(0, m_SheetViewData.ColumnCount, si);

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }
 public Rect GetDrawRect(eColumnType type)
 {
     return(mHeader.GetColumnRect(mHeader.GetVisibleColumnIndex((int)type)));
 }
Exemple #3
0
 public static string ColumnTypeToString(eColumnType columnType)
 {
     return(columnTypeToString[columnType]);
 }
 public bool IsColumnVisible(eColumnType type)
 {
     return(CTL_Settings.ColumnVisibility[(int)type]);
 }
Exemple #5
0
 public TableColumn(string name, string tableName, eColumnType columnType)
 {
     this.name       = name;
     this.tableName  = tableName;
     this.columnType = columnType;
 }