Esempio n. 1
0
        private void bunifuFlatButton2_Click(object sender, EventArgs e)
        {
            try
            {
                if (dem == 1)
                {
                    string  tenCh   = tbTenChuong.text;
                    decimal tongCho = 0;

                    string manv = tbMaNv.text;
                    try
                    {
                        tongCho = decimal.Parse(tbTongCho.text);
                    }
                    catch
                    {
                        Alert a = new Alert("Tổng số chỗ hoặc số chỗ trống nhập không hợp lệ!", AlertType.error);
                        a.ShowDialog();
                        return;
                    }
                    if (tbTenChuong.text == "" || tbTongCho.text == "" || tbMaNv.text == "")
                    {
                        Alert a = new Alert("Vui lòng nhập đủ thông tin!", AlertType.info);
                        a.ShowDialog();
                    }
                    else if (kiemTra(tenCh) == true)
                    {
                        Alert a = new Alert("Tên chuồng đã tồn tại!", AlertType.error);
                        a.ShowDialog();
                    }

                    else
                    {
                        try
                        {
                            tongCho = decimal.Parse(tbTongCho.text);
                        }
                        catch
                        {
                            Alert a = new Alert("Tổng số chỗ hoặc số chỗ trống nhập không hợp lệ!", AlertType.error);
                            a.ShowDialog();
                        }
                        try
                        {
                            string    querry = "insert into ChuongTrai(tenChuong,tongsocho,sochocontrong,manv) values (N'" + tenCh + "',N'" + tongCho + "','" + tongCho + "','" + manv + "')";
                            DataTable data   = KetNoi.Istance.ExcuteQuerry(querry);
                            Alert     a      = new Alert("Thêm thành công", AlertType.success);
                            a.ShowDialog();
                            setNull();
                            LoadData();
                            dem                   = 0;
                            btnThem.Enabled       = true;
                            btnSua.Enabled        = true;
                            btnXoa.Enabled        = true;
                            dgvChuongTrai.Enabled = true;
                        }
                        catch
                        {
                            Alert a = new Alert("Thêm thất bại!", AlertType.info);
                            a.ShowDialog();
                        }
                    }
                }
                else if (dem == 2)
                {
                    string tenCh   = tbTenChuong.text;
                    string tongCho = tbTongCho.text;

                    string manv = tbMaNv.text;

                    if (tbTenChuong.text == "")
                    {
                        Alert a = new Alert("Vui lòng chọn đối tượng muốn sửa!", AlertType.error);
                        a.ShowDialog();
                    }
                    else if (tbTenChuong.text == "" || tbTongCho.text == "" || tbMaNv.text == "")
                    {
                        Alert a = new Alert("Vui lòng nhập đủ thông tin!", AlertType.error);
                        a.ShowDialog();
                    }
                    else if (tbTenChuong.text != tenChuongTrai && kiemTra(tbTenChuong.text) == true)
                    {
                        Alert a = new Alert("Tên chuồng đã tồn tại!", AlertType.error);
                        a.ShowDialog();
                    }

                    else if (int.Parse(tongCho) < DemBo(txmachuong.Text))
                    {
                        Alert a = new Alert("Số bò trong chuồng phải ít hơn hoặc bằng \n tổng số chỗ!", AlertType.error);
                        a.ShowDialog();
                    }
                    else
                    {
                        try
                        {
                            string    querry = "update ChuongTrai set tenChuong = N'" + tenCh + "',tongsocho=N'" + tongCho + "',manv = '" + manv + "' where maChuong = N'" + txmachuong.Text + "'";
                            DataTable data   = KetNoi.Istance.ExcuteQuerry(querry);
                            Alert     a      = new Alert("Sửa Thành Công!", AlertType.success);
                            a.ShowDialog();
                            setNull();
                            LoadData();
                            dem                   = 0;
                            btnThem.Enabled       = true;
                            btnSua.Enabled        = true;
                            btnXoa.Enabled        = true;
                            dgvChuongTrai.Enabled = true;
                        }
                        catch
                        {
                            Alert a = new Alert("Sửa Thất Bại!", AlertType.info);
                            a.ShowDialog();
                        }
                    }
                }
            }
            catch
            {
                Alert a = new Alert("Dữ liệu không hợp lệ hoặc lỗi kết nối.", AlertType.error);
                a.ShowDialog();
            }
        }
