private void dgvMilkTea_CellClick(object sender, DataGridViewCellEventArgs e) { index = dgvMilkTea.CurrentCell == null ? -1 : dgvMilkTea.CurrentCell.RowIndex; if (index != -1) { txtMilkTeaID.Text = dgvMilkTea.Rows[index].Cells[0].Value.ToString(); txtMilkTeaName.Text = dgvMilkTea.Rows[index].Cells[1].Value.ToString(); txtMilkTeaPrice.Text = dgvMilkTea.Rows[index].Cells[2].Value.ToString(); txtMilkTeaQuantity.Text = dgvMilkTea.Rows[index].Cells[3].Value.ToString(); MilkTea obj = dgvMilkTea.Rows[index].DataBoundItem as MilkTea; listCategory = busCT.GetListCategory(); int i = 0; foreach (Category dto in listCategory) { if (dto.CategoryID.Equals(obj.Category)) { cboCategory.SelectedIndex = i; } i++; } string cateID = busMT.getCategoryIDByMilkTeaID(txtMilkTeaID.Text); cboCategory.SelectedItem = cateID; txtImage.Text = dgvMilkTea.Rows[index].Cells[5].Value.ToString(); picbMilkTea.Image = Image.FromFile(txtImage.Text); } txtMilkTeaID.Enabled = false; btnAdd.Enabled = false; btnUpdate.Enabled = true; }
public bool AddNewMilkTea(MilkTea dto) { bool result; string sql = "insert MilkTeas values (@ID , @Name, @Quantity, @Price, @Category, @Image)"; SqlConnection cnn = DBConnection.GetConnection(); SqlCommand cmd = new SqlCommand(sql, cnn); cmd.Parameters.AddWithValue("@ID", dto.MilkTeaID); cmd.Parameters.AddWithValue("@Name", dto.MilkTeaName); cmd.Parameters.AddWithValue("@Quantity", dto.Quantity); cmd.Parameters.AddWithValue("@Price", dto.Price); cmd.Parameters.AddWithValue("@Category", dto.Category); cmd.Parameters.AddWithValue("@Image", dto.Image); try { if (cnn.State == ConnectionState.Closed) { cnn.Open(); } result = cmd.ExecuteNonQuery() > 0; } catch { return(false); } cnn.Close(); return(result); }
public List <MilkTea> SearchMilkTea(string milkteaID) { List <MilkTea> list = new List <MilkTea>(); SqlConnection cnn = DBConnection.GetConnection(); string sql = "select * from MilkTeas where MilkTeaName like " + "'%" + milkteaID + "%'"; SqlCommand cmd = new SqlCommand(sql, cnn); cnn.Open(); SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); if (reader.HasRows) { while (reader.Read()) { MilkTea milkteaDTO = new MilkTea() { MilkTeaID = reader.GetString(0), MilkTeaName = reader.GetString(1), Price = (float)reader.GetDouble(2), Quantity = reader.GetInt32(3), Category = reader.GetString(4), Image = reader.GetString(5) }; list.Add(milkteaDTO); } } cnn.Close(); return(list); }
private void btnAdd_Click(object sender, EventArgs e) { if (CheckDataToAdd()) { Category obj = (Category)cboCategory.SelectedItem; MilkTea dto = new MilkTea { MilkTeaID = txtMilkTeaID.Text, MilkTeaName = txtMilkTeaName.Text, Quantity = int.Parse(txtMilkTeaQuantity.Text), Price = float.Parse(txtMilkTeaPrice.Text), Category = obj.CategoryID, Image = txtImage.Text }; if (busMT.AddNewMilkTea(dto)) { MessageBox.Show("Add success !!!"); } else { MessageBox.Show("Add fail !!!"); } LoadData(); } }
private void Start() { UIManager = GameObject.Find("UIMANAGER").GetComponent <UIManager>(); UIManager.Interact(GetComponent <VIDE_Assign>()); order = GetComponentInChildren <MilkTea>(); if (PayEvent == null) { PayEvent = new UnityEvent(); } }
static void Main(string[] args) { DrinkBase milkTea = new MilkTea(); milkTea = new Pearl(milkTea); milkTea = new Pudding(milkTea); Console.WriteLine($"Desc: {milkTea.Desc}"); Console.WriteLine($"Total Cost: {milkTea.TotalCost}"); DrinkBase fruitTea = new FruitTea(); fruitTea = new Apple(fruitTea); fruitTea = new Peach(fruitTea); Console.WriteLine($"Desc: {fruitTea.Desc}"); Console.WriteLine($"Total Cost: {fruitTea.TotalCost}"); }
// 創立物件 // static 函數宣告:讓在主程式中,不需要實體化物件就可以使用 public static Drink CreateDrink(string order) { Drink obj = null; // 讓工廠判斷要實體化哪個物件的部分 // 可以想像成販賣機上的按鈕 switch (order) { case "紅茶": obj = new BlackTea(); break; case "奶茶": obj = new MilkTea(); break; } return(obj); }
public bool Update(MilkTea dto) { bool check = false; string sql = "Update MilkTeas Set MilkTeaName = @Name, Quantity = @Quantity, Price = @Price, CategoryID = @Category, Image = @Image Where MilkTeaID = @ID"; SqlConnection conn = DBConnection.GetConnection(); conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@ID", dto.MilkTeaID); cmd.Parameters.AddWithValue("@Name", dto.MilkTeaName); cmd.Parameters.AddWithValue("@Quantity", dto.Quantity); cmd.Parameters.AddWithValue("@Price", dto.Price); cmd.Parameters.AddWithValue("@Category", dto.Category); cmd.Parameters.AddWithValue("@Image", dto.Image); check = cmd.ExecuteNonQuery() > 0; conn.Close(); return(check); }
public List <MilkTea> GetListMilkTea() { List <MilkTea> list = new List <MilkTea>(); string sql = "select mt.MilkTeaID,mt.MilkTeaName,mt.Quantity,mt.Price,ct.CategoryName,mt.CategoryID,mt.Image " + "From MilkTeas as mt,Category as ct Where ct.CategoryID = mt.CategoryID"; SqlConnection conn = DBConnection.GetConnection(); SqlCommand cmd = new SqlCommand(sql, conn); conn.Open(); SqlDataReader read = cmd.ExecuteReader(CommandBehavior.CloseConnection); if (read.HasRows) { while (read.Read()) { MilkTea milkTeaDTO = new MilkTea() { MilkTeaID = read.GetString(0), MilkTeaName = read.GetString(1), Quantity = read.GetInt32(2), Price = (float)read.GetDouble(3), Category = read.GetString(5), Image = read.GetString(6) }; //string M ilkTeaID = read.GetString(0); // string MilkTeaName = read.GetString(1); // int Quantity = read.GetInt32(2); // float Price = (float)read.GetDouble(3); // string Category = read.GetString(4); //CategoryDTO categoryDTO = null; //foreach (CategoryDTO dto in categoryDTOs) //{ // if (dto.CategoryID.Equals(Category)) categoryDTO = dto; //} //MilkTeaDTO milkTeaDTO = new MilkTeaDTO(MilkTeaID, MilkTeaName, Quantity, Price, Category, categoryDTO); list.Add(milkTeaDTO); } } conn.Close(); return(list); }
private void btnUpdate_Click(object sender, EventArgs e) { if (CheckDataToUpdate()) { Category obj = (Category)cboCategory.SelectedItem; MilkTea dto = new MilkTea { MilkTeaID = txtMilkTeaID.Text, MilkTeaName = txtMilkTeaName.Text, Quantity = int.Parse(txtMilkTeaQuantity.Text), Price = float.Parse(txtMilkTeaPrice.Text), Category = obj.CategoryID, Image = txtImage.Text }; if (busMT.Update(dto)) { MessageBox.Show("Update successfully.", "Announce", MessageBoxButtons.OK, MessageBoxIcon.Information); } LoadData(); } }
public MilkTea FindProduct(string ID) { MilkTea milkTea = null; string sql = "select * from MilkTeas where MilkTeaID=@ID"; SqlConnection cnn = DBConnection.GetConnection(); SqlCommand cmd = new SqlCommand(sql, cnn); cmd.Parameters.AddWithValue("@ID", ID); try { if (cnn.State == ConnectionState.Closed) { cnn.Open(); } SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); if (reader.HasRows) { if (reader.Read()) { milkTea = new MilkTea(); milkTea.MilkTeaID = reader.GetString(0); milkTea.MilkTeaName = reader.GetString(1); milkTea.Price = (float)reader.GetDouble(2); milkTea.Quantity = reader.GetInt32(3); milkTea.Category = reader.GetString(4); milkTea.Image = reader.GetString(5); } } } catch (Exception e) { throw new Exception(e.Message); } cnn.Close(); return(milkTea); }
private Boolean CheckDataToAdd() { MilkTea dto = busMT.FindProduct(txtMilkTeaID.Text); if (dto != null) { error1.SetError(txtMilkTeaID, "ID is duplicate !"); txtMilkTeaID.Focus(); return(false); } else if (string.IsNullOrEmpty(txtMilkTeaID.Text)) { error1.SetError(txtMilkTeaID, "ID can't be blank !"); txtMilkTeaID.Focus(); return(false); } else if (txtMilkTeaID.Text.Length > 5) { error1.SetError(txtMilkTeaID, "ID max length is 5!"); txtMilkTeaID.Focus(); return(false); } else { error1.SetError(txtMilkTeaID, ""); } if (string.IsNullOrEmpty(txtMilkTeaName.Text)) { error1.SetError(txtMilkTeaName, "Name can't be blank !"); txtMilkTeaName.Focus(); return(false); } else if (txtMilkTeaName.Text.Length >= 50) { error1.SetError(txtMilkTeaName, "Name max length is 50!"); txtMilkTeaName.Focus(); return(false); } else { error1.SetError(txtMilkTeaName, ""); } string regexPrice = @"^\d+(.\d{1,2})?$"; if (string.IsNullOrEmpty(txtMilkTeaPrice.Text)) { error1.SetError(txtMilkTeaPrice, "Price can't be blank !"); txtMilkTeaPrice.Focus(); return(false); } if (txtMilkTeaPrice.Text.Length > 50) { error1.SetError(txtMilkTeaPrice, "Price max length is 50!"); txtMilkTeaPrice.Focus(); return(false); } if (!Regex.IsMatch(txtMilkTeaPrice.Text, regexPrice)) { error1.SetError(txtMilkTeaPrice, "Price only contains number characters"); txtMilkTeaPrice.Focus(); return(false); } else { error1.SetError(txtMilkTeaPrice, ""); } string regexQuantity = @"^\d+$"; if (string.IsNullOrEmpty(txtMilkTeaQuantity.Text)) { error1.SetError(txtMilkTeaQuantity, "Quantity can't be blank !"); txtMilkTeaQuantity.Focus(); return(false); } if (txtMilkTeaQuantity.Text.Length > 50) { error1.SetError(txtMilkTeaQuantity, "Quantity max length is 50!"); txtMilkTeaQuantity.Focus(); return(false); } if (!Regex.IsMatch(txtMilkTeaQuantity.Text, regexQuantity)) { error1.SetError(txtMilkTeaQuantity, "Quantity only contains number characters"); txtMilkTeaQuantity.Focus(); return(false); } else { error1.SetError(txtMilkTeaQuantity, ""); } if (string.IsNullOrEmpty(txtImage.Text)) { error1.SetError(txtImage, "Image can't be blank !"); txtImage.Focus(); return(false); } else if (txtImage.Text.Length > 500) { error1.SetError(txtImage, "Image max length is 500 !"); return(false); } else { error1.SetError(txtImage, ""); } return(true); }
public bool Update(MilkTea dto) { return(dao.Update(dto)); }
public bool AddNewMilkTea(MilkTea dto) { return(dao.AddNewMilkTea(dto)); }
public MilkTeaDecorator(MilkTea milkTea) { this.milkTea = milkTea; }