コード例 #1
0
        private void btnLuuLoaiMon_Click(object sender, RoutedEventArgs e)
        {
            if (txtTenLoaiMon.Text == "")
            {
                MessageBox.Show("Bạn phải nhập tên loại món!", "Lỗi!", MessageBoxButton.OK, MessageBoxImage.Error);
                txtTenLoaiMon.Focus();
            }
            else
            {
                try
                {
                    if (themLoaiMon)
                    {
                        QLMonAnLoaiMon qlmalm = new QLMonAnLoaiMon();
                        qlmalm.ThemLoaiMon(txtTenLoaiMon.Text);
                        MessageBox.Show("Đã thêm xong!", "Notify!", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        QLMonAnLoaiMon qlmalm = new QLMonAnLoaiMon();
                        qlmalm.CapNhatLoaiMon(maLoaiMon, txtTenLoaiMon.Text);
                        MessageBox.Show("Đã sửa thông tin loại món vừa chọn!", "Notify!", MessageBoxButton.OK, MessageBoxImage.Information);
                    }

                    LoadLoaiMon();
                    DgvLoaiMon.IsEnabled   = true;
                    cbxLoaiMon.ItemsSource = qlmalm.DSLoaiMon().DefaultView;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Lỗi!", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
コード例 #2
0
        private void btnLuuMonAn_Click(object sender, RoutedEventArgs e)
        {
            if (txtTenMonAn.Text == "")
            {
                MessageBox.Show("Bạn phải nhập tên món!", "Lỗi!", MessageBoxButton.OK, MessageBoxImage.Error);
                txtTenMonAn.Focus();
            }
            else if (txtGiaTien.Text == "")
            {
                MessageBox.Show("Bạn phải nhập giá tiền!", "Lỗi!", MessageBoxButton.OK, MessageBoxImage.Error);
                txtTenMonAn.Focus();
            }
            else
            if (cbxLoaiMon.Text == "")
            {
                MessageBox.Show("Bạn phải chọn loại món!", "Lỗi!", MessageBoxButton.OK, MessageBoxImage.Error);
                txtTenMonAn.Focus();
            }
            else
            {
                try
                {
                    if (themMonAn)
                    {
                        string filePath = "./Images/HinhMonAn/HinhMonAn" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".png";

                        var encoder = new PngBitmapEncoder();
                        encoder.Frames.Add(BitmapFrame.Create((BitmapSource)imgMonAn.Source));
                        using (FileStream stream = new FileStream(filePath, FileMode.Create))
                            encoder.Save(stream);
                        QLMonAnLoaiMon qlmalm = new QLMonAnLoaiMon();
                        qlmalm.ThemMonAn(txtTenMonAn.Text, cbxLoaiMon.Text, Convert.ToInt32(txtGiaTien.Text), filePath);
                        MessageBox.Show("Đã thêm xong!", "Notify!", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        string filePath = "./Images/HinhMonAn/HinhMonAn" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".png";

                        var encoder = new PngBitmapEncoder();
                        encoder.Frames.Add(BitmapFrame.Create((BitmapSource)imgMonAn.Source));
                        using (FileStream stream = new FileStream(filePath, FileMode.Create))
                            encoder.Save(stream);
                        QLMonAnLoaiMon qlmalm = new QLMonAnLoaiMon();
                        qlmalm.CapNhatMonAn(maMonAn, txtTenMonAn.Text, cbxLoaiMon.Text, Convert.ToInt32(txtGiaTien.Text), filePath);

                        //File.Delete(filePath);
                        MessageBox.Show("Đã sửa thông tin loại món vừa chọn!", "Notify!", MessageBoxButton.OK, MessageBoxImage.Information);
                    }

                    LoadMonAn();
                    dgvMonAn.IsEnabled = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Lỗi!", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }