public static DataTable GetDonDatHang(string HoTen, string DT, string DC, bool isdate, DateTime From, DateTime To) { try { DataTable dt = new DataTable(); SQLHelper sqlHelper = new SQLHelper(); string where = ""; if (HoTen != string.Empty) { where += " and ddh.HoTen like '%" + HoTen + "%' "; } if (DT != string.Empty) { where += " and ddh.DienThoai like '%" + DT + "%' "; } if (DC != string.Empty) { where += " and ddh.DiaChi like '%" + DC + "%'"; } if (isdate) { where += " and ddh.NgayTao between @tungay and @denngay"; sqlHelper.AddParameterToSQLCommand("@tungay", SqlDbType.DateTime); sqlHelper.AddParameterToSQLCommand("@denngay", SqlDbType.DateTime); sqlHelper.SetSQLCommandParameterValue("@tungay", new DateTime(From.Year, From.Month, From.Day, 0, 0, 0)); sqlHelper.SetSQLCommandParameterValue("@denngay", new DateTime(To.Year, To.Month, To.Day, 23, 59, 59)); } string sql = string.Format(@"SELECT ddh.ID, ddh.HoTen, ddh.DienThoai, ddh.DiaChi, ddh.SoLuong, ddh.ThanhTien, ddh.NgayTao, ddh.GhiChu FROM [" + Config._DBNameFrontEnd + @"].dbo.DonDatHang ddh where 1=1 {0}", where); dt = sqlHelper.GetDatasetByCommand(sql).Tables[0]; return(dt); } catch (Exception ex) { CTLError.WriteError("GetDonDatHang ", ex.Message); return(null); throw; } }
public static bool InsertDonDatHang(EntityDonDatHang dh, DataTable ctdh) { SQLHelper sqlHelper = new SQLHelper(); decimal soluong = 0; decimal thanhtien = 0; try { sqlHelper.BeginTransaction("InsertDDH"); string sql = string.Format(@" INSERT INTO [" + Config._DBNameFrontEnd + @"].dbo.DonDatHang ( ID, HoTen, DienThoai, DiaChi, SoLuong, ThanhTien, NgayTao, GhiChu ) VALUES ( '{0}'/* ID */, '{1}'/* HoTen */, '{2}'/* DienThoai */, '{3}'/* DiaChi */, {4}/* SoLuong */, {5}/* ThanhTien */, @ngaytao/* NgayTao */, '{6}'/* GhiChu */ )", dh.ID, dh.HoTen, dh.DT, dh.DiaChi, dh.SoLuong, dh.ThanTien, dh.GhiChu); sqlHelper.AddParameterToSQLCommand("@ngaytao", SqlDbType.DateTime); //sqlHelper.AddParameterToSQLCommand("@image", SqlDbType.Image); sqlHelper.SetSQLCommandParameterValue("@ngaytao", dh.NgayTao); //sqlHelper.SetSQLCommandParameterValue("@image", a.Image); bool kq = sqlHelper.GetExecuteNonQueryByCommand(sql) > 0; if (!kq) { InfoMessage.HienThi("Lưu đơn hàng không thành công!", "Lưu đơn đặt hàng", "Thong Bao", HinhAnhThongBao.LOI, NutThongBao.DONGY); return(false); } foreach (DataRow row in ctdh.Rows) { EntityCTDonDatHang ct = new EntityCTDonDatHang(); ct.ID = Guid.NewGuid().ToString(); ct.IDDonDatHang = dh.ID; ct.SKU = row["SKU"].ToString(); ct.UPC = row["UPC"].ToString(); ct.GhiChu = ("" + row["GhiChu"]).ToString(); ct.TenSP = row["Description"].ToString(); ct.SoLuong = Convert.ToDecimal(row["SoLuong"]); ct.GiaGoc = Convert.ToDecimal(row["GiaGoc"]); ct.GiaKM = Convert.ToDecimal("0" + row["GiaKM"]); ct.ThanTien = Convert.ToDecimal(row["ThanhTien"]); kq &= InsertCTDDH(ct); soluong += ct.SoLuong; thanhtien += ct.ThanTien; } //kq &= UpdateDonDatHang(dh.ID, soluong, thanhtien); if (!kq) { InfoMessage.HienThi("Lưu đơn hàng không thành công!", "Lưu đơn đặt hàng", "Thong Bao", HinhAnhThongBao.LOI, NutThongBao.DONGY); return(false); } sqlHelper.Commit(); InfoMessage.HienThi("Lưu đơn hàng thành công!!!", "Lưu đơn đặt hàng", "Thong Bao", HinhAnhThongBao.THANHCONG, NutThongBao.DONGY); return(true); } catch (Exception ex) { sqlHelper.Rollback("InsertDDH"); InfoMessage.HienThi("Lưu đơn hàng không thành công!", "Lưu đơn đặt hàng", "Thong Bao", HinhAnhThongBao.LOI, NutThongBao.DONGY); CTLError.WriteError("InsertDonDatHang ", ex.Message); return(false); throw; } }
private void BTHienthi_Click(object sender, EventArgs e) { WaitingMsg waitingMsg = new WaitingMsg("Chương trình đang load dữ liệu!", "Please Waiting ......."); try { _tbDSGia.Clear(); copyfile(Config._pathfileWinDSS); //TPSDataAccess access = new TPSDataAccess(Path.Combine(CTLConfig._pathfileWinDSS, "INVMST")); TPSDataAccess access = new TPSDataAccess(_PathFileINVMST); TPSDataAccess accessPathWSS = new TPSDataAccess(Path.Combine(Config._pathfileWinDSS, "SYSMST")); SQLHelper helper = new SQLHelper(true); string MaST = "0"; MaST = accessPathWSS.getMaSieuthi(); _storeName = MaST; helper.AddParameterToSQLCommand("@STR", SqlDbType.NVarChar, 8); helper.SetSQLCommandParameterValue("@STR", MaST); if (MaST == "0") { InfoMessage.HienThi("Khong lay duoc StoreNumber " + MaST + " ", "Vui long lien he voi quan tri", "Loi Get StoreNumber", HinhAnhThongBao.LOI, NutThongBao.DONGY); return; } string strconf = ""; string strsale = ""; string strupc = ""; if (!radConfirAll.Checked) { strconf = " and CONF_PRICE=" + (radconfirYes.Checked ? "'Y'" : "'N'"); helper.AddParameterToSQLCommand("@ISTYPE", SqlDbType.NVarChar, 8); helper.SetSQLCommandParameterValue("@ISTYPE", (radconfirNo.Checked) ? "01" : "CS"); } if (!radsaleAll.Checked) { strsale = " and SELL_UNIT=" + (radsaleEA.Checked ? "'EA'" : "'KG'"); helper.AddParameterToSQLCommand("@ISLUM", SqlDbType.NVarChar, 8); helper.SetSQLCommandParameterValue("@ISLUM", (radsaleKG.Checked) ? radsaleKG.Text : radsaleEA.Text); } if (!radUPCALL.Checked) { strupc = " and UPC<>''"; helper.AddParameterToSQLCommand("@ISUPC", SqlDbType.NVarChar, 8); helper.SetSQLCommandParameterValue("@ISUPC", 1); } DataTable dt = helper.GetDatatableBySP("PRLN_spGetPricebyStore"); string sql = string.Format("Select SKU,Price,Description from INVMST where 1=1 {0}{1}{2} order by SKU", strconf, strsale, strupc); DataTable tbg = access.GetDataTable(sql); int dem = 0; foreach (DataRow dataRow in dt.Rows) { decimal p = Convert.ToDecimal(dataRow["PLNITM"].ToString()); for (int i = dem; i < tbg.Rows.Count; i++) { decimal pMMS = Convert.ToDecimal(tbg.Rows[i]["SKU"].ToString()); if (p == pMMS) { if (Convert.ToDecimal(tbg.Rows[i]["Price"]) != Convert.ToDecimal(dataRow["PLNAMT"].ToString())) { DataRow r = _tbDSGia.NewRow(); r["SKU"] = "00" + dataRow["PLNITM"].ToString(); r["Check"] = false; r["Description"] = tbg.Rows[i]["Description"].ToString(); r["Price"] = Convert.ToDecimal(dataRow["PLNAMT"].ToString()); r["PriceMMS"] = Convert.ToDecimal(tbg.Rows[i]["Price"]); _tbDSGia.Rows.Add(r); } dem = i + 1; break; } else if (pMMS > p) { dem = i; break; } } } GrDSPriceSKU.DataSource = _tbDSGia; waitingMsg.Finish(); } catch (Exception exception) { CTLError.WriteError("btLoadData ", exception.Message); waitingMsg.Finish(); return; throw; } }