Exemple #1
0
 public void Clear()
 {
     selectedCustomer = null;
     textBox1.Text = "";
     textBox4.Text = "";
     textBox3.Text = "";
     textBox5.Text = "";
 }
Exemple #2
0
 public EditCustomerForm(Customer c)
     : this()
 {
     this.Text = "Edit Customer";
     this.SaveBtn.Text = "Update";
     cust = c;
     NameTxt.Text = c.Name;
     PhnNum.Text = c.PhoneNumber;
     Email.Text = c.Email;
     address.Text = c.Address;
 }
Exemple #3
0
 private void button1_Click(object sender, EventArgs e)
 {
     CustomersForm form = new CustomersForm(textBox1.Text, textBox4.Text, textBox3.Text, textBox5.Text);
     if (form.ShowDialog() == DialogResult.OK)
     {
         if (form.SelectedCustomer != null)
         {
             selectedCustomer = form.SelectedCustomer;
             textBox1.Text = form.SelectedCustomer.Name;
             textBox4.Text = form.SelectedCustomer.PhoneNumber;
             textBox3.Text = form.SelectedCustomer.Address;
             textBox5.Text = form.SelectedCustomer.Email;
         }
     }
 }
Exemple #4
0
 public bool CreateCustomer(out Customer newCustomer)
 {
     newCustomer = selectedCustomer;
     if (selectedCustomer == null)
     {
         if (textBox1.Text == "" && (textBox3.Text != "" || textBox4.Text != "" || textBox5.Text != ""))
         {
             MessageBox.Show("Please enter a customer name.");
             return false;
         }
         else if(textBox1.Text != "")
         {
             selectedCustomer = DataLayer.CreateCustomer(textBox1.Text, textBox4.Text, textBox3.Text, textBox5.Text);
             newCustomer = selectedCustomer;
         }
     }
     return true;
 }
Exemple #5
0
 private void SaveBtn_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrWhiteSpace(NameTxt.Text))
     {
         MessageBox.Show("Please enter a name.");
         return;
     }
     if (cust != null)
     {
         cust.Name = NameTxt.Text;
         cust.PhoneNumber = PhnNum.Text;
         cust.Email = Email.Text;
         cust.Address = address.Text;
     }
     else
     {
         cust = DataLayer.CreateCustomer(NameTxt.Text,PhnNum.Text,address.Text,Email.Text);
     }
     DialogResult = System.Windows.Forms.DialogResult.OK;
 }