Esempio n. 2
0
 private void bunifuFlatButton2_Click(object sender, EventArgs e)
 {
     try
     {
         if (dem == 1)
         {
             string mathucan  = tbMaThucAn.text;
             string tenthucan = tbTenThucAn.text;
             if (tbMaThucAn.text == "" || tbTenThucAn.text == "")
             {
                 Alert a = new Alert("Vui lòng nhập đủ thông tin!", AlertType.info);
                 a.ShowDialog();
             }
             else if (kiemTra(mathucan) == true)
             {
                 Alert a = new Alert("Mã thức ăn đã tồn tại!", AlertType.error);
                 a.ShowDialog();
             }
             else
             {
                 try
                 {
                     string    querry = "insert into ThucAn values ('" + mathucan + "',N'" + tenthucan + "')";
                     DataTable data   = KetNoi.Istance.ExcuteQuerry(querry);
                     Alert     a      = new Alert("Thêm thành công", AlertType.success);
                     a.ShowDialog();
                     setNull();
                     LoadData();
                     dem             = 0;
                     btnXoa.Enabled  = true;
                     btnThem.Enabled = true;
                     btnSua.Enabled  = true;
                 }
                 catch
                 {
                     Alert a = new Alert("Thêm thất bại!", AlertType.info);
                     a.ShowDialog();
                 }
             }
         }
         else if (dem == 2)
         {
             string mathucan  = tbMaThucAn.text;
             string tenthucan = tbTenThucAn.text;
             if (tbTenThucAn.text == "")
             {
                 Alert a = new Alert("Vui lòng chọn đối tượng muốn sửa!", AlertType.error);
                 a.ShowDialog();
             }
             else if (tbMaThucAn.text == "" || tbTenThucAn.text == "")
             {
                 Alert a = new Alert("Vui lòng nhập đủ thông tin!", AlertType.error);
                 a.ShowDialog();
             }
             else
             {
                 try
                 {
                     string    querry = "update ThucAn set tenthucan = N'" + tenthucan + "' where mathucan = '" + mathucan + "' ";
                     DataTable data   = KetNoi.Istance.ExcuteQuerry(querry);
                     Alert     a      = new Alert("Sửa Thành Công!", AlertType.info);
                     a.ShowDialog();
                     setNull();
                     LoadData();
                     dem             = 0;
                     btnXoa.Enabled  = true;
                     btnThem.Enabled = true;
                     btnSua.Enabled  = true;
                 }
                 catch
                 {
                     Alert a = new Alert("Sửa Thất Bại!", AlertType.info);
                     a.ShowDialog();
                 }
             }
         }
     }
     catch
     {
         Alert a = new Alert("Dữ liệu không hợp lệ hoặc lỗi kết nối.", AlertType.error);
         a.ShowDialog();
     }
 }
Esempio n. 3
0
        private void bunifuThinButton22_Click(object sender, EventArgs e)
        {
            bool fileError = true;

            try
            {
                if (bien == 0)
                {
                    Alert a = new Alert("Hiện tại chưa có dữ liệu để xuất", AlertType.error);
                    a.ShowDialog();
                }
                else
                {
                    SaveFileDialog saveFileDialog = new SaveFileDialog();
                    saveFileDialog.Filter   = "PDF(*.pdf)|*.pdf";
                    saveFileDialog.FileName = "VonMuaBo.pdf";
                    if (saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        fileError = false;
                        if (File.Exists(saveFileDialog.FileName))
                        {
                            try
                            {
                                File.Delete(saveFileDialog.FileName);
                            }
                            catch
                            {
                                fileError = true;
                            }
                        }
                    }
                    if (!fileError)
                    {
                        string deviceInfo =
                            "<DeviceInfo>" +
                            "  <OutputFormat>EMF</OutputFormat>" +
                            "  <PageWidth>9in</PageWidth>" +
                            "  <PageHeight>6in</PageHeight>" +
                            "  <MarginTop>0.25in</MarginTop>" +
                            "  <MarginLeft>0.25in</MarginLeft>" +
                            "  <MarginRight>0.25in</MarginRight>" +
                            "  <MarginBottom>0.25in</MarginBottom>" +
                            "</DeviceInfo>";
                        byte[] bytes = reportViewer1.LocalReport.Render(
                            "PDF", deviceInfo);
                        FileStream fs = new FileStream(saveFileDialog.FileName, FileMode.Create);

                        fs.Write(bytes, 0, bytes.Length);

                        fs.Close();
                        path = Convert.ToString(Path.GetFullPath(saveFileDialog.FileName));
                        Alert a = new Alert("Xuất thành công", AlertType.success);
                        a.ShowDialog();
                    }
                }
            }
            catch
            {
                Alert a = new Alert("Dữ liệu không hợp lệ hoặc lỗi kết nối.", AlertType.error);
                a.ShowDialog();
            }
        }
