public static string GetReceiptCode() { FinReceiptDT receiptDT = new FinReceiptDT(); string mmyy = getMMyy(); DataTable invoiceTable = receiptDT.GetByCond("Code like 'PT" + mmyy + "%'", " Code DESC"); string prefix = "PT" + mmyy; string suffix = "0001"; if (invoiceTable != null && invoiceTable.Rows.Count > 0) { suffix = getSuffix(invoiceTable.Rows[0]["Code"].ToString()); } return(prefix + suffix); }
public HttpResponseMessage Delete(string id) { SqlTransaction tran = DataProvider.beginTrans(); try { string message = id; FinReceiptDT receiptDT = new FinReceiptDT(); DataTable dtReceipt = receiptDT.GetByCond("InvoiceId=" + id); if (dtReceipt.Rows.Count > 0) { message = "Lỗi: Phiếu bán hàng đã thu tiền, không thể xóa."; } else { DataTable dtInvoice = invoiceDT.GetByID(id); DataTable invoiceDetail = invoiceDetailDT.GetByCond("InvoiceId=" + id); foreach (DataRow row in invoiceDetail.Rows) { string invCode = dtInvoice.Rows[0]["Code"].ToString(); int storeId = Converter.ToInt32(dtInvoice.Rows[0]["StoreId"]); int productId = Converter.ToInt32(row["ProductId"]); string quantity = row["ProductId"].ToString(); StoreModel.ChangeInvoice(invCode, storeId, productId, quantity, tran); invoiceDetailDT.DeleteViaCond("InvoiceId=" + id, tran); invoiceDT.Delete(id, tran); tran.Commit(); } } return(Request.CreateResponse <string>(HttpStatusCode.OK, message)); } catch (Exception e) { ExceptionHandler.Log(e); tran.Rollback(); return(Request.CreateResponse <string>(HttpStatusCode.OK, "")); } finally { tran.Dispose(); } }