public async Task <IActionResult> Create([Bind("RefLocationId,LocationName,RefLocationTypeId,ParentLocationId,Latitude,Longitude")] RefLocation refLocation) { if (ModelState.IsValid) { _context.Add(refLocation); await _context.SaveChangesAsync(); TempData["messageType"] = "success"; TempData["messageTitle"] = "RECORD CREATED"; TempData["message"] = "New record successfully created"; return(RedirectToAction(nameof(Index), new { id = refLocation.ParentLocationId })); } var parent = await _context.Locations .Include(x => x.LocationTypes) .Where(x => x.RefLocationId == refLocation.RefLocationId) .FirstOrDefaultAsync(); ViewData["RefLocationTypeId"] = new SelectList(_context.LocationTypes .Where(x => x.LocationLevel > parent.LocationTypes.LocationLevel), "RefLocationTypeId", "LocationType"); ViewData["ParentLocationName"] = parent.LocationName; ViewData["ParentId"] = refLocation.ParentLocationId; return(View(refLocation)); }
public async Task <IActionResult> Create([Bind("RefLocationId,LocationName,RefLocationTypeId,ParentLocationId,Latitude,Longitude")] RefLocation refLocation) { if (ModelState.IsValid) { _context.Add(refLocation); await _context.SaveChangesAsync(); TempData["messageType"] = "success"; TempData["messageTitle"] = "RECORD CREATED"; TempData["message"] = "New record successfully created"; return(RedirectToAction(nameof(Index))); } ViewData["RefLocationTypeId"] = new SelectList(_context.LocationTypes, "RefLocationTypeId", "LocationType", refLocation.RefLocationTypeId); ViewData["ParentLocationId"] = new SelectList(_context.Locations, "RefLocationId", "RefLocationId", refLocation.ParentLocationId); return(View(refLocation)); }
public async Task <IActionResult> Edit(string id, [Bind("RefLocationId,LocationName,RefLocationTypeId,ParentLocationId,Latitude,Longitude")] RefLocation refLocation) { if (id != refLocation.RefLocationId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(refLocation); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RefLocationExists(refLocation.RefLocationId)) { return(NotFound()); } else { throw; } } TempData["messageType"] = "success"; TempData["messageTitle"] = "RECORD UPDATED"; TempData["message"] = "Record successfully updated"; return(RedirectToAction(nameof(Index), new { id = refLocation.ParentLocationId })); } ViewData["RefLocationTypeId"] = new SelectList(_context.LocationTypes, "RefLocationTypeId", "LocationType", refLocation.RefLocationTypeId); ViewData["ParentLocationId"] = new SelectList(_context.Locations, "RefLocationId", "RefLocationId", refLocation.ParentLocationId); ViewData["ParentId"] = refLocation.ParentLocationId; return(View(refLocation)); }
protected void SaveLocation(ASPxGridView grid) { ASPxPageControl pageControl_Location = grid.FindEditFormTemplateControl("pageControl_Location") as ASPxPageControl; ASPxPageControl pageControl = this.grid.FindEditFormTemplateControl("pageControl") as ASPxPageControl; ASPxTextBox txt_WarehouseCode = pageControl.FindControl("txt_Code") as ASPxTextBox; ASPxTextBox txt_Id = pageControl_Location.FindControl("txt_Id") as ASPxTextBox; ASPxTextBox txt_Code = pageControl_Location.FindControl("txt_Location_Code") as ASPxTextBox; string id = SafeValue.SafeString(txt_Id.Text, ""); Wilson.ORMapper.OPathQuery query = new Wilson.ORMapper.OPathQuery(typeof(RefLocation), "Id='" + id + "'"); RefLocation obj = C2.Manager.ORManager.GetObject(query) as RefLocation; bool action = false; string code = ""; if (obj == null) { action = true; obj = new RefLocation(); string sql = "select Code from ref_location where LocLevel='Unit' and WarehouseCode='" + txt_WarehouseCode.Text + "'"; DataTable dt = C2.Manager.ORManager.GetDataSet(sql).Tables[0]; if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { code = dt.Rows[i]["Code"].ToString(); if (txt_Code.Text.ToUpper() == code.ToUpper()) { throw new Exception("Please enter another value of the Code again!"); return; } } } } if (txt_Code.Text == "") { throw new Exception("Code not be null!!!"); return; } obj.Code = txt_Code.Text; ASPxTextBox txtName = pageControl_Location.FindControl("txt_Location_Name") as ASPxTextBox; string name = txtName.Text.Trim(); if (txtName.Text == "") { throw new Exception("Name not be null!!!"); return; } obj.Name = name; obj.Code = txt_Code.Text; obj.WarehouseCode = txt_WarehouseCode.Text; ASPxButtonEdit txt_ZoneCode = pageControl_Location.FindControl("btn_L_ZoneCode") as ASPxButtonEdit; obj.ZoneCode = txt_ZoneCode.Text; ASPxButtonEdit txt_PartyId = pageControl_Location.FindControl("txt_PartyId") as ASPxButtonEdit; obj.PartyId = txt_PartyId.Text; ASPxButtonEdit txt_StoreCode = pageControl_Location.FindControl("btn_L_StoreCode") as ASPxButtonEdit; obj.StoreCode = txt_StoreCode.Text; ASPxSpinEdit txt_Length = pageControl_Location.FindControl("txt_Length") as ASPxSpinEdit; obj.Length = SafeValue.SafeDecimal(txt_Length.Text); ASPxSpinEdit txt_Width = pageControl_Location.FindControl("txt_Width") as ASPxSpinEdit; obj.Width = SafeValue.SafeDecimal(txt_Width.Text); ASPxSpinEdit txt_Height = pageControl_Location.FindControl("txt_Height") as ASPxSpinEdit; obj.Height = SafeValue.SafeDecimal(txt_Height.Text); ASPxSpinEdit txt_SpaceM3 = pageControl_Location.FindControl("txt_SpaceM3") as ASPxSpinEdit; obj.SpaceM3 = SafeValue.SafeDecimal(txt_SpaceM3.Text); ASPxMemo memoRemark = pageControl_Location.FindControl("memo_Remark") as ASPxMemo; obj.Remark = memoRemark.Text; if (action) { obj.CreateBy = EzshipHelper.GetUserName(); obj.CreateDateTime = DateTime.Now; obj.Loclevel = "Unit"; Manager.ORManager.StartTracking(obj, Wilson.ORMapper.InitialState.Inserted); Manager.ORManager.PersistChanges(obj); } else { obj.UpdateBy = EzshipHelper.GetUserName(); obj.UpdateDateTime = DateTime.Now; Manager.ORManager.StartTracking(obj, Wilson.ORMapper.InitialState.Updated); Manager.ORManager.PersistChanges(obj); } }
protected void AddOrUpdate() { ASPxPageControl pageControl = this.grid.FindEditFormTemplateControl("pageControl") as ASPxPageControl; ASPxTextBox txt_Id = pageControl.FindControl("txt_Id") as ASPxTextBox; ASPxTextBox txt_Code = pageControl.FindControl("txt_Code") as ASPxTextBox; ASPxLabel lblMess = pageControl.FindControl("lblMessage") as ASPxLabel; string id = SafeValue.SafeString(txt_Id.Text, ""); Wilson.ORMapper.OPathQuery query = new Wilson.ORMapper.OPathQuery(typeof(RefLocation), "Id='" + id + "'"); RefLocation obj = C2.Manager.ORManager.GetObject(query) as RefLocation; bool action = false; string code = ""; string pId = ""; if (obj == null) { action = true; obj = new RefLocation(); string sql = "select Code from ref_location"; DataTable dt = C2.Manager.ORManager.GetDataSet(sql).Tables[0]; if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { code = dt.Rows[i]["Code"].ToString(); if (txt_Code.Text.ToUpper() == code.ToUpper()) { throw new Exception("Please enter another value of the Short Name again!"); return; } } } } if (txt_Code.Text == "") { throw new Exception("Code not be null!!!"); return; } obj.Code = txt_Code.Text; ASPxTextBox txtName = pageControl.FindControl("txt_Name") as ASPxTextBox; string name = txtName.Text.Trim(); //if (txtName.Text == "") //{ // throw new Exception("Name not be null!!!"); // return; //} obj.Name = name; obj.Code = txt_Code.Text; ASPxButtonEdit txt_WarehouseCode = pageControl.FindControl("txt_WarehouseCode") as ASPxButtonEdit; obj.WarehouseCode = txt_WarehouseCode.Text; ASPxButtonEdit btn_ZoneCode = pageControl.FindControl("btn_ZoneCode") as ASPxButtonEdit; obj.ZoneCode = btn_ZoneCode.Text; ASPxButtonEdit txt_PartyId = pageControl.FindControl("txt_PartyId") as ASPxButtonEdit; obj.PartyId = txt_PartyId.Text; ASPxButtonEdit btn_StoreCode = pageControl.FindControl("btn_StoreCode") as ASPxButtonEdit; obj.StoreCode = btn_StoreCode.Text; ASPxSpinEdit txt_Length = pageControl.FindControl("txt_Length") as ASPxSpinEdit; obj.Length = SafeValue.SafeDecimal(txt_Length.Text); ASPxSpinEdit txt_Width = pageControl.FindControl("txt_Width") as ASPxSpinEdit; obj.Width = SafeValue.SafeDecimal(txt_Width.Text); ASPxSpinEdit txt_Height = pageControl.FindControl("txt_Height") as ASPxSpinEdit; obj.Height = SafeValue.SafeDecimal(txt_Height.Text); ASPxSpinEdit txt_SpaceM3 = pageControl.FindControl("txt_SpaceM3") as ASPxSpinEdit; obj.SpaceM3 = SafeValue.SafeDecimal(txt_SpaceM3.Text); ASPxMemo memoRemark = pageControl.FindControl("memo_Remark") as ASPxMemo; obj.Remark = memoRemark.Text; ASPxTextBox txt_Loclevel = pageControl.FindControl("txt_Loclevel") as ASPxTextBox; obj.Loclevel = txt_Loclevel.Text; if (action) { obj.CreateBy = HttpContext.Current.User.Identity.Name; obj.CreateDateTime = DateTime.Now; Manager.ORManager.StartTracking(obj, Wilson.ORMapper.InitialState.Inserted); Manager.ORManager.PersistChanges(obj); Session["NameWhere"] = "Id='" + obj.Id + "'"; this.dsRefLocation.FilterExpression = Session["NameWhere"].ToString(); if (this.grid.GetRow(0) != null) { this.grid.StartEdit(0); } } else { obj.UpdateBy = HttpContext.Current.User.Identity.Name; obj.UpdateDateTime = DateTime.Now; Manager.ORManager.StartTracking(obj, Wilson.ORMapper.InitialState.Updated); Manager.ORManager.PersistChanges(obj); } }
protected void btnAdd_Click(object sender, EventArgs e) { try { if (cmb_WareHouse.Value != null) { int column = SafeValue.SafeInt(Column.Value, 0); int level = SafeValue.SafeInt(Level.Value, 0); string rack = Rack.Value; if (column > 0) { string zone = rack + "00"; #region Zone RefLocation obj = new RefLocation(); obj.Name = "RACK:" + rack; obj.Code = zone; obj.WarehouseCode = SafeValue.SafeString(cmb_WareHouse.Value); obj.ZoneCode = ""; obj.PartyId = ""; obj.StoreCode = ""; obj.Length = 0; obj.Width = 0; obj.Height = 0; obj.SpaceM3 = 0; obj.Remark = ""; obj.Loclevel = "Zone"; obj.CreateBy = HttpContext.Current.User.Identity.Name; obj.CreateDateTime = DateTime.Now; obj.UpdateBy = HttpContext.Current.User.Identity.Name; obj.UpdateDateTime = DateTime.Now; Manager.ORManager.StartTracking(obj, Wilson.ORMapper.InitialState.Inserted); Manager.ORManager.PersistChanges(obj); #endregion for (int i = 1; i <= column; i++) { #region Location string loc = ""; if (i < 10) { zone = rack + "0" + i; } else { zone = rack + i; } if (level > 0) { for (int j = 1; j <= level; j++) { if (j > 0 && j < 10) { loc = zone + "-" + "0" + j; } else { loc = zone + "-" + j; } if (loc.Length > 0) { #region Loction RefLocation obj1 = new RefLocation(); obj1.Name = loc; obj1.Code = loc; obj1.WarehouseCode = SafeValue.SafeString(cmb_WareHouse.Value); obj1.ZoneCode = rack + "00"; obj1.PartyId = ""; obj1.StoreCode = ""; obj1.Length = 0; obj1.Width = 0; obj1.Height = 0; obj1.SpaceM3 = 0; obj1.Remark = ""; obj1.Loclevel = "Unit"; obj1.CreateBy = HttpContext.Current.User.Identity.Name; obj1.CreateDateTime = DateTime.Now; obj1.UpdateBy = HttpContext.Current.User.Identity.Name; obj1.UpdateDateTime = DateTime.Now; Manager.ORManager.StartTracking(obj1, Wilson.ORMapper.InitialState.Inserted); Manager.ORManager.PersistChanges(obj1); #endregion } } } #endregion } this.lab.Text = "Success!"; } } else { this.lab.Text = "Warehouse is not null"; } } catch (Exception ex) { this.lab.Text = "Warehouse is not null"; } }