private double _total; // Luu tong gia tri hoa don khi item databound #endregion #region --- PAGE EVENT --- protected void Page_Load(object sender, EventArgs e) { Page.Title = @"Quản lý phiếu xuất"; if (!string.IsNullOrEmpty(Request.QueryString["ExportId"]) && Request.QueryString["ExportId"] != "0") { _currentExport = Module.GetById <IvExport>(Convert.ToInt32(Request.QueryString["ExportId"])); } else { _currentExport = new IvExport(); } if (!string.IsNullOrEmpty(Request.QueryString["bookingRoomId"])) { _bookingRoom = Module.GetById <BookingRoom>(Convert.ToInt32(Request.QueryString["bookingRoomId"])); phInfoRoom.Visible = true; //var info = _bookingRoom.Room.Name + Environment.NewLine; //foreach (Customer customer in _bookingRoom.Customers) //{ // info += customer.Fullname + Environment.NewLine; //} litRoom.Text = _bookingRoom.Room.Name; } string argCode = string.Format("document.getElementById({0}).value", "arg"); // string storageId = string.Format("document.getElementById('{0}').value", ddlStorage.ClientID); string storageId = string.Format("document.getElementById('{0}').value", 0); // Tạo đoạn code đăng ký phương thức callback, trong đó txtCode là tham số truyền vào call back, ValidateProductCode là phương thức xử lý dữ liệu callback string cbReference = Page.ClientScript.GetCallbackEventReference(this, argCode + "+" + "'|'" + "+" + storageId, "LoadProduct", "context", "LoadProduct", true); // Đăng ký phương thức vừa tạo string cbScript = "function UseCallback(arg,context)" + "{" + cbReference + ";" + "}"; Page.ClientScript.RegisterClientScriptBlock(GetType(), "UseCallback", cbScript, true); _ivUnits = Module.IvUnitGetAll(null); if (!IsPostBack) { LoadStorage(); int count = Module.CountExportByDateTime(Request.QueryString, UserIdentity, DateTime.Today) + 1; txtCode.Text = string.Format("PX{0}-{1}", DateTime.Today.ToString("ddMMyyyy"), count); txtName.Text = string.Format("Phiếu xuất ngày {0}-{1}", DateTime.Today.ToString("dd/MM/yyyy"), count); txtExportedDate.Text = DateTime.Today.ToString("dd/MM/yyyy"); LoadInfoExport(); if (_currentExport.Id > 0) { BindrptProductList(); } } if (!UserIdentity.HasPermission(AccessLevel.Administrator)) { btnSaveProductExport.Visible = false; } }
protected void rptRoomsDay_OnItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "updateStatus") { var id = Convert.ToInt32(e.CommandArgument); var room = Module.RoomGetById(id); if (room != null) { var booking = FindBookingApproved(room, _currentDate); if (room.Status != RoomType.Cleaned) { if (room.Status == RoomType.InUsed) { room.Status = RoomType.NotCleaned; } else if (room.Status == RoomType.NotCleaned) { room.Status = RoomType.Cleaned; } else { room.Status = RoomType.InUsed; } Module.SaveOrUpdate(room); } else if (room.Status == RoomType.Cleaned && booking != null) { if (room.Status == RoomType.Cleaned) { room.Status = RoomType.InUsed; } Module.SaveOrUpdate(room); if (room.Status == RoomType.InUsed) { IvExport ivExport = new IvExport(); ivExport.ExportDate = DateTime.Now; ivExport.Room = room; ivExport.Status = IvExportType.Created; ivExport.BookingRoom = booking.BookingRooms.FirstOrDefault(r => r.Room.Id == room.Id); Module.SaveOrUpdate(ivExport, UserIdentity); } } else { ShowErrors("Không có booking nào cho phòng này ngày hôm nay"); } GetDataRoomInFloor(); } } }
protected void rptExportList_ItemCommand(object sender, RepeaterCommandEventArgs e) { switch (e.CommandName.ToLower()) { case "delete": IvExport export = Module.GetById <IvExport>(Convert.ToInt32(e.CommandArgument)); Module.Delete(export); BindrptExportList(); break; default: break; } }
public void PushExport(string exports) { InventoryServRes res = new InventoryServRes(); res.BillSuccess = new Dictionary <int, int>(); res.BillFails = new List <int>(); res.ProductFails = new List <int>(); res.BillProductFails = new Dictionary <int, int>(); res.BillProductSuccess = new Dictionary <int, int>(); try { if (!string.IsNullOrWhiteSpace(exports)) { var exportList = JsonConvert.DeserializeObject <List <ExportDTO> >(exports); if (exportList.Count > 0) { foreach (var r in exportList) { var count = Module.IvExportCheckByCode(r.Code); if (count <= 0) { var export = new IvExport(); try { if (r.ExportId > 0) { export = Module.GetById <IvExport>(r.ExportId); } export.ModifiedDate = r.ModifiedDate; export.Name = r.Name; if (r.BookingRoomId > 0) { export.BookingRoom = Module.BookingRoomGetById(r.BookingRoomId); if (export.BookingRoom.Customers != null) { export.TotalCustomer = export.BookingRoom.Customers.Count; export.AverageCost = export.Pay / export.TotalCustomer; } } export.Code = r.Code; export.CreatedDate = r.CreatedDate; export.CustomerName = r.CustomerName; export.Deleted = r.Deleted; export.Detail = r.Detail; export.Pay = r.Pay; if (r.RoomId > 0) { export.Room = Module.RoomGetById(r.RoomId); } export.Status = r.Status; if (r.StorageId > 0) { export.Storage = Module.IvStorageGetById(r.StorageId); } export.ExportDate = r.ExportDate; export.Total = r.Total; export.IsDebt = r.IsDebt; export.Agency = r.Agency; if (r.CruiseId > 0) { export.Cruise = Module.CruiseGetById(r.CruiseId); } Module.SaveOrUpdate(export); res.BillSuccess.Add(r.Id, export.Id); var isInsertProductSuccess = true; if (r.ExportProducts.Count > 0) { foreach (var p in r.ExportProducts) { try { var productExport = new IvProductExport(); if (p.ExportProductId > 0) { productExport = Module.GetById <IvProductExport>(p.ExportProductId); } productExport.Discount = p.Discount; productExport.DiscountType = p.DiscountType; productExport.Export = export; if (p.ProductId > 0) { productExport.Product = Module.IvProductGetById(p.ProductId); } productExport.QuanityRateParentUnit = p.QuanityRateParentUnit; productExport.Quantity = p.Quantity; if (p.StorageId > 0) { productExport.Storage = Module.IvStorageGetById(p.StorageId); } productExport.Total = p.Total; productExport.UnitPrice = p.UnitPrice; if (p.UnitId > 0) { productExport.Unit = Module.IvUnitGetById(p.UnitId); } Module.SaveOrUpdate(productExport); res.BillProductSuccess.Add(p.Id, productExport.Id); } catch (Exception e) { isInsertProductSuccess = false; res.ProductFails.Add(p.Id); res.Exceptions += p.Id + ".Pr :" + e.Message + Environment.NewLine; } } } if (!isInsertProductSuccess) { res.BillProductFails.Add(r.Id, export.Id); res.BillFails.Add(r.Id); } } catch (Exception e) { res.BillFails.Add(r.Id); res.Exceptions += r.Id + ".Ex: " + e.Message + Environment.NewLine; } } } } } res.Status = "1"; HttpContext.Current.Response.ContentType = "application/json"; HttpContext.Current.Response.Charset = "utf-8"; HttpContext.Current.Response.Write(JsonConvert.SerializeObject(res)); } catch (Exception e) { res.Status = "0"; HttpContext.Current.Response.ContentType = "application/json"; HttpContext.Current.Response.Charset = "utf-8"; HttpContext.Current.Response.Write(JsonConvert.SerializeObject(res)); } }
protected void rptExportList_ItemDataBound(object sender, RepeaterItemEventArgs e) { //if (e.Item.ItemType == ListItemType.Header) //{ // RepeaterOrder.FILE_NAME = "IvProductExportList.aspx"; // RepeaterOrder.SetOrderLink(e, "Name", Request.QueryString); // RepeaterOrder.SetOrderLink(e, "Code", Request.QueryString); // RepeaterOrder.SetOrderLink(e, "ExportDate", Request.QueryString); // RepeaterOrder.SetOrderLink(e, "ExportBy", Request.QueryString); // RepeaterOrder.SetOrderLink(e, "Total", Request.QueryString); // RepeaterOrder.SetOrderLink(e, "ExportTo", Request.QueryString); // return; //} if (e.Item.DataItem is IvExport) { IvExport export = (IvExport)e.Item.DataItem; HyperLink hplName = e.Item.FindControl("hplName") as HyperLink; if (hplName != null) { hplName.Text = export.Name; hplName.NavigateUrl = string.Format("IvExportAdd.aspx?NodeId={0}&SectionID={1}&ExportId={2}", Node.Id, Section.Id, export.Id); } Label lblCode = e.Item.FindControl("lblCode") as Label; if (lblCode != null) { lblCode.Text = export.Code; } Label lblRoom = e.Item.FindControl("lblRoom") as Label; if (lblRoom != null) { if (export.Room != null) { lblRoom.Text = export.Room.Name; } } Label lblCustomer = e.Item.FindControl("lblCustomer") as Label; if (lblCustomer != null) { lblCustomer.Text = export.CustomerName; } Label lblExportDate = e.Item.FindControl("lblExportDate") as Label; if (lblExportDate != null) { lblExportDate.Text = export.ExportDate.ToString("dd/MM/yyyy"); } Label lblExportBy = e.Item.FindControl("lblExportBy") as Label; if (lblExportBy != null) { lblExportBy.Text = export.ExportedBy; } Label lblExportTo = e.Item.FindControl("lblExportTo") as Label; if (lblExportTo != null) { lblExportTo.Text = export.CustomerName; } Label lblTotal = e.Item.FindControl("lblTotal") as Label; if (lblTotal != null) { lblTotal.Text = export.Total.ToString("#,0.#"); } Label lblPay = e.Item.FindControl("lblPay") as Label; if (lblPay != null) { lblPay.Text = export.Pay.ToString("#,0.#"); } Label lblStatus = e.Item.FindControl("lblStatus") as Label; if (lblStatus != null) { if (export.Pay >= export.Total) { lblStatus.Text = "Đã thanh toán"; } if (0 < export.Pay && export.Pay < export.Total) { lblStatus.Text = "Còn tồn"; } if (export.Pay <= 0) { lblStatus.Text = "Chưa thanh toán"; } } HyperLink hplEdit = e.Item.FindControl("hplEdit") as HyperLink; if (hplEdit != null) { hplEdit.NavigateUrl = string.Format("IvExportAdd.aspx?NodeId={0}&SectionId={1}&ExportId={2}", Node.Id, Section.Id, export.Id); } var btnDelete = e.Item.FindControl("btnDelete") as ImageButton; if (btnDelete != null) { if (!UserIdentity.HasPermission(AccessLevel.Administrator)) { btnDelete.Visible = false; } } } if (e.Item.ItemType == ListItemType.Footer) { Label lblsumTotal = e.Item.FindControl("lblsumTotal") as Label; if (lblsumTotal != null) { lblsumTotal.Text = sumTotal.ToString("#,0.#"); } } }