Example #1
0
        private void btThem_Click(object sender, EventArgs e)
        {
            if (timSach_Ma(btEditMa.Text.Trim()) == true && timSach_Ten(btEditTen.Text.Trim()) == true) // nếu sách đã có
            {
                if (txtSLN.Text != "")
                {
                    if (int.Parse(txtSLN.Text) < nhaptt || int.Parse(txtSLT.Text) < tontruocnhap)
                    {
                        MessageBox.Show("Vi phạm điều kiện trong lưu ý!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    //long newSLT = long.Parse(txtSLT.Text) + long.Parse(txtSLN.Text);
                    SACH sa = new SACH(btEditMa.Text.Trim());
                    sa.Sua_PNS(long.Parse(txtSLN.Text.Trim()));

                    CTPHIEUNHAP ctpn = new CTPHIEUNHAP(DateTime.Now.ToString("ddMMhhmmss"), txtMaPhieu.Text.Trim(), btEditMa.Text.Trim(), int.Parse(txtSLN.Text.Trim()));
                    ctpn.Them();
                    load_DSPN();
                }
                else
                {
                    MessageBox.Show("Số lượng nhập của sách chưa có !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else // nếu sách chưa có
            {
                if (txtSLN.Text != "")
                {
                    DialogResult dr = MessageBox.Show("Sách này hiện chưa có trong nhà sách, bạn có muốn thêm sách mới vào danh sách sách?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                    if (dr != DialogResult.Yes)
                    {
                        return;
                    }
                    if (txtGia.Text.Trim() == "")
                    {
                        txtGia.Text = "0";
                    }
                    SACH sa = new SACH(btEditMa.Text.Trim(), btEditTen.Text.Trim(), txtTL.Text.Trim(), txtTG.Text.Trim(), long.Parse(txtSLN.Text.Trim()), float.Parse(txtGia.Text.Trim()));
                    sa.Them();

                    CTPHIEUNHAP ctpn = new CTPHIEUNHAP(DateTime.Now.ToString("ddMMhhmmss"), txtMaPhieu.Text, btEditMa.Text, int.Parse(txtSLN.Text.Trim()));
                    ctpn.Them();
                    load_DSPN();
                }
                else
                {
                    MessageBox.Show("Số lượng nhập của sách chưa có !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
Example #2
0
        public void Update_SACH(string sql, SACH sa)
        {
            DBService db = new DBService();

            db.openconn();
            SqlCommand cmd = new SqlCommand(sql, db.conn);
            //đánh dấu điểm bắt đầu
            SqlTransaction tran = db.conn.BeginTransaction("ThemLopTransaction");

            cmd.Transaction = tran;
            try
            {
                SqlParameter pa1 = new SqlParameter("@ma", sa.Ma);
                cmd.Parameters.Add(pa1);
                SqlParameter pa2 = new SqlParameter("@ten", sa.Ten);
                cmd.Parameters.Add(pa2);
                SqlParameter pa3 = new SqlParameter("@tl", sa.Theloai);
                cmd.Parameters.Add(pa3);
                SqlParameter pa4 = new SqlParameter("@tg", sa.Tacgia);
                cmd.Parameters.Add(pa4);
                SqlParameter pa5 = new SqlParameter("@slt", sa.Slt);
                cmd.Parameters.Add(pa5);
                SqlParameter pa6 = new SqlParameter("@dg", sa.Gia);
                cmd.Parameters.Add(pa6);


                cmd.ExecuteNonQuery();
                tran.Commit();//kết thúc transaction
            }
            catch (Exception ex)
            {
                tran.Rollback();//quay lui tới thời điểm beginTran
                throw ex;
            }
            db.closeconn();
        }