Exemple #1
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            float wei;
            long  fd;

            try
            {
                wei = float.Parse(txbnewWeight.Text);
                fd  = long.Parse(txbnewPricefood.Text);
            }
            catch { MessageBox.Show("Cân nặng hoặc tiền thức ăn không đúng !"); return; }
            string type = ((ComboBoxItem)(cbbnewtype.SelectedItem)).Content.ToString();

            if (txbIDBill.Text.Length <= 0 || txbIDBill.Text.Length > 10)
            {
                MessageBox.Show("Mã hóa đơn không đúng !");
                return;
            }
            if (txbIDBill.Text == "" || txbIDBill.Text == " ")
            {
                MessageBox.Show("Mã hóa đơn không được rỗng !");
                return;
            }
            BILL_IN bill = BillinBUS.GetById(txbIDBill.Text);

            if (bill != null)
            {
                MessageBox.Show("Mã hóa đơn đã tồn tại !");
                return;
            }
            if (type == "Loại 1")
            {
                type = "DTYPE_1";
            }
            else if (type == "Loại 2")
            {
                type = "DTYPE_2";
            }
            else if (type == "Loại 3")
            {
                type = "DTYPE_3";
            }

            string doghouse = ((ComboBoxItem)(cbbnewMaChuong.SelectedItem)).Content.ToString();

            if (doghouse == "Chuồng 1")
            {
                doghouse = "DH01";
            }
            else if (doghouse == "Chuồng 2")
            {
                doghouse = "DH02";
            }
            else if (doghouse == "Chuồng 3")
            {
                doghouse = "DH03";
            }

            byte[] dogimage = UIProcess.Inst.ImageToByteArray(ImageDog);
            DOG    newDog   = new DOG()
            {
                TYPE = type, WEIGHT = wei, FOODPRICE = fd, DAYIN = DateTime.Now, STATUS = 0, IDDOGHOUSE = doghouse, IMAGES = dogimage
            };
            DOG DogAferInset;

            try
            {
                DogAferInset = DogBUS.Insert(newDog);
            }
            catch { MessageBox.Show("Thất bại, kiểm tra kết nối !"); return; };
            DOG_INFOR doginfo = new DOG_INFOR()
            {
                STREET   = txbBill_Streets.Text,
                WARD     = txbBill_Ward.Text,
                DISTRICT = txbBill_District.Text,
                TIME     = TimeSpan.Parse(DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss")),
                IDDOG    = DogAferInset.ID
            };

            try
            {
                DogInforBUS.Insert(doginfo);
            }
            catch
            {
                DOG dogdelete = DogBUS.getByID(DogAferInset.ID.ToString());
                DogBUS.Delete(dogdelete);
                MessageBox.Show("Thêm thất bại, kiểm tra kết nối !");
                return;
            }

            BILL_IN billin = new BILL_IN()
            {
                IDDOG    = DogAferInset.ID,
                DAY_BILL = DateTime.Now,
                FINE     = long.Parse(txbnewPricefood.Text),
                ID_BILL  = txbIDBill.Text,
                ID_USER  = _acc.ID_USER,
            };

            BillinBUS.Insert(billin);
            LoadListDogs();

            MessageBox.Show("Thêm chó thành công !");
            ResetBillIn();
        }
 public static void Update(DOG_INFOR obj)
 {
     reps.Update(obj);
 }
 public static void Delete(DOG_INFOR obj)
 {
     reps.Delete(obj);
 }
 public static DOG_INFOR Insert(DOG_INFOR obj)
 {
     return(reps.Insert(obj));
 }