예제 #1
0
        public bool DeleteData(CocktailDTO cocktail)
        {
            try
            {
                conn.Open();
                command = conn.CreateCommand();

                command.CommandText = "delete from cocktail " +
                                      "where name='" + cocktail.name + "'";
                int count = command.ExecuteNonQuery();

                if (count == 1)
                {
                    MessageBox.Show("삭제 완료!!");
                    return(true);
                }
                else
                {
                    MessageBox.Show("삭제 실패ㅜ");
                    return(false);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("삭제 실패ㅜ");
                return(false);
            }
            finally
            {
                command.Dispose();
                conn.Close();
            }
        }
예제 #2
0
        private CocktailDTO SetDTO()
        {
            CocktailDTO cocktail = new CocktailDTO();

            cocktail.name       = tbName.Text;
            cocktail.alcohol    = int.Parse(tbAlcohol.Text);
            cocktail.baseLiquor = tbBaseLiquor.Text;
            cocktail.material   = tbMaterial.Text;
            cocktail.recipe     = tbRecipe.Text;

            return(cocktail);
        }
예제 #3
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            CocktailDAO cocktailDAO = new CocktailDAO();
            CocktailDTO cocktail    = SetDTO();

            bool isSuccess = cocktailDAO.UpdateData(cocktail);

            if (isSuccess)
            {
                this.Dispose();
            }
        }
예제 #4
0
        public CocktailInfo(CocktailDTO cocktail)
        {
            InitializeComponent();

            tbName.Text       = cocktail.name;
            tbAlcohol.Text    = cocktail.alcohol.ToString();
            tbBaseLiquor.Text = cocktail.baseLiquor;
            tbMaterial.Text   = cocktail.material;
            tbRecipe.Text     = cocktail.recipe;

            btnSave.Visible   = false;
            btnUpdate.Visible = true;
        }
예제 #5
0
        private void cockTailDGV_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            CocktailDTO cocktail = new CocktailDTO();
            string      name     = cockTailDGV.SelectedCells[0].Value.ToString();

            cocktail.name = name;
            cocktail      = cocktailDAO.SelectData(cocktail);

            CocktailInfo info = new CocktailInfo(cocktail);

            info.btnUpdate.Click += new EventHandler(RefreshDGV);
            info.StartPosition    = FormStartPosition.Manual;
            info.Location         = new Point(this.Location.X + 30, this.Location.Y + 30);

            info.Show();
        }
예제 #6
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            string name = cockTailDGV.SelectedCells[0].Value.ToString();

            if (name != "")
            {
                CocktailDTO cocktail = new CocktailDTO();
                cocktail.name = name;

                DialogResult result = MessageBox.Show(this, "정말로 삭제하겠습니까?", "", MessageBoxButtons.YesNo);

                if (result == DialogResult.Yes)
                {
                    cocktailDAO.DeleteData(cocktail);

                    RefreshDGV(this, EventArgs.Empty);
                }
            }
        }
예제 #7
0
        public CocktailDTO SelectData(CocktailDTO cocktail)
        {
            CocktailDTO totalInfo = new CocktailDTO();

            try
            {
                conn.Open();
                command = conn.CreateCommand();

                command.CommandText = "select * from cocktail " +
                                      "where name = '" + cocktail.name + "'";
                reader = command.ExecuteReader();

                if (reader.HasRows)
                {
                    reader.Read();
                    totalInfo.name       = reader.GetString(0);
                    totalInfo.alcohol    = reader.GetInt32(1);
                    totalInfo.baseLiquor = reader.GetString(2);
                    totalInfo.material   = reader.GetString(3);
                    totalInfo.recipe     = reader.GetString(4);

                    return(totalInfo);
                }
                else
                {
                    MessageBox.Show("불러오기 실패ㅜ");
                    return(null);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("불러오기 실패ㅜ");
                return(null);
            }
            finally
            {
                reader.Close();
                command.Dispose();
                conn.Close();
            }
        }
예제 #8
0
        public List <CocktailDTO> GetCocktails()
        {
            List <CocktailDTO> cocktails = new List <CocktailDTO>();

            try
            {
                conn.Open();
                command = conn.CreateCommand();

                command.CommandText = "select * from cocktail";
                reader = command.ExecuteReader();

                while (reader.Read())
                {
                    CocktailDTO cocktail = new CocktailDTO();

                    cocktail.name       = reader.GetString(0);
                    cocktail.alcohol    = reader.GetInt32(1);
                    cocktail.baseLiquor = reader.GetString(2);
                    cocktail.material   = reader.GetString(3);
                    cocktail.recipe     = reader.GetString(4);

                    cocktails.Add(cocktail);
                }

                //MessageBox.Show("Sussece");
            }catch (OdbcException e)
            {
                MessageBox.Show("Failure");
                Console.WriteLine(e.Message);
            }
            finally
            {
                reader.Close();
                command.Dispose();
                conn.Close();
            }

            return(cocktails);
        }
예제 #9
0
        public bool UpdateData(CocktailDTO cocktail)
        {
            try
            {
                conn.Open();
                command = conn.CreateCommand();

                command.CommandText = "update cocktail set " +
                                      "name='" + cocktail.name + "', " +
                                      "alcohol=" + cocktail.alcohol + ", " +
                                      "baseLiquor='" + cocktail.baseLiquor + "', " +
                                      "material='" + cocktail.material + "', " +
                                      "recipe='" + cocktail.recipe + "' " +
                                      "where name='" + cocktail.name + "'";
                int count = command.ExecuteNonQuery();

                if (count == 1)
                {
                    MessageBox.Show("수정 완료!!");
                    return(true);
                }
                else
                {
                    MessageBox.Show("수정 실패ㅜ");
                    return(false);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("수정 실패ㅜ");
                return(false);
            }
            finally
            {
                command.Dispose();
                conn.Close();
            }
        }
예제 #10
0
        public bool InsertData(CocktailDTO cocktail)
        {
            try
            {
                conn.Open();
                command = conn.CreateCommand();

                command.CommandText = "insert into cockTail values('"
                                      + cocktail.name + "', "
                                      + cocktail.alcohol + ", '"
                                      + cocktail.baseLiquor + "', '"
                                      + cocktail.material + "', '"
                                      + cocktail.recipe + "')";
                int count = command.ExecuteNonQuery();

                if (count == 1)
                {
                    MessageBox.Show("저장 완료!!");
                    return(true);
                }
                else
                {
                    MessageBox.Show("저장 실패ㅜ");
                    return(false);
                }
            }catch (Exception e)
            {
                MessageBox.Show("저장 실패ㅜ");
                return(false);
            }
            finally
            {
                command.Dispose();
                conn.Close();
            }
        }