private void btnThayDoi_Click(object sender, EventArgs e) { DataTable dt = ThamSo_BUS.GetThamSoAll();//Lấy tất cả tham số trong bảng THAMSO int maThamSo; if (dt.Rows.Count == 0)//Kiểm tra xem trong bảng THAMSO đã có dữ liệu hay chưa { MessageBox.Show("Bạn phải khôi phục về mặc định trước khi thay đổi"); btnMacDinh_Click(sender, e); return; } else { maThamSo = int.Parse(dt.Rows[0].ItemArray[0].ToString());//Gán bằng giá trị đầu tiên của đối tượng dt chính là MaThamSo trong bảng THAMSO } ThamSo_DTO ts = new ThamSo_DTO(); ts.MaThamSo = maThamSo; if (chkApDungQD4.Checked == true) { ts.ApDungQuyDinh4 = 1; } else { ts.ApDungQuyDinh4 = 0; } try { ts.SoLuongNhapToiThieu = UInt32.Parse(txtSoLuongNhapToiThieu.Text); ts.SoLuongTonToiDa = UInt32.Parse(txtSoLuongTonToiDa.Text); ts.SoTienNoToiDa = UInt64.Parse(txtSoTienNoToiDa.Text); ts.SoLuongTonToiThieu = UInt32.Parse(txtSoLuongTonToiThieu.Text); ts.TiLeTinhDonGiaBan = UInt32.Parse(txtTiLeTinhDonGiaBan.Text); } catch (FormatException) { MessageBox.Show("Bạn phải nhập vào tất cả các tham số"); return; } catch (OverflowException) { MessageBox.Show("Số không được âm"); return; } //Kiểm tra xem việc thay đổi có thành công hay không string ketQua = ThamSo_BUS.CapNhat(ts); if (ketQua == "Success") { MessageBox.Show("Thay đổi thành công"); } else { MessageBox.Show(ketQua, "Lỗi"); } HienThiGiaTriHienTai(); }
//Cập nhật lại bảng THAMSO public static string Update(ThamSo_DTO ts) { if (ThamSo_DAO.LayThamSoBangMa(ts.MaThamSo) == null) //Kiểm tra xem ts.MaThamSo đã có trong bảng THAMSO hay không { return(ThamSo_DAO.Them(ts)); //Không có trong bảng THAMSO thì thêm mới } else { return(ThamSo_DAO.CapNhat(ts));//Có thì cập nhật lại bảng THAMSO } }
//Lấy ra MaThamSo bằng ma không có thì trả về null public static ThamSo_DTO LayThamSoBangMa(int ma) { string sql = "select * from THAMSO where MaThamSo=" + ma + ""; DataTable dt = DataAccess.ThucThiQuery(sql); if (dt.Rows.Count == 0) { return(null); } else { ThamSo_DTO ts = new ThamSo_DTO(); ts.MaThamSo = (int)dt.Rows[0].ItemArray[0]; return(ts); } }
private void btnMacDinh_Click(object sender, EventArgs e) { txtSoLuongNhapToiThieu.Text = "150"; txtSoLuongTonToiThieu.Text = "20"; txtSoLuongTonToiDa.Text = "300"; txtSoTienNoToiDa.Text = "20000"; txtTiLeTinhDonGiaBan.Text = "105"; chkApDungQD4.Checked = true; int maThamSo; DataTable dt = ThamSo_BUS.GetThamSoAll();//Lấy tất cả tham số trong bảng THAMSO //Kiểm tra xem trong dt trả về có dữ liệu hay không if (dt.Rows.Count == 0) { maThamSo = 0; } else { maThamSo = int.Parse(dt.Rows[0].ItemArray[0].ToString());//Gán bằng giá trị đầu tiên của đối tượng dt chính là MaThamSo trong bảng THAMSO } ThamSo_DTO ts = new ThamSo_DTO(); ts.MaThamSo = maThamSo; ts.SoLuongNhapToiThieu = UInt32.Parse(txtSoLuongNhapToiThieu.Text); ts.SoLuongTonToiDa = UInt32.Parse(txtSoLuongTonToiDa.Text); ts.SoTienNoToiDa = UInt64.Parse(txtSoTienNoToiDa.Text); ts.SoLuongTonToiThieu = UInt32.Parse(txtSoLuongTonToiThieu.Text); ts.TiLeTinhDonGiaBan = UInt32.Parse(txtTiLeTinhDonGiaBan.Text); ts.ApDungQuyDinh4 = 1; //Kiểm tra thử khôi phục mặc định có thành công không string ketQua = ThamSo_BUS.Update(ts); if (ketQua == "Success") { MessageBox.Show("Đã khôi phục về mặc định!"); } else { MessageBox.Show(ketQua); } HienThiGiaTriHienTai(); }
//Cập nhật bảng THAMSO public static string CapNhat(ThamSo_DTO ts) { return(ThamSo_DAO.CapNhat(ts)); }
//Thêm mới 1 tham số public static string Them(ThamSo_DTO ts) { string sql = "insert into THAMSO(TiLeTinhDonGiaBan,SoLuongNhapToiThieu,SoLuongTonToiThieu,SoLuongTonToiDa,SoTienNoToiDa,ApDungQuyDinh4) values (" + ts.TiLeTinhDonGiaBan + "," + ts.SoLuongNhapToiThieu + "," + ts.SoLuongTonToiThieu + "," + ts.SoLuongTonToiDa + "," + ts.SoTienNoToiDa + "," + ts.ApDungQuyDinh4 + ")"; return(DataAccess.ThucThiNonQuery(sql)); }
//Cập nhật các cột trong bảng THAMSO public static string CapNhat(ThamSo_DTO ts) { string sql = "update THAMSO set TiLeTinhDonGiaBan=" + ts.TiLeTinhDonGiaBan + ",SoLuongNhapToiThieu=" + ts.SoLuongNhapToiThieu + ",SoLuongTonToiThieu=" + ts.SoLuongTonToiThieu + ",SoLuongTonToiDa=" + ts.SoLuongTonToiDa + ",SoTienNoToiDa=" + ts.SoTienNoToiDa + ",ApDungQuyDinh4=" + ts.ApDungQuyDinh4 + " where MaThamSo = " + ts.MaThamSo + ""; return(DataAccess.ThucThiNonQuery(sql)); }