コード例 #1
0
        public bool DesignGridFromSQL(string sqlParam, ref string strErr)
        {
            try
            {
                strSQL = sqlParam;

                Query objQuery = new Query();

                DataSet ds = objQuery.ExecuteQueryCommand(strSQL);

                dtReadOnlyGrid = ds.Tables[0].Copy();
                dtReadOnlyGrid.TableName = "Table";
                ds.Dispose();
                //Changing For New Component
                //_BSource = new BindingSource(dtReadOnlyGrid, null);

                intColCount = dtReadOnlyGrid.Columns.Count;
                strColNames = new string[intColCount];

                for (int i = 0; i < intColCount; i++)
                    strColNames[i] = dtReadOnlyGrid.Columns[i].ColumnName;

               ///***Displaying data from a Table to a Grid and aligning the Columns***
                intColCount = dtReadOnlyGrid.Columns.Count;
                strColNames = new string[intColCount];

                for (int i = 0; i < intColCount; i++)
                    strColNames[i] = dtReadOnlyGrid.Columns[i].ColumnName;

                string[] strHeadings = new string[intColCount];

                ////**** Creating the Header text by replacing the Underscore(_)
                ////**** Symbol with the Space ( ).

                clsLanguage objLang = new clsLanguage();

                for (int i = 0; i < intColCount; i++)
                {
                    strHeadings[i] = strColNames[i].Replace("_", " ");

                    if (strLangID != null && strColNames[i].IndexOf("MASK_") < 0)
                    {
                        if (strLangID.Length >= intColCount)
                        {
                            string strTmp = objLang.LanguageString(strLangID[i]);
                            if (strTmp == "*****")
                                strHeadings[i] = "** " + strHeadings[i];
                            else
                                strHeadings[i] = strTmp;
                        }
                        else
                        {
                            if (strLangID.Length > i)
                            {
                                string strTmp = objLang.LanguageString(strLangID[i]);

                                if (strTmp == "*****")
                                    strHeadings[i] = "** " + strHeadings[i];
                                else
                                    strHeadings[i] = strTmp;
                            }
                            else
                            {
                                strHeadings[i] = "** " + strHeadings[i];
                            }
                        }
                    }
                    else
                    {
                        strHeadings[i] = "** " + strHeadings[i];
                    }
                }

                if (objLang != null)
                    objLang.Dispose();

                ////**** Creating a new Table Style to include the TextBoxes in the Datagrid
                //this.DataSource =_BSource;
                this.DataSource = dtReadOnlyGrid;
                if (SetDefault == true)
                {

                    //DataGridViewCellStyle headerstyle = new DataGridViewCellStyle();
                    //headerstyle.BackColor = System.Drawing.Color.Linen;
                    //headerstyle.ForeColor = System.Drawing.Color.Navy;
                    //this.GridColor = System.Drawing.Color.Silver;
                    //this.ColumnHeadersDefaultCellStyle.ApplyStyle(headerstyle);

                }
                else
                {
                    //this.ColumnHeadersDefaultCellStyle.BackColor = System.Drawing.Color.LightSteelBlue;
                    //this.ColumnHeadersDefaultCellStyle.ForeColor = System.Drawing.Color.Navy;
                    //this.GridColor = System.Drawing.Color.Silver;

                }

                ////**** To incorporate the Font the in DataGrid Cell.

                intVisibleColumnCount = 0;
                if (this.Columns.Count > 0)
                {
                    this.Columns.Clear();
                }
                for (int i = 0; i < intColCount; i++)
                {
                    if (strColNames[i].ToUpper().IndexOf("MASK") == 0)
                        continue;

                    intVisibleColumnCount++;

                    DataGridViewTextBoxColumn dgTBCol = new DataGridViewTextBoxColumn();
                    dgTBCol.DataPropertyName = dtReadOnlyGrid.Columns[i].ColumnName;
                    dgTBCol.HeaderText = strHeadings[i];
                    this.Columns.Add(dgTBCol);

                }
                //*****************************
                AutoSizeCol();
                if (boolLevelSearch == true)
                {
                    //this.KeyDown += new KeyEventHandler(BackSpaceKeyDown);
                    arlHierarchyLevel = new ArrayList();
                    arlHierarchyValue = new ArrayList();
                    arlPrimKey = new ArrayList();
                }
                this.AllowSorting = true;
                //***************************
                //BindingCompleted = true;
                clsReadOnlyGrid_BindingContextChanged(null, null);
                //this.Font = new Font(this.Font, FontStyle.Regular);
               // this.AutoSize = true;
                return true;
            }
            catch (Exception ex)
            {
                strErr = ex.Message + " - " + ex.Source;
                return false;
            }
        }
