Exemplo n.º 1
0
        //load list of contracts from database
        public List <ContractItem> GetContracts()
        {
            try
            {
                using (MySqlConnection connection = new MySqlConnection(ConnectionSettings.ConectionVal()))
                {
                    MySqlCommand command = connection.CreateCommand();

                    command.CommandText = $"SELECT * FROM `contracts`;";

                    List <ContractItem> output = new List <ContractItem>();

                    try
                    {
                        connection.Open();
                    }
                    catch
                    {
                        MessageBox.Show("Can't Connect To DB!");
                    }

                    MySqlDataReader reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        ContractItem contract = new ContractItem
                        {
                            Id            = reader["id"].ToString(),
                            Status        = reader["status"].ToString(),
                            Worker        = reader["worker"].ToString(),
                            Date          = reader["date"].ToString().Substring(0, reader["date"].ToString().IndexOf(" ")),
                            Contact       = reader["contact"].ToString(),
                            Client        = reader["client"].ToString(),
                            InvoiceStatus = reader["invoice_status"].ToString(),
                            ExpiryDate    = reader["expiry_date"].ToString().Substring(0, reader["expiry_date"].ToString().IndexOf(" ")),
                            Other         = reader["other"].ToString()
                        };

                        output.Add(contract);
                    }

                    return(output);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(null);
            }
        }
Exemplo n.º 2
0
        //Refresh itemlist
        private void RefreshContractItems()
        {
            DataAccessContracts dataAccessContracts = new DataAccessContracts();

            Items = dataAccessContracts.GetContracts();

            //empty last item with default values
            ContractItem itemLast = new ContractItem();

            itemLast.ContractItemSet("", "Priceing", LoginWindow.LoggedIn.UserNameDB
                                     , DateTime.Today.ToString("yyyy-MM-dd"),
                                     "", "", "", DateTime.Today.AddMonths(1).ToString("yyyy-MM-dd"), "");

            Items.Add(itemLast);

            ContractsDataGrind.ItemsSource = Items;

            CheckSelection();
        }