Exemple #6
0
 public static void ToggleCustomerDeleted(Customer customer, bool deleted)
 {
     using (SqlCeCommand cmd = new SqlCeCommand(@"update Customer set isRemoved = @deleted
                                                  where CustomerID = @CustomerID"))
     {
         cmd.Parameters.AddWithValue("@deleted", deleted);
         cmd.Parameters.AddWithValue("@customerId", customer.CustomerId);
         ExecuteNonQuery(cmd);
     }
 }
Exemple #7
0
 /// <summary>
 /// Updates the sell information for an inventoryItem
 /// </summary>
 /// <param name="inventoryItem">The item that is being sold</param>
 /// <param name="customer">The customer that is purchasing the item</param>
 /// <param name="date">The date it was purchased</param>
 /// <param name="sellPrice">The price the item was sold for</param>
 public static void SellInventory(InventoryItem inventoryItem, Customer customer, DateTime date, double sellPrice)
 {
     if (inventoryItem == null)
         throw new ArgumentNullException("Inventory Item cannot be null");
     using (SqlCeCommand cmd = new SqlCeCommand(@"update Inventory set soldPrice = @soldPrice, dateSold = @dateSold, buyer = @buyer where inventoryId = @inventoryId"))
     {
         cmd.Parameters.AddWithValue("@soldPrice", sellPrice);
         cmd.Parameters.AddWithValue("@dateSold", date.Date);
         cmd.Parameters.AddWithValue("@buyer", customer != null ? (object)customer.CustomerId : DBNull.Value);
         cmd.Parameters.AddWithValue("@inventoryId", inventoryItem.InvnetoryId);
         ExecuteNonQuery(cmd);
     }
 }
Exemple #8
0
 /// <summary>
 /// Adds the purchased media to the list of inventory
 /// </summary>
 /// <param name="media">The Media that was purchased</param>
 /// <param name="customer">The customer that you purchased the media from (This field can be null)</param>
 /// <param name="datePurchased">The data the media was purchased</param>
 /// <param name="purchasePrice">The price paid for the media</param>
 /// <param name="quality">The quality of the media</param>
 /// <param name="description">A short description of the media(Look, Damages...) to be able to make sure you found the correct physical media</param>
 /// <returns>returns the new Inventory entry</returns>
 public static InventoryItem PurchaseInventory(Media media, Customer seller, DateTime datePurchased, double purchasePrice, Quality quality, string description)
 {
     using (SqlCeCommand cmd = new SqlCeCommand(@"insert into Inventory (datePurchased,purchasePrice,quality,mediaId,description,seller)
                                                 values (@datePurchased,@purchasePrice,@quality,@mediaId,@description,@seller)"))
     {
         cmd.Parameters.AddWithValue("@datePurchased", datePurchased.Date);
         cmd.Parameters.AddWithValue("@purchasePrice", purchasePrice);
         cmd.Parameters.AddWithValue("@quality", QualityString(quality));
         cmd.Parameters.AddWithValue("@mediaId", media.MediaId);
         cmd.Parameters.AddWithValue("@description", (object)description ?? DBNull.Value);
         cmd.Parameters.AddWithValue("@seller", seller != null ? (object)seller.CustomerId : DBNull.Value);
         int id = ExecuteCreate(cmd);
         using (SqlCeCommand select = new SqlCeCommand("select * from Inventory inner join Media on Media.MediaID = Inventory.MediaID where inventoryId = @inventoryId"))
         {
             select.Parameters.AddWithValue("@inventoryId", id);
             IDataReader reader = ExecuteReader(select);
             if (reader.Read())
             {
                 return InventoryItem.Load(reader);
             }
             throw new Exception("Unable to create the inventory item. Unknown error.");
         }
     }
 }
Exemple #9
0
 internal static Customer Load(IDataReader reader)
 {
     int id = (int)reader["customerId"];
     if (cachedCustomer.ContainsKey(id))
         return cachedCustomer[id];
     else
     {
         Customer c = new Customer(reader);
         cachedCustomer[id] = c;
         return c;
     }
 }
Exemple #10
0
 /// <summary>
 /// Gets all media that a customer has bought or sold to pats tracks
 /// </summary>
 /// <param name="customer">The customer to get the history for</param>
 /// <returns></returns>
 public static Filter ByCustomer(Customer customer)
 {
     return OrFilter(BySeller(customer), ByBuyer(customer));
 }
Exemple #11
0
 /// <summary>
 /// Gets all media that this customer bought from us
 /// </summary>
 /// <param name="customer">The customer that bought the media</param>
 /// <returns></returns>
 public static Filter ByBuyer(Customer customer)
 {
     return new ColumnFilter(FilterTables.Inventory, "Inventory.buyer = " + customer.CustomerId);
 }
Exemple #12
0
 public void Sell(Customer customer, DateTime date, double sellPrice)
 {
     DataLayer.SellInventory(this, customer, date, sellPrice);
     this.buyer = customer;
     this.buyerId = customer == null ? null : (int?)customer.CustomerId;
     this.SoldPrice = sellPrice;
     this.DateSold = date;
 }
Exemple #13
0
 private void _createBtn_Click(object sender, EventArgs e)
 {
     if (_nameTxt.Text == "")
     {
         MessageBox.Show("Please enter a customer name. Customer name is required");
         return;
     }
     SelectedCustomer = DataLayer.CreateCustomer(_nameTxt.Text,_phoneTxt.Text,_addressTxt.Text,_emailTxt.Text);
     DialogResult = System.Windows.Forms.DialogResult.OK;
 }
Exemple #14
0
 private void button3_Click(object sender, EventArgs e)
 {
     SelectedCustomer = null;
     DialogResult = System.Windows.Forms.DialogResult.Cancel;
 }
Exemple #15
0
 private void _selectBtn_Click(object sender, EventArgs e)
 {
     if (customerDataGridControl1.SelectedCustomer != null)
     {
         SelectedCustomer = customerDataGridControl1.SelectedCustomer;
         DialogResult = System.Windows.Forms.DialogResult.OK;
     }
     else
     {
         MessageBox.Show("Please select a customer from the list of customers.");
     }
 }