Esempio 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.");
        }
Esempio n. 2
0
        /// <summary>
        /// Sends table content to database if user agrees.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveTableToDatabase(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Current table in database will be deleted. Do you want to proceed?",
                                                  "Warning",
                                                  MessageBoxButtons.YesNo);

            if (result != DialogResult.Yes)
            {
                return;
            }


            using (GetUserServiceClient client = new GetUserServiceClient("NetTcpBinding_IGetUserService"))
                client.ReplaceTable(GetDataTable(MainGridView));

            Output("Saved data to database.");
        }