예제 #1
0
        private void btnXoa_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult key = MessageBox.Show(
                "Bạn có muốn xóa?",
                "Xóa?",
                MessageBoxButton.YesNo,
                MessageBoxImage.Question,
                MessageBoxResult.No);

            if (key == MessageBoxResult.No)
            {
                return;
            }
            else
            {
                {
                    if (txtma.Text == "")
                    {
                        MessageBox.Show("Không được bỏ trống mã hàng");
                    }

                    else
                    {
                        DienThoai sv = new DienThoai();
                        sv.ma     = txtma.Text;
                        sv.tonkho = txttonkho.Text;
                        Xoa_dien_thoai(sv);
                    }
                }
            }
        }
예제 #2
0
        private void Cap_nhat_dien_thoai(DienThoai dienthoaii)
        {
            try
            {
                DataTable danhsach = new DataTable();
                using (SqlConnection connection =
                           new SqlConnection(@"Server=DESKTOP-6N9SC5N;Database=quanlydienthoai; Integrated Security=SSPI"))
                    using (SqlCommand command =
                               new SqlCommand("SELECT * FROM Dienthoai;", connection))
                        using (SqlDataAdapter adapter = new SqlDataAdapter(command))
                            using (SqlCommandBuilder builder = new SqlCommandBuilder(adapter))
                            {
                                adapter.FillSchema(danhsach, SchemaType.Source);
                                adapter.Fill(danhsach);
                                DataRow[] dt = danhsach.Select(
                                    "ma = '" + dienthoaii.ma + "'");
                                dt[0]["dongia"] = dienthoaii.dongia;
                                dt[0]["tonkho"] = dienthoaii.tonkho;

                                adapter.Update(danhsach);
                                MessageBox.Show("Cập nhật dữ liệu thành công!");
                                dulieu.ItemsSource = danhsach.DefaultView;
                            }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Loi khi mo ket noi: " + ex.Message);
            }
        }
예제 #3
0
        private void Xoa_dien_thoai(DienThoai dienthoaii)
        {
            try
            {
                DataTable danhsach = new DataTable();
                using (SqlConnection connection =
                           new SqlConnection(@"Server=DESKTOP-6N9SC5N;Database=quanlydienthoai; Integrated Security=SSPI"))
                    using (SqlCommand command =
                               new SqlCommand("SELECT * FROM Dienthoai;", connection))
                        using (SqlDataAdapter adapter = new SqlDataAdapter(command))
                            using (SqlCommandBuilder builder = new SqlCommandBuilder(adapter))
                            {
                                adapter.FillSchema(danhsach, SchemaType.Source);
                                adapter.Fill(danhsach);
                                //DataRow[] dt = danhsach.Select("ma = '" + dienthoaii.ma + "'");

                                DataRow[] dt = danhsach.Select(
                                    "ma = '" + dienthoaii.ma + "'");



                                if ((int)dt[0]["tonkho"] == 0)
                                {
                                    MessageBoxResult key = MessageBox.Show(
                                        "Bạn muốn xóa dòng điện thoại này khỏi cơ sở dữ liệu?",
                                        "Xóa?",
                                        MessageBoxButton.YesNo,
                                        MessageBoxImage.Question,
                                        MessageBoxResult.No);
                                    if (key == MessageBoxResult.No)
                                    {
                                        return;
                                    }
                                    else
                                    {
                                        danhsach.Select("ma = '" + dienthoaii.ma + "'");
                                        dt[0].Delete();
                                        adapter.Update(dt);
                                        MessageBox.Show("Xóa dữ liệu thành công!");
                                        dulieu.ItemsSource = danhsach.DefaultView;
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Khong thể xóa vì còn hàng");
                                }
                            }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Loi khi mo ket noi: " + ex.Message);
            }
        }
예제 #4
0
 private void Them_dien_thoai(DienThoai dienthoaii)
 {
 }
예제 #5
0
        private void checktanggiamgia(DienThoai dienthoaii)
        {
            int dongiaa;

            try
            {
                DataTable danhsach = new DataTable();
                using (SqlConnection connection =
                           new SqlConnection(@"Server=DESKTOP-6N9SC5N;Database=quanlydienthoai; Integrated Security=SSPI"))
                    using (SqlCommand command =
                               new SqlCommand("SELECT * FROM Dienthoai;", connection))
                        using (SqlDataAdapter adapter = new SqlDataAdapter(command))
                            using (SqlCommandBuilder builder = new SqlCommandBuilder(adapter))
                            {
                                adapter.FillSchema(danhsach, SchemaType.Source);
                                adapter.Fill(danhsach);

                                DataRow[] dt = danhsach.Select(
                                    "ma = '" + dienthoaii.ma + "'");
                                dongiaa = (int)dt[0]["dongia"];
                            }

                if (dongiaa > Int32.Parse(txtdongia.Text))
                {
                    //GiamGia(dienthoaii);
                    MessageBoxResult key = MessageBox.Show(
                        "Mặt hàng điện thoại này giảm giá?",
                        "Thông báo",
                        MessageBoxButton.YesNo,
                        MessageBoxImage.Question,
                        MessageBoxResult.No);
                    if (key == MessageBoxResult.No)
                    {
                        return;
                    }
                    else
                    {
                        Cap_nhat_dien_thoai(dienthoaii);
                    }
                }

                else
                {
                    MessageBoxResult key = MessageBox.Show(
                        "Mặt hàng điện thoại này tăng giá?",
                        "Thông báo",
                        MessageBoxButton.YesNo,
                        MessageBoxImage.Question,
                        MessageBoxResult.No);
                    if (key == MessageBoxResult.No)
                    {
                        return;
                    }
                    else
                    {
                        Cap_nhat_dien_thoai(dienthoaii);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Loi khi mo ket noi " + ex.Message);
            }
        }
예제 #6
0
        private void btnCapnhat_Click(object sender, RoutedEventArgs e)
        {
            if (cndl == 1)
            {
                MessageBoxResult key = MessageBox.Show(
                    "Bạn có muốn cập nhật dữ liệu?",
                    "Cập nhật kho",
                    MessageBoxButton.YesNo,
                    MessageBoxImage.Question,
                    MessageBoxResult.No);
                if (key == MessageBoxResult.No)
                {
                    return;
                }
                else
                {
                    if (txtma.Text.Length == 0 || txtdongia.Text.Length == 0 || txttonkho.Text.Length == 0)
                    {
                        MessageBox.Show("Không được bỏ trống");
                    }

                    else



                    {
                        int a = int.Parse(txtdongia.Text);
                        int b = int.Parse(txttonkho.Text);

                        if (a < 0 || b < 0)
                        {
                            MessageBox.Show("Không thể nhập số âm");
                        }
                        else
                        {
                            if (a % 1000 != 0)
                            {
                                MessageBox.Show("Đơn giá cần phải chia hết cho 1000", "Dữ liệu lỗi");
                            }
                            else
                            {
                                DienThoai sv = new DienThoai();
                                txtma.MaxLength = 9;
                                sv.ma           = txtma.Text;
                                sv.dongia       = txtdongia.Text;
                                sv.tonkho       = txttonkho.Text;
                                //Cap_nhat_dien_thoai(sv);

                                /*sv.mahang = txtma.Text;
                                 * sv.dongia = txtdongia.Text;
                                 * sv.tonkho = txttonkho.Text;*/
                                checktanggiamgia(sv);
                            }
                        }
                    }
                }
            }

            else
            {
                MessageBox.Show("Dữ liệu bị khóa");
            }
        }