public int Insert(Entities.TheGiamGia pb1) { try { pb = new Constants.TheGiamGia(); Sql = new Constants.Sql(); string sql = Sql.InsertTheGiamGia; Connection conn = new Connection(); SqlConnection cn = conn.openConnection(); SqlCommand cmd = new SqlCommand(sql, cn); cmd.Parameters.Add(pb.HanhDong, SqlDbType.NVarChar, 50).Value = pb1.HanhDong; cmd.Parameters.Add(pb.MaTheGiamGia, SqlDbType.VarChar, 50).Value = pb1.MaTheGiamGia; cmd.Parameters.Add(pb.MaKhachHang, SqlDbType.VarChar, 50).Value = pb1.MaKhachHang; cmd.Parameters.Add(pb.GiaTriThe, SqlDbType.Float).Value = pb1.GiaTriThe; cmd.Parameters.Add(pb.NgayBatDau, SqlDbType.DateTime).Value = pb1.NgayBatDau; cmd.Parameters.Add(pb.NgayKetThuc, SqlDbType.DateTime).Value = pb1.NgayKetThuc; cmd.Parameters.Add(pb.Deleted, SqlDbType.Bit).Value = pb1.Deleted; int i = cmd.ExecuteNonQuery(); cmd.Connection.Dispose(); cn.Close(); conn.closeConnection(); cn = null; conn = null; return(i); } catch (Exception ex) { string s = ex.Message; return(0); } }
public int Delete(Entities.TheGiamGia pb1) { try { pb = new Constants.TheGiamGia(); Sql = new Constants.Sql(); string sql = Sql.DeleteTheGiamGia; Connection conn = new Connection(); SqlConnection cn = conn.openConnection(); SqlCommand cmd = new SqlCommand(sql, cn); cmd.Parameters.Add(pb.MaTheGiamGia, SqlDbType.VarChar, 50).Value = pb1.MaTheGiamGia; int i = cmd.ExecuteNonQuery(); cmd.Connection.Dispose(); cn.Close(); conn.closeConnection(); cn = null; conn = null; return(i); } catch (Exception ex) { string s = ex.Message; return(0); } }
public Entities.TheGiamGia[] Select() { Entities.TheGiamGia[] arrC = null; try { pb = new Constants.TheGiamGia(); Sql = new Constants.Sql(); string sql = Sql.SelectTheGiamGia; conn = new Connection(); cn = conn.openConnection(); cmd = new SqlCommand(sql, cn); dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); arr = new ArrayList(); while (dr.Read()) { Entities.TheGiamGia TheGiamGia = new Entities.TheGiamGia(); TheGiamGia.MaTheGiamGia = dr[pb.MaTheGiamGia].ToString(); TheGiamGia.MaKhachHang = dr[pb.MaKhachHang].ToString(); TheGiamGia.GiaTriThe = dr[pb.GiaTriThe].ToString(); TheGiamGia.GiaTriConLai = dr[pb.GiaTriConLai].ToString(); TheGiamGia.NgayBatDau = DateTime.Parse(dr[pb.NgayBatDau].ToString()); TheGiamGia.NgayKetThuc = DateTime.Parse(dr[pb.NgayKetThuc].ToString()); TheGiamGia.Deleted = (Boolean)dr[pb.Deleted]; arr.Add(TheGiamGia); } int n = arr.Count; if (n == 0) { arrC = new Entities.TheGiamGia[0]; } arrC = new Entities.TheGiamGia[n]; for (int i = 0; i < n; i++) { arrC[i] = (Entities.TheGiamGia)arr[i]; } } catch (Exception ex) { string s = ex.Message.ToString(); } finally { cmd.Connection.Dispose(); cn.Close(); conn.closeConnection(); } return(arrC); }
/// <summary> /// nút thêm /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsslthem_Click(object sender, EventArgs e) { this.Enabled = false; try { if (KiemTra() == true) { //CheckConflictInsert(); txtSochungtu.Text = ProID("HDBanHang"); kt = true; if (kt == true) { cl = new Server_Client.Client(); this.Client1 = cl.Connect(Luu.IP, Luu.Ports); string date = ""; try { date = new Common.Utilities().MyDateConversion(mskngaychungtu.Text); } catch { MessageBox.Show("Bạn nhập sai định dạng ngày tháng", "Hệ thống cảnh báo"); mskngaychungtu.Focus(); return; } string khachtra = "0"; if (txtkhachtra.Text == "") khachtra = "0"; else khachtra = txtkhachtra.Text; if (Convert.ToDouble(khachtra) < (Convert.ToDouble(txtTongtien.Text) - Convert.ToDouble(txtGTTheVip.Text) - double.Parse(txtGTTheGT.Text))) { lbloi.Text = "Khách trả không thể nhỏ hơn Tổng tiền"; return; } Entities.HDBanHang pt = new Entities.HDBanHang(); string makho = LayMaKho(cbbkhohang.Text); double ttn = 0; Entities.TheVip tv1 = null; Entities.TheGiamGia tgg1 = null; // The Vip if (Convert.ToDouble(txtTongtien.Text) < Convert.ToDouble(txtGTTheVip.Text)) { ttn = Convert.ToDouble(txtGTTheVip.Text) - Convert.ToDouble(txtTongtien.Text); tv1 = new Entities.TheVip("", txtMaTheVip.Text, "", ttn.ToString(), "", "", false); } else { ttn = Convert.ToDouble(txtTongtien.Text) - Convert.ToDouble(txtGTTheVip.Text); tv1 = new Entities.TheVip("", txtMaTheVip.Text, "", "0", "", "", false); // The Gia Tri. if (Convert.ToDouble(txtTongtien.Text) - Convert.ToDouble(txtGTTheVip.Text) < Convert.ToDouble(txtGTTheGT.Text)) { ttn = Convert.ToDouble(txtGTTheGT.Text) - (Convert.ToDouble(txtTongtien.Text) - Convert.ToDouble(txtGTTheVip.Text)); tgg1 = new Entities.TheGiamGia(); tgg1.MaTheGiamGia = txtMaTheGT.Text; tgg1.GiaTriConLai = ttn.ToString(); } else { ttn = Convert.ToDouble(txtTongtien.Text) - Convert.ToDouble(txtGTTheVip.Text) - Convert.ToDouble(txtGTTheVip.Text); tgg1 = new TheGiamGia { MaTheGiamGia = txtMaTheGT.Text, GiaTriConLai = "0" }; } } chietkhau = (double.Parse(txtGiamgia.Text) + double.Parse(txtChietkhau.Text)).ToString(); string ckTongHoaDon = txtPhantramchietkhau.Text; if (string.IsNullOrEmpty(txtPhantramchietkhau.Text)) ckTongHoaDon = "0"; pt = new HDBanHang("Insert", 0, txtSochungtu.Text, Convert.ToDateTime(date), txtMakhachhang.Text, "0", " ", cbxHinhthucthanhtoan.Text, makho, _datesv, " ", (_currentNhanVien != null) ? _currentNhanVien.MaNhanVien : Common.Utilities.User.NhanVienID, "TT_0001", txtGiamgia.Text, ttn.ToString(), "0", txtGTGT.Text, txtTongtien.Text, true, txtMaTheVip.Text, txtGTTheVip.Text, txtDiengiai.Text, false, Common.Utilities.User.TenDangNhap, txtkhachtra.Text, ckTongHoaDon, txtMaTheGT.Text, txtGTTheGT.Text) { ChiTietHDBanHang = CheckDataGridInsert(dtgvsanpham), ChiTietKhoHangTheoHoaHonNhap = CheckDataGridTruSL(dtgvsanpham), TheVip = tv1, TheGiamGia = tgg1 }; Clientstrem = cl.SerializeObj(this.Client1, "HDBanHang", pt); bool kt1 = false; kt1 = (bool)cl.DeserializeHepper(Clientstrem, kt1); if (kt1 == true) { //Cập nhật điểm thưởng cho khách hàng if (!string.IsNullOrEmpty(txtMakhachhang.Text)) { //Cập nhật điểm thưởng khách hàng thành công bool kq = CapNhatDiemThuongKhachHang(txtMakhachhang.Text, txtTongtien.Text); } else { //Cập nhật điểm thưởng khách hàng thất bại } ///////////////////////////////////// khachtra = "0"; if (txtkhachtra.Text == "") khachtra = "0"; else khachtra = txtkhachtra.Text; if (cbkiemtra.Checked == true) { frmBaoCaorpt bcrpt = new frmBaoCaorpt("HDBanLe", txtSochungtu.Text, double.Parse(txtGiamgia.Text), khachtra, txtdutra.Text, txtKhachPhaiTra.Text, txtGTGT.Text, lbnhanvien.Text, "in", mskngaychungtu.Text, txtGTTheVip.Text, txtGTTheGT.Text, "", txtChietkhau.Text, "", "", ""); } GiaVonBanHang(pt.ChiTietHDBanHang); this.Close(); } else { MessageBox.Show("Thêm thất bại - xin thử lại", "Hệ thống cảnh báo"); } } } } catch { } finally { this.Enabled = true; } }
public void TheGiamGia() { cl = new Server_Client.Client(); // gán TCPclient this.Client1 = cl.Connect(Luu.IP, Luu.Ports); // khởi tạo biến truyền vào với hàm khởi tạo Entities.TheGiamGia pt = new Entities.TheGiamGia(); pt.HanhDong = "Select"; Clientstrem = cl.SerializeObj(this.Client1, "TheGiamGia", pt); // đổ mảng đối tượng vào datagripview thegiagiam = (Entities.TheGiamGia[])cl.DeserializeHepper1(Clientstrem, thegiagiam); if (thegiagiam == null) thegiagiam = new Entities.TheGiamGia[0]; }
public Entities.TheGiamGia[] Select() { Entities.TheGiamGia[] arrC = null; try { pb = new Constants.TheGiamGia(); Sql = new Constants.Sql(); string sql = Sql.SelectTheGiamGia; conn = new Connection(); cn = conn.openConnection(); cmd = new SqlCommand(sql, cn); dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); arr = new ArrayList(); while (dr.Read()) { Entities.TheGiamGia TheGiamGia = new Entities.TheGiamGia(); TheGiamGia.MaTheGiamGia = dr[pb.MaTheGiamGia].ToString(); TheGiamGia.MaKhachHang = dr[pb.MaKhachHang].ToString(); TheGiamGia.GiaTriThe = dr[pb.GiaTriThe].ToString(); TheGiamGia.GiaTriConLai = dr[pb.GiaTriConLai].ToString(); TheGiamGia.NgayBatDau = DateTime.Parse(dr[pb.NgayBatDau].ToString()); TheGiamGia.NgayKetThuc = DateTime.Parse(dr[pb.NgayKetThuc].ToString()); TheGiamGia.Deleted = (Boolean)dr[pb.Deleted]; arr.Add(TheGiamGia); } int n = arr.Count; if (n == 0) { arrC = new Entities.TheGiamGia[0]; } arrC = new Entities.TheGiamGia[n]; for (int i = 0; i < n; i++) { arrC[i] = (Entities.TheGiamGia)arr[i]; } } catch (Exception ex) { string s = ex.Message.ToString(); } finally { cmd.Connection.Dispose(); cn.Close(); conn.closeConnection(); } return arrC; }
/// <summary> /// GetTheGT /// </summary> /// <param name="barCode"></param> /// <param name="congTy"></param> /// <returns></returns> public MaVachThe[] GetTheGt(Barcode[] barCode, ThongTinCongTy congTy) { List<MaVachThe> retVal = null; try { retVal = new List<MaVachThe>(); cl = new Server_Client.Client(); // gán TCPclient client = cl.Connect(Luu.IP, Luu.Ports); // khởi tạo biến truyền vào với hàm khởi tạo TheGiamGia pt = new TheGiamGia { HanhDong = "Select" }; clientstrem = cl.SerializeObj(client, "TheGiamGia", pt); TheGiamGia[] tggArr = new TheGiamGia[1]; // đổ mảng đối tượng vào datagripview tggArr = (TheGiamGia[])cl.DeserializeHepper1(clientstrem, tggArr); // foreach (Barcode code in barCode) { foreach (TheGiamGia item in tggArr) { if (code.MaHangHoa.Trim().ToUpper().Equals(item.MaTheGiamGia.Trim().ToUpper())) { MaVachThe mavach = new MaVachThe { TenCongTy = congTy.TenCongTy + "\r\n" + congTy.DiaChi, TenThe = "Thẻ Giá Trị", MaKH = item.MaKhachHang, TenKH = code.TenHangHoa, NgayBatDau = item.NgayBatDau.ToShortDateString(), NgayKetThuc = item.NgayKetThuc.ToShortDateString(), MaVach = code.MaVach, MaThe = item.MaTheGiamGia, GiaTriThe = double.Parse(item.GiaTriThe) }; retVal.Add(mavach); break; } } } } catch (Exception) { retVal = null; } return retVal.ToArray(); }