コード例 #2
0
        /// <summary>
        /// Executes a procedure for populating the treegridview
        /// </summary>
        /// <param name="SQLProcName">Procedure Name/SQL query string</param>
        /// <param name="isSQL">true if the supplied 'SQLProcName' if SQL query;else false</param>
        /// <param name="strErrMsg">Error message to be returned</param>
        /// <returns></returns>
        private bool ExecuteProcedure(string SQLProcName, bool isSQL, ref string strErrMsg)
        {
            try
            {
                Query objQuery = new Query();

                if (!isSQL)
                {
                    string[] arrStrProcParamNames = new string[0];
                    string[] arrStrProcParamValues = new string[0];
                    if (ProcParamNames.Count - arlOutParam.Count > 0)
                    {
                        arrStrProcParamNames = new string[ProcParamNames.Count - arlOutParam.Count];
                        arrStrProcParamValues = new string[ProcParamNames.Count - arlOutParam.Count];
                        for (int i = 0; i < ProcParamNames.Count; i++)
                        {
                            if (ProcParamValues[i] != null)
                            {
                                arrStrProcParamNames[i] = ProcParamNames[i].ToString();
                                arrStrProcParamValues[i] = ProcParamValues[i].ToString();
                            }
                        }
                        objQuery.SetInputParameterNames(SQLProcName, arrStrProcParamNames);
                        objQuery.SetInputParameterValues(arrStrProcParamValues);
                    }

                    arrStrProcParamNames = new string[arlOutParam.Count];
                    arrStrProcParamValues = new string[arlOutParam.Count];
                    int iOutParamIndex = 0;
                    for (int i = 0; i < ProcParamNames.Count; i++)
                    {
                        if (ProcParamValues[i] == null)
                        {
                            arrStrProcParamNames[iOutParamIndex++] = ProcParamNames[i].ToString();
                        }
                    }
                    objQuery.SetOutputParameterNames(SQLProcName, arrStrProcParamNames);

                    dsSource = objQuery.ExecuteQueryProcedure(SQLProcName);
                }
                else
                {
                    dsSource = objQuery.ExecuteQueryCommand(SQLProcName);
                }

                dtSource = dsSource.Tables[0].Copy();
                dsSource.Dispose();

                intColCount = dtSource.Columns.Count;
                strColNames = new string[intColCount];

                for (int i = 0; i < intColCount; i++)
                    strColNames[i] = dtSource.Columns[i].ColumnName;

                if (isSQL == false)
                {
                    strProcOutValue = new string[arlOutParam.Count];
                    for (int i = 0; i < arlOutParam.Count; i++)
                    {
                        strProcOutValue[i] = objQuery.GetOutputParameterValue(arlOutParam[i].ToString());
                    }
                }

                dtSource = dsSource.Tables[0];

                dvSource = dtSource.DefaultView;

                dvSource.AllowNew = false;
                intTotalRowCount = dvSource.Count;					//INDRANIL

                //dtSource.Columns.Add("MASK_LOAD_COL_VALUE");

                //for (int i = 0; i < dtSource.Rows.Count; i++)
                //    dtSource.Rows[i]["MASK_LOAD_COL_VALUE"] = "0";

                intColCount = dtSource.Columns.Count - 1;

                //MyGridTextBoxColumn._RowCount = dtSource.Rows.Count;

                ChangeDataTable();

                return true;
            }
            catch (Exception ex)
            {
                strErrMsg = ex.Message + " - " + ex.Source;
                return false;
            }
        }
コード例 #3
0
        public bool PopulateGrid(string sqlParam, ref string strErr)
        {
            try
            {
                strSQL = sqlParam;

                ///***Displaying data from a Table to a Grid and aligning the Columns***
                Query objQuery = new Query();

                DataSet ds = objQuery.ExecuteQueryCommand(strSQL);

                dtReadOnlyGrid = ds.Tables[0].Copy();
                ds.Dispose();

                intColCount = dtReadOnlyGrid.Columns.Count;
                strColNames = new string[intColCount];

                for (int i = 0; i < intColCount; i++)
                    strColNames[i] = dtReadOnlyGrid.Columns[i].ColumnName;

                this.DataSource = dtReadOnlyGrid;

                this.AutoSize = true;

                RowCount = dtReadOnlyGrid.Rows.Count;

                return true;
            }
            catch (Exception ex)
            {
                strErr = ex.Message + " - " + ex.Source;
                return false;
            }
        }