Ejemplo n.º 1
0
        /// <summary>
        /// Retrieves table from database.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LoadTableFromDatabase(object sender, EventArgs e)
        {
            using (GetUserServiceClient client = new GetUserServiceClient("NetTcpBinding_IGetUserService"))
            {
                DataSet set = client.GetTable();

                if (set.DataSetName == "Error")
                {
                    MessageBox.Show("Client could not connect to database. Server is either unavailable or you are not connected to the internet.",
                                    "Connection error");
                    return;
                }
                DataTable table = set.Tables[0];

                RefreshDataGridView(MainGridView);

                MainGridView.DataSource = table;
                foreach (DataGridViewColumn column in MainGridView.Columns)
                {
                    column.HeaderText = table.Columns[MainGridView.Columns.IndexOf(column)].Caption;
                }
            }

            ChangedCells.Clear();
            BadCells.Clear();
            SetButtons(true, true, true);
            LoadSettings();
            Output("Loaded data from database.");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads table from XML file.
        /// </summary>
        private void LoadFromXML()
        {
            if (!File.Exists(XmlPath))
            {
                MainGridView.Rows.Clear();
                return;
            }

            RefreshDataGridView(MainGridView);

            using (DataSet set = new DataSet())
            {
                set.ReadXml(XmlPath, XmlReadMode.ReadSchema);

                MainGridView.DataSource = set.Tables[0];

                foreach (DataGridViewColumn column in MainGridView.Columns)
                {
                    column.HeaderText = set.Tables[0].Columns[MainGridView.Columns.IndexOf(column)].Caption;
                }
            }

            ChangedCells.Clear();
            BadCells.Clear();

            SetButtons(false, false, true);
            LoadSettings();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Changes given cell based on it's formatting
        /// </summary>
        /// <param name="cell"></param>
        /// <param name="isFormattingCorrect"></param>
        private void SetCell(DataGridViewCell cell, bool isFormattingCorrect)
        {
            if (isFormattingCorrect)
            {
                if (BadCells.Contains(cell))
                {
                    BadCells.Remove(cell);
                }
                cell.Style.BackColor = Color.PaleGreen;
            }
            else
            {
                if (!BadCells.Contains(cell))
                {
                    BadCells.Add(cell);
                }
                cell.Style.BackColor = Color.IndianRed;
            }

            if (MainGridView.Columns[cell.ColumnIndex].Name == "Apartment")
            {
                if (!ChangedCells.Contains(cell))
                {
                    cell.Style.BackColor = Color.Empty;
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Deletes content of given DataGridView.
        /// </summary>
        /// <param name="gridView"></param>
        private void RefreshDataGridView(DataGridView gridView)
        {
            gridView.Columns.Clear();

            DataTable DT = (DataTable)gridView.DataSource;

            DT?.Clear();
            BadCells.Clear();
            ChangedCells.Clear();

            gridView.Refresh();
        }
Ejemplo n.º 5
0
        private void DataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
            {
                return;
            }

            DataGridViewCell currentCell    = MainGridView[e.ColumnIndex, e.RowIndex];
            bool             isInputCorrect = CheckCell(currentCell);

            SetCell(currentCell, isInputCorrect);

            ChangedCells.Add(currentCell);

            SetButtons(!BadCells.Any(), true, !BadCells.Any());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Remove cells inside the given row.
        /// </summary>
        /// <param name="row"></param>
        private void DeleteCellsFromRow(DataGridViewRow row)
        {
            foreach (DataGridViewCell cell in row.Cells)
            {
                if (ChangedCells.Contains(cell))
                {
                    ChangedCells.Remove(cell);
                }
                if (BadCells.Contains(cell))
                {
                    BadCells.Remove(cell);
                }
            }

            if (!BadCells.Any())
            {
                SetButtons(true, true, true);
            }
        }