Esempio n. 4
0
        private void bunifuFlatButton2_Click(object sender, EventArgs e)
        {
            try
            {
                if (dem == 1)
                {
                    string  mathuoc    = tbMaThuoc.text;
                    string  tenthuoc   = tbTenThuoc.text;
                    string  dvt        = cbDVT.Text;
                    decimal soluongcon = 0;
                    if (tbTenThuoc.text == "" || cbDVT.Text == "" || tbSoLuongCon.text == "")
                    {
                        Alert a = new Alert("Vui lòng nhập đủ thông tin!", AlertType.info);
                        a.ShowDialog();
                    }
                    else if (kiemTra(tenthuoc) == true)
                    {
                        Alert a = new Alert("Tên thuốc đã tồn tại!", AlertType.error);
                        a.ShowDialog();
                    }
                    else
                    {
                        try
                        {
                            soluongcon = decimal.Parse(tbSoLuongCon.text);
                        }
                        catch
                        {
                            Alert a = new Alert("Số lượng nhập không hợp lệ!", AlertType.error);
                            a.ShowDialog();
                        }

                        try
                        {
                            string    querry = "insert into ThuocVacXin(tenthuoc,donvitinh,slcon) values (N'" + tenthuoc + "',N'" + dvt + "','" + soluongcon + "')";
                            DataTable data   = KetNoi.Istance.ExcuteQuerry(querry);
                            Alert     a      = new Alert("Thêm thành công", AlertType.success);
                            a.ShowDialog();
                            setNull();
                            dem             = 0;
                            btnXoa.Enabled  = true;
                            btnThem.Enabled = true;
                            btnSua.Enabled  = true;
                            LoadData();
                            LoadCBBox();
                        }
                        catch
                        {
                            Alert a = new Alert("Thêm thất bại!", AlertType.info);
                            a.ShowDialog();
                        }
                    }
                }
                else if (dem == 2)
                {
                    string  mathuoc    = tbMaThuoc.text;
                    string  tenthuoc   = tbTenThuoc.text;
                    string  dvt        = cbDVT.Text;
                    decimal soluongcon = 0;
                    if (tbTenThuoc.text == "")
                    {
                        Alert a = new Alert("Vui lòng chọn đối tượng muốn sửa!", AlertType.error);
                        a.ShowDialog();
                    }
                    else if (tbTenThuoc.text == "" || cbDVT.Text == "" || tbSoLuongCon.text == "")
                    {
                        Alert a = new Alert("Vui lòng nhập đủ thông tin!", AlertType.error);
                        a.ShowDialog();
                    }
                    else if (kiemTra(tenthuoc) == true)
                    {
                        Alert a = new Alert("Tên thuốc đã tồn tại!", AlertType.error);
                        a.ShowDialog();
                    }
                    else
                    {
                        try
                        {
                            soluongcon = decimal.Parse(tbSoLuongCon.text);
                        }
                        catch
                        {
                            Alert a = new Alert("Số lượng nhập không hợp lệ!", AlertType.error);
                            a.ShowDialog();
                        }
                        try
                        {
                            string    querry = "update ThuocVacxin set tenthuoc = N'" + tenthuoc + "',donvitinh = N'" + dvt + "',slcon = '" + soluongcon + "' where mathuoc = '" + mathuoc + "'";
                            DataTable data   = KetNoi.Istance.ExcuteQuerry(querry);
                            Alert     a      = new Alert("Sửa Thành Công!", AlertType.info);
                            a.ShowDialog();
                            setNull();
                            LoadData();
                            LoadCBBox();
                            dem               = 0;
                            btnXoa.Enabled    = true;
                            btnThem.Enabled   = true;
                            btnSua.Enabled    = true;
                            tbMaThuoc.Enabled = true;
                        }
                        catch
                        {
                            Alert a = new Alert("Sửa Thất Bại!", AlertType.info);
                            a.ShowDialog();
                        }
                    }
                }
            }
            catch
            {
                Alert a = new Alert("Dữ liệu không hợp lệ hoặc lỗi kết nối.", AlertType.error);
                a.ShowDialog();
            }
        }