public TapmacViewModel(UserInformation user, string costCentCode) { // UserInformation user = (UserInformation)App.Current.Properties["userinfo"]; userinformation = user; costCenterCode = costCentCode; tapmac = new Tapmachine(userinformation); DDTAPPING_MAC ddtap = tapmac.getTapmachines(costCenterCode); if (ddtap == null) { ddtappingmac = new DDTAPPING_MAC(); ddtappingmac.COST_CENT_CODE = costCenterCode; ddtappingmac.MAX_TAP_SIZE = 0; ddtappingmac.MIN_TAP_SIZE = 0; ddtappingmac.MOTOR_POWER = 0; ddtappingmac.NO_OF_SPINDLES = 0; ddtappingmac.PUSH_STORKE_SHAFT_SPEED = 0; } else { ddtappingmac = new DDTAPPING_MAC(); ddtappingmac.COST_CENT_CODE = ddtap.COST_CENT_CODE; ddtappingmac.MAX_TAP_SIZE = ddtap.MAX_TAP_SIZE; ddtappingmac.MIN_TAP_SIZE = ddtap.MIN_TAP_SIZE; ddtappingmac.MOTOR_POWER = ddtap.MOTOR_POWER; ddtappingmac.NO_OF_SPINDLES = ddtap.NO_OF_SPINDLES; ddtappingmac.PUSH_STORKE_SHAFT_SPEED = ddtap.PUSH_STORKE_SHAFT_SPEED; } this.cancelTapmacCommand = new DelegateCommand(this.CancelTapmac); this.saveTapmacCommand = new DelegateCommand(this.SaveTapmac); this.unloadCommand = new DelegateCommand(this.UnloadTapmac); }
public bool saveTapmachine(DDTAPPING_MAC tapmac) { string mode = ""; DDTAPPING_MAC tapm = (from o in DB.DDTAPPING_MAC where o.COST_CENT_CODE == tapmac.COST_CENT_CODE && o.DELETE_FLAG == false select o).FirstOrDefault(); try { if (tapm == null) { tapm = new DDTAPPING_MAC(); mode = "New"; tapm.COST_CENT_CODE = tapmac.COST_CENT_CODE; tapm.DELETE_FLAG = false; tapm.ENTERED_BY = userInformation.UserName; tapm.ENTERED_DATE = DateTime.Now; tapm.ROWID = Guid.NewGuid(); } else { tapm.UPDATED_BY = userInformation.UserName; tapm.UPDATED_DATE = DateTime.Now; } tapm.MIN_TAP_SIZE = tapmac.MIN_TAP_SIZE; tapm.MAX_TAP_SIZE = tapmac.MAX_TAP_SIZE; tapm.MOTOR_POWER = tapmac.MOTOR_POWER; tapm.NO_OF_SPINDLES = tapmac.NO_OF_SPINDLES; tapm.PUSH_STORKE_SHAFT_SPEED = tapmac.PUSH_STORKE_SHAFT_SPEED; if (mode == "New") { DB.DDTAPPING_MAC.InsertOnSubmit(tapm); } DB.SubmitChanges(); tapm = null; return(true); } catch (System.Data.Linq.ChangeConflictException) { DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges); } catch (Exception ex) { ex.LogException(); if (mode == "New") { DB.DDTAPPING_MAC.DeleteOnSubmit(tapm); } else { DB.DDTAPPING_MAC.Context.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, tapm); } } return(false); }