Beispiel #1
0
        private void FillGrid()
        {
            LoadingGrid = true;
            cn          = new SQLiteConnection("Data Source=" + FileToUse + "; FailIfMissing=true");
            cn.SetPassword(Password);
            cn.Open();
            string SQL;

            SQL = "SELECT * FROM Rooms";
            SQLiteCommand cmd = new SQLiteCommand(SQL, cn);

            da = new SQLiteDataAdapter(cmd);
            ds = new DataSet();
            try
            {
                da.Fill(ds);
                DataTable dt = ds.Tables[0];
                bindingSource1.DataSource         = dt;
                RoomsNavigator.BindingSource      = bindingSource1;
                RoomsGrid.DataSource              = bindingSource1;
                RoomsGrid.AutoGenerateColumns     = true;
                RoomsGrid.Columns[0].Visible      = false;
                RoomsGrid.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                RoomsGrid.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            }
            catch (Exception ex)
            {
                Close();
            }
            sqCommandBuilder = new SQLiteCommandBuilder(da);
            if (RoomsGrid.SortedColumn == null)
            {
                //               RoomsGrid.Sort(RoomsGrid.Columns[1], ListSortDirection.Ascending);
            }
            else
            {
                if (RoomsGrid.SortOrder == SortOrder.Ascending)
                {
                    RoomsGrid.Sort(RoomsGrid.SortedColumn, ListSortDirection.Ascending);
                }
                else
                {
                    RoomsGrid.Sort(RoomsGrid.SortedColumn, ListSortDirection.Descending);
                }
            }

            for (int i = 0; i < RoomsGrid.ColumnCount; i++)
            {
                RoomsGrid.Columns[i].SortMode = DataGridViewColumnSortMode.Automatic;
            }

            LoadingGrid             = false;
            SaveAndContinue.Enabled = false;
            SaveAndExit.Enabled     = false;
            toolStripButton9.Text   = "Exit";
        }
Beispiel #2
0
        private void Save_Click(object sender, EventArgs e)
        {
            int i = 1;

            RoomsGrid.EndEdit();
            try
            {
                i = RoomsGrid.CurrentCell.RowIndex;
            }
            catch (Exception ex)
            {
            }

            try
            {
                RoomsGrid.EndEdit();
                if (RoomsGrid.RowCount == 1)
                {
                    RoomsGrid.CurrentCell = RoomsGrid[1, 0];
                    bindingNavigatorAddNewItem1.PerformClick();
                    RoomsGrid.CurrentCell = RoomsGrid[1, 1];
                    bindingSource1.RemoveCurrent();
                    RoomsGrid.CurrentCell = RoomsGrid[1, 0];
                }
                else
                {
                    if (i > 1)
                    {
                        RoomsGrid.CurrentCell = RoomsGrid[1, i - 1];
                    }
                    else
                    {
                        RoomsGrid.CurrentCell = RoomsGrid[1, 0];
                        RoomsGrid.CurrentCell = RoomsGrid[1, 1];
                        RoomsGrid.CurrentCell = RoomsGrid[1, 0];
                    }
                    RoomsGrid.CurrentCell = RoomsGrid[1, i];
                }
            }
            catch (Exception ex)
            {
            }

            try
            {
                LoadingGrid = true;
                RoomsGrid.EndEdit();
                da.Update(ds.Tables[0]);
                ds.Tables[0].AcceptChanges();
                FillGrid();
                LoadingGrid = false;
            }
            catch (Exception ex)
            {
            }

            System.Windows.Forms.ToolStripButton B = (System.Windows.Forms.ToolStripButton)sender;
            if ((B.Name == "SaveAndExit"))
            {
                Close();
            }
        }