示例#1
0
        public void LoadDataBase(string SQL)
        {
            string        nSQL = SQL;
            string        nConnectionString = ConnectDataBase.ConnectionString;
            SqlConnection nConnect          = new SqlConnection(nConnectionString);

            nConnect.Open();
            try
            {
                SqlCommand nCommand = new SqlCommand(nSQL, nConnect);
                nCommand.CommandType = CommandType.Text;

                SqlDataReader nReader = nCommand.ExecuteReader();
                int           i       = 0;
                if (nReader.HasRows)
                {
                    while (nReader.Read())
                    {
                        GridViewData.Rows.Add();
                        GridViewData.Rows[i].Cells[0].Value = i + 1;
                        GridViewData.Rows[i].Cells[1].Value = nReader[m_FieldDisplay].ToString();
                        GridViewData.Rows[i].Cells[1].Tag   = nReader[m_FieldValue];
                        GridViewData.AutoResizeRow(i);

                        i++;
                    }
                }
                nReader.Close();
                nCommand.Dispose();
                GridViewData.Rows[i].Cells[0].Value = i + 1;
                GridViewData.Rows[i].Cells[1].Tag   = "";
            }
            catch (Exception Err)
            {
                m_Message = Err.ToString();
            }
            finally
            {
                nConnect.Close();
            }
        }
示例#2
0
        private void GridViewData_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow nRow = GridViewData.Rows[e.RowIndex];

            if (nRow.Cells[1].Value == null)
            {
                nRow.Cells[1].ErrorText = "Không được nhập rỗng";
            }
            else
            {
                nRow.Cells[1].ErrorText = null;
                string nCategoryName = nRow.Cells[1].Value.ToString();
                if (!nRow.IsNewRow && (nRow.Cells[1].Tag != null && nRow.Cells[1].Tag.ToString().Length != 0))
                {
                    string nCategoryKey = nRow.Cells[1].Tag.ToString();
                    UpdateCategory(nCategoryKey, nCategoryName);
                }
                if (nRow.Index == GridViewData.Rows.Count - 2 && (nRow.Cells[1].Tag == null || (int)nRow.Cells[1].Tag.ToString().Length == 0))
                {
                    nRow.Cells[1].Tag = CreateCategory(nCategoryName);
                }
            }
            GridViewData.AutoResizeRow(e.RowIndex);
        }