/// <summary> /// Berfungsi untuk menambahkan component di halaman edit memo /// </summary> /// <param name="memoID">Sebuah integer yang merupakan id dari memo</param> /// <param name="memoViewModel">Sebuah object dari memo view model</param> /// <returns>Component berhasil ditambahkan</returns> public ActionResult AddMemoComponent(int memoID, MemoViewModel memoViewModel) { try { var username = User.Identity.Name; foreach (var memoComponent in memoViewModel.selectedPROComponentID) { var newMemoComponent = new MemoComponent { MemoID = memoID, ComponentID = memoComponent, Created = DateTime.Now, CreatedBy = username, LastModified = DateTime.Now, LastModifiedBy = username }; db.MemoComponents.Add(newMemoComponent); } db.SaveChanges(); Session["message"] = "component added"; return(RedirectToAction("Edit", "Memo", new { id = memoID })); } catch (Exception ex) { ViewBag.Exception = ex; } return(View("Error")); }
public IHttpActionResult DeleteMemoJobCard(int memoJobCardID, int componentID, int memoComponentID, int memoQuantity, string userID, string userName) { using (PowerAppsCMSEntities db = new PowerAppsCMSEntities()) { Guid guidUserID = Guid.Parse(userID.Replace(" ", string.Empty)); DateTime now = DateTime.Now; MemoJobCard selectedMemoJobCard = db.MemoJobCards.Find(memoJobCardID); db.MemoJobCards.Remove(selectedMemoJobCard); if (db.SaveChanges() > 0) { MemoComponent selectedMemoComponent = db.MemoComponents.Where(x => x.ID == memoComponentID).SingleOrDefault(); bool isEqualValue = IsEqual(componentID, memoComponentID, memoQuantity); if (isEqualValue == false && selectedMemoComponent.Status == (int)MemoStatus.Complete) { selectedMemoComponent.Status = (int)MemoStatus.OnProcess; selectedMemoComponent.LastModifiedBy = userName; selectedMemoComponent.LastModified = now; db.SaveChanges(); } int countListMemoJobCards = db.MemoJobCards.Where(x => x.MemoComponentID == memoComponentID).Count(); if (countListMemoJobCards == 0) { selectedMemoComponent.Status = (int)MemoStatus.NotStarted; selectedMemoComponent.LastModifiedBy = userName; selectedMemoComponent.LastModified = now; db.SaveChanges(); } } return(Ok(HttpStatusCode.OK)); } }
private static bool PrintOrderCode(this OnlineOrder order, string printer) { var index = 1; var count = order.Items.Sum(o => o.Count); foreach (var item in order.Items) { for (int i = 0; i < item.Count; i++) { var memo = new MemoComponent(order.TradeCode, item.Product, item.Option, index, count); PrintDocument document = new PrintDocument(); document.PrinterSettings.PrinterName = printer; document.PrinterSettings.DefaultPageSettings.Margins = new Margins(2, 0, 0, 0); document.PrintPage += (sender, ev) => { foreach (var print in memo.GenernatePrintItems()) { ev.Graphics.DrawString(print.Text, print.Font, Brushes.Black, new PointF(print.Point.X, print.Point.Y)); } }; index++; document.Print(); } } return(true); }
public void DelMemoComponent(string str) { MemoComponent memo = null; if (memoComponents.TryGetValue(str, out memo)) { memoComponents.Remove(str); memo.Close(); } }
public IHttpActionResult PostMemoJobCard(int componentID, int memoComponentID, int PBProcessID, int quantity, int memoQuantity, string userID, string userName) { using (PowerAppsCMSEntities db = new PowerAppsCMSEntities()) { Guid guidUserID = Guid.Parse(userID.Replace(" ", string.Empty)); DateTime now = DateTime.Now; MemoJobCard memoJobCard = new MemoJobCard(); memoJobCard.MemoComponentID = memoComponentID; memoJobCard.MaterialPreparationProcessID = PBProcessID; memoJobCard.Quantity = quantity; memoJobCard.UserID = guidUserID; memoJobCard.Created = memoJobCard.LastModified = now; memoJobCard.CreatedBy = memoJobCard.LastModifiedBy = userName; db.MemoJobCards.Add(memoJobCard); if (db.SaveChanges() > 0) { MemoComponent selectedMemoComponent = db.MemoComponents.Where(x => x.ID == memoComponentID).SingleOrDefault(); if (selectedMemoComponent.Status == (int)MemoStatus.NotStarted) { selectedMemoComponent.Status = (int)MemoStatus.OnProcess; selectedMemoComponent.LastModifiedBy = userName; selectedMemoComponent.LastModified = now; db.SaveChanges(); } bool isEqualValue = IsEqual(componentID, memoComponentID, memoQuantity); if (isEqualValue == true) { selectedMemoComponent.Status = (int)MemoStatus.Complete; selectedMemoComponent.LastModifiedBy = userName; selectedMemoComponent.LastModified = now; db.SaveChanges(); } } return(Ok(HttpStatusCode.OK)); } }
/// <summary> /// Berfungsi untuk menambahkan memo baru ke dalam database /// </summary> /// <param name="memoViewModel">Sebuah object dari memo view model</param> /// <returns>Ketika memo berhasil ditambahkan, maka web akan meredirect ke halaman detail</returns> public ActionResult SaveMemo(MemoViewModel memoViewModel) { List <Services.NewMemoServices> memo = (List <Services.NewMemoServices>)Session["newMemo"]; var currentMemo = memo[0].Memo; var currentListOfMemoPRO = memo[0].ListOfMemoPROs; try { var username = User.Identity.Name; var newMemo = new Memo { Description = currentMemo.Description, MemoTypeID = currentMemo.MemoTypeID, ProductID = currentMemo.ProductID, Created = DateTime.Now, CreatedBy = username, LastModified = DateTime.Now, LastModifiedBy = username }; db.Memos.Add(newMemo); db.SaveChanges(); var newMemoID = newMemo.ID; foreach (var memoPro in currentListOfMemoPRO) { var newMemoPRO = new MemoPRO { MemoID = newMemoID, PROID = memoPro.PROID, Quantity = memoPro.Quantity, Created = DateTime.Now, CreatedBy = username, LastModified = DateTime.Now, LastModifiedBy = username }; db.MemoPROes.Add(newMemoPRO); } db.SaveChanges(); var selectedComponent = memoViewModel.SelectedComponent; foreach (int componentID in memoViewModel.SelectedComponent) { var newMemoComponent = new MemoComponent { MemoID = newMemoID, ComponentID = componentID, Created = DateTime.Now, CreatedBy = username, LastModified = DateTime.Now, LastModifiedBy = username }; db.MemoComponents.Add(newMemoComponent); } db.SaveChanges(); Session.Remove("newMemo"); return(RedirectToAction("Details", "Memo", new { id = newMemoID })); } catch (Exception ex) { ViewBag.Exception = ex; } return(View("Error")); }