void BtnAddClick(object sender, EventArgs e)
 {
     if(btnAdd.Text == "Add")
     {
         Enabler(true);
         btnAdd.Text = "Save";
         btnCancel.Visible = true;
         if(pos.Count>0)
         {
             cbxPOs.SelectedIndex = 0;
         }
     }
     else
     {
         btnCancel.Visible = false;
         lblLoading.Text = "Adding Invoice. Please Wait.";
         lblLoading.Visible = true;
         Enabler(false);
         btnAdd.Text = "Add";
         Invoice theInvoice = new Invoice();
         theInvoice.MacsTracID = int.Parse(nudInvoice.Value.ToString());
         theInvoice.Amount = nudAmount.Value;
         if(cbxPOs.SelectedIndex >= 0)
         {
             theInvoice.PONumber = cbxPOs.SelectedItem.ToString();
         }
         theInvoice.Date = dtpDate.Value;
         theInvoice.ClientID = clientID;
         Model.AddInvoice(theInvoice);
         LoadInvoices();
         lblLoading.Visible = false;
     }
 }
Example #2
0
        public static bool UpdateInvoice(Invoice theInvoice)
        {
            if(theConnection.ConnectionString == string.Empty)
            {
                theConnection.ConnectionString = connectionString;
            }
            try
            {
                theConnection.Open();
                theCommand.Connection = theConnection;

                commandString = "update Invoices set clientID = @clientID,amount = @amount,date = @date,invoiceMTNumber = @invoiceMTNumber," +
                    "poMTNumber = @poMTNumber where invoiceID = " + theInvoice.ID;
                theCommand.CommandText = commandString;
                theCommand.Prepare();

                theCommand.Parameters.Clear();
                theCommand.Parameters.AddWithValue("@clientID",1111);
                theCommand.Parameters.AddWithValue("@amount",111111.11);
                theCommand.Parameters.AddWithValue("@date",DateTime.Now.ToShortDateString());
                theCommand.Parameters.AddWithValue("@invoiceMTNumber",111111);
                theCommand.Parameters.AddWithValue("@poMTNumber","the po");
                theCommand.Parameters["@clientID"].Value = theInvoice.ClientID;
                theCommand.Parameters["@amount"].Value = theInvoice.Amount;
                string day;
                string month;
                if(theInvoice.Date.Day<10)
                {
                    day = "0" + theInvoice.Date.Day;
                }
                else
                {
                    day = theInvoice.Date.Day.ToString();
                }
                if(theInvoice.Date.Month<10)
                {
                    month = "0" + theInvoice.Date.Month;
                }
                else
                {
                    month = theInvoice.Date.Month.ToString();
                }
                string date = theInvoice.Date.Year + "-" + month + "-" + day;
                theCommand.Parameters["@date"].Value = date;
                theCommand.Parameters["@invoiceMTNumber"].Value = theInvoice.MacsTracID;
                theCommand.Parameters["@poMTNumber"].Value = theInvoice.PONumber;
                theCommand.ExecuteNonQuery();

                return true;
            }
            catch(MySqlException ex)
            {
                return false;
            }
            finally
            {
                theConnection.Close();
            }
        }
Example #3
0
        public static List<Invoice> GetInvoices(int clientID)
        {
            if(theConnection.ConnectionString == string.Empty)
            {
                theConnection.ConnectionString = connectionString;
            }
            List<Invoice> theInvoices = new List<Invoice>();
            Invoice theInvoice;
            try
            {
                commandString = "select * from Invoices where clientID = " + clientID;
                theConnection.Open();
                theCommand.Connection = theConnection;
                theCommand.CommandText = commandString;
                reader = theCommand.ExecuteReader();
                while (reader.Read())
                {
                    theInvoice = new Invoice();
                    theInvoice.Amount = decimal.Parse(reader["amount"].ToString());
                    theInvoice.ClientID = int.Parse(reader["clientID"].ToString());
                    theInvoice.Date = DateTime.Parse(reader["date"].ToString());
                    theInvoice.ID = int.Parse(reader["invoiceID"].ToString());
                    theInvoice.MacsTracID = int.Parse(reader["invoiceMTNumber"].ToString());
                    if(reader["poMTNumber"] != null)
                    {
                        theInvoice.PONumber = reader["poMTNumber"].ToString();
                    }
                    theInvoices.Add(theInvoice);
                }
                return theInvoices;

            }
            catch (MySqlException ex)
            {
                return new List<Invoice>();
            }
            finally
            {
                theConnection.Close();
            }
        }