// ADD Record private void buttonADD_Click(object sender, RoutedEventArgs e) { lwdom_chemlist_Model lwdclMod = new lwdom_chemlist_Model(); lwdom_chemlist_Woker LWDCLWkr = new lwdom_chemlist_Woker(); // load the model lwdclMod = Load_Model(); // async ADD clVM.Add_ChemList_Async(lwdclMod); // reset fields ResetDisplayFields(); // use inital button configuration InitialButtonConfiguration(); }
// constructor public ChemList_ViewModel() { // worker CLWkr = new lwdom_chemlist_Woker(); }
// UPDATE ChemList Record private void buttonUpdate_Click(object sender, RoutedEventArgs e) { lwdom_chemlist_Model lwdclMod = new lwdom_chemlist_Model(); lwdom_chemlist_Woker LWDCLWkr = new lwdom_chemlist_Woker(); // load the model lwdclMod = (lwdom_chemlist_Model)this.DataContext; // async Update clVM.Update_ChemList_Async(lwdclMod); // reset fields ResetDisplayFields(); // use inital button configuration InitialButtonConfiguration(); }
// DELETE Record private void buttonDELETE_Click(object sender, RoutedEventArgs e) { lwdom_chemlist_Woker LWDCLWkr = new lwdom_chemlist_Woker(); MessageBoxResult result; Int64 recID = 0; bool boolResult = false; result = MessageBox.Show("You are about to Delete a record.\nDo you want to continue?", "Delete", MessageBoxButton.OKCancel, MessageBoxImage.Warning); string strMsg = ""; if (MessageBoxResult.OK == result) { boolResult = Int64.TryParse(lblOBJECTID.Content.ToString(), out recID); if (recID > 0) { strMsg = LWDCLWkr.Delete_ChemList_rec(recID); } else { strMsg = "Record ID problem"; } } else { strMsg = "Delete Cancelled."; } // put message in sender sender = strMsg; // reset ResetDisplayFields(); // initial button config InitialButtonConfiguration(); // Delete Event if (OnChemList_DELETE != null) OnChemList_DELETE(sender, new RoutedEventArgs()); }
// constructor public Win_LWChemList() { InitializeComponent(); LWCWkr = new lwdom_chemlist_Woker(); _ActStatus = ""; // LISTENER: Selected data changed // Handle on ChemList selection changed events uc_ChemicalList_List.OnChemList_SELECTED += (o, e) => { var datagrid = (DataGrid)o; var itm = datagrid.SelectedItem; if ((itm is lwdom_chemlist_Model) == false) return; lwdom_chemlist_Model selectedContent = (lwdom_chemlist_Model)itm; uc_ChemicalList_Detail.DataContext = selectedContent; labelStatus.Content = "ChemCode ID: " + selectedContent.ChemCode; uc_ChemicalList_Detail.Execute_UpdateButtonConfiguration(); }; // ADD ENABLED - used for both blank // and copy base ADD uc_ChemicalList_Detail.OnChemList_ADDEnabel += (o, e) => { // display message labelStatus.Content = o.ToString(); }; // ADD Record uc_ChemicalList_Detail.OnChemList_ADD += (o, e) => { // display message labelStatus.Content = o.ToString(); // turn ON busy Indicator busy_Indicator.IsBusy = true; // redisplay data in grid // Get Async Chem List clVM.Get_ChemList_byActiveStatus_Async(_ActStatus); }; // UPDATE Record uc_ChemicalList_Detail.OnChemList_UPDATE += (o, e) => { // display message labelStatus.Content = o.ToString(); _SearchChemCode = ""; if (txtSearchChemCode != null) _SearchChemCode = txtSearchChemCode.Text.Trim(); // turn ON busy Indicator busy_Indicator.IsBusy = true; // redisplay data in grid // Get Async Work Order List // SearchChemCode has value if (_SearchChemCode.Trim() != "") { clVM.Get_List_byLIKEChemCode_Async(_SearchChemCode); } else { // redisplay data in grid // Get Async Chem List // SearchChemCode does not have value clVM.Get_ChemList_byActiveStatus_Async(_ActStatus); txtSearchChemCode.Text.Trim(); } }; // DELETE Record uc_ChemicalList_Detail.OnChemList_DELETE += (o, e) => { // display message labelStatus.Content = o.ToString(); // turn ON busy Indicator busy_Indicator.IsBusy = true; // redisplay data in grid // Get Async Chem List clVM.Get_ChemList_byActiveStatus_Async(_ActStatus); }; // CANCEL uc_ChemicalList_Detail.OnChemList_CANCEL += (o, e) => { // display message labelStatus.Content = o.ToString(); // turn ON busy Indicator busy_Indicator.IsBusy = true; // redisplay data in grid // Get Async Chem List clVM.Get_ChemList_Async(); uc_ChemicalList_List.cboChemActiveStatus.Text = ""; }; // LISTENER: Async Get Chem List base on active // status selection uc_ChemicalList_List.OnChemList_StatusSELECTED += (o, e) => { _ActStatus = o.ToString(); // turn ON busy Indicator busy_Indicator.IsBusy = true; // reset and initial button uc_ChemicalList_Detail.Execute_InitialButtonConfiguration(); // Get List, Async Get if (_ActStatus.Trim() != "") { clVM.Get_ChemList_byActiveStatus_Async(_ActStatus); uc_ChemicalList_List.LabelBanner.Content = "Chemical List (" + _ActStatus + ")"; } else { clVM.Get_ChemList_Async(); uc_ChemicalList_List.LabelBanner.Content = "Chemical List"; } }; // Listening for ViewModel Property Change // -------------------------------- // Loading the data grid MVVM style // -------------------------------- clVM.PropertyChanged += (o, e) => { // the View Model is notifying us that a property was updated // checking for a specific property returned by the View Model if (e.PropertyName == "Chemical_List") { uc_ChemicalList_List.DataContext = clVM.clvmMod_List; labelStatus.Content = "Retrieved " + clVM.clvmMod_List.Count + " Chemicals."; // turn off busy Indicator busy_Indicator.IsBusy = false; // change key board focus Keyboard.Focus(txtSearchChemCode); } }; // Telling the ViewModel to retieve data clVM.Get_ChemList_Async(); labelStatus.Content = "Retrieving data..."; }