private void UpdateMappedPhrase(InbAttribMapPhraseDto pData) { bool isUpdate = pData.Id > 0; DataRow row = null; try { InbAttribMapPhraseDal inbAttribMapPhraseDal = new InbAttribMapPhraseDal(sqlConnectionString); int methodResult = 0; if (isUpdate) { methodResult = inbAttribMapPhraseDal.Update(pData); } else if (pData.ActiveFlag.Equals("N")) { methodResult = inbAttribMapPhraseDal.Delete(pData.Id); } else { methodResult = inbAttribMapPhraseDal.Insert(pData); } if (methodResult > 0) { // update grid view with new row. if (tblPhrases == null) { InitPhraseTable(); } if (isUpdate) { row = tblPhrases.Rows.Find(pData.Id); if (row != null) { tblPhrases.Rows[tblPhrases.Rows.IndexOf(row)].Delete(); } } else { row = tblPhrases.NewRow(); row["ID"] = methodResult; row["Mapped Attribute ID"] = pData.InbAttribMapValId; row["Phrase"] = pData.Phrase; row["Active Flag"] = pData.ActiveFlag; tblPhrases.Rows.Add(row); } } else { throw new Exception("No Attribute changes were made to the database."); } } catch (Exception err) { XtraMessageBox.Show("An error occurred while attempting to perform the requested update." + Environment.NewLine + "Error CNF-301 in " + FORM_NAME + ".UpdateMappedPhrase(): " + err.Message, FORM_ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void barDeleteMapping_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { DataRow dr = null; try { if (gridViewMappedPhrases.IsValidRowHandle(gridViewMappedPhrases.FocusedRowHandle)) { dr = gridViewMappedPhrases.GetDataRow(gridViewMappedPhrases.FocusedRowHandle); InbAttribMapPhraseDal inbAttribMapPhraseDal = new InbAttribMapPhraseDal(sqlConnectionString); Int32 id = Convert.ToInt32(dr["ID"].ToString()); inbAttribMapPhraseDal.Delete(id); } } catch (Exception ex) { XtraMessageBox.Show("An error occurred while attempting to delete the requested mapping." + Environment.NewLine + "Error CNF-304 in " + FORM_NAME + ".barDeleteMapping_ItemClick(): " + ex.Message, FORM_ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void Test_InbAttribMapPhraseDal() { const string BASE_MAPPED_VALUE = "TEST_IF"; messageSeqNo = 0; // Pre-Requisite -- INB_ATTRIB row, CODE = "CPTY_SN" // INB_ATTRIB_MAP_VAL: ID = 1, MAPPED_VALUE = "TEST_IF" InbAttribMapValDal inbAttribMapValDal = new InbAttribMapValDal(sqlConnectionString); List<InbAttribMapValDto> resultMapValList = new List<InbAttribMapValDto>(); InbAttribMapValDto mapValData = new InbAttribMapValDto(); mapValData.InbAttribCode = "CPTY_SN"; mapValData.MappedValue = BASE_MAPPED_VALUE; mapValData.Descr = BASE_MAPPED_VALUE + "- DESCR"; mapValData.ActiveFlag = "Y"; //Make sure TEST_IF exists in INB_ATTRB table resultMapValList = inbAttribMapValDal.GetMapValues(mapValData.InbAttribCode); bool foundRow = false; foreach (InbAttribMapValDto mapVal in resultMapValList) { if (mapVal.MappedValue.Equals(BASE_MAPPED_VALUE)) { mapValData.Id = mapVal.Id; foundRow = true; break; } } if (!foundRow) { mapValData.Id = inbAttribMapValDal.Insert(mapValData); } Assert.IsTrue(mapValData.Id > 0, getMessage("Attrib Map Val row not found.")); InbAttribMapPhraseDal inbAttribMapPhraseDal = new InbAttribMapPhraseDal(sqlConnectionString); List<InbAttribMapPhraseDto> resultDataList = new List<InbAttribMapPhraseDto>(); List<InbAttribMapComboDto> resultComboList = new List<InbAttribMapComboDto>(); InbAttribMapPhraseDto parmData = new InbAttribMapPhraseDto(); //Make sure the data we are about to insert doesn't already exist. resultDataList = inbAttribMapPhraseDal.GetPhrases(mapValData.Id); int oldTestDataRowsDeleted = 0; foreach (InbAttribMapPhraseDto mapPhrase in resultDataList) { inbAttribMapPhraseDal.Delete(mapPhrase.Id); oldTestDataRowsDeleted++; } bool oldTestDataExists = resultDataList.Count != oldTestDataRowsDeleted; Assert.IsFalse(oldTestDataExists, getMessage("Old test data exists and was not deleted.")); //Main test routine const string INPUT_A = "TEST_IF_01"; const string INPUT_B = "TEST_IF_02"; const string INPUT_C = "TEST_IF_03"; const string INPUT_D = "TEST_IF_04"; Int32 testIdInsert1 = 0; Int32 testIdInsert2 = 0; //Insert -- test null value parms parmData.InbAttribMapValId = mapValData.Id; parmData.Phrase = INPUT_A; parmData.ActiveFlag = "Y"; testIdInsert1 = inbAttribMapPhraseDal.Insert(parmData); Assert.AreNotEqual(0, testIdInsert1, getMessage("Row inserted - non-Zero Id returned.")); expectedValue = INPUT_A; resultDataList = inbAttribMapPhraseDal.GetPhrases(parmData.InbAttribMapValId); Assert.IsTrue(resultDataList.Count > 0, getMessage("No rows returned after insert.")); foundRow = false; foreach (InbAttribMapPhraseDto mapPhrase in resultDataList) { if (mapPhrase.Id.Equals(testIdInsert1)) { Assert.AreEqual(INPUT_A, mapPhrase.Phrase, getMessage("MappedPhrase not found.")); foundRow = true; break; } } Assert.IsTrue(foundRow, getMessage("Row not found after insert.")); //Insert -- test non-null value parms parmData.InbAttribMapValId = mapValData.Id; parmData.Phrase = INPUT_B; parmData.ActiveFlag = "Y"; testIdInsert2 = inbAttribMapPhraseDal.Insert(parmData); Assert.AreNotEqual(0, testIdInsert2, getMessage("Row inserted - non-Zero Id returned.")); expectedValue = INPUT_B; resultComboList = inbAttribMapPhraseDal.GetPhrases("TEST_IF"); Assert.IsTrue(resultDataList.Count > 0, getMessage("No rows returned after insert.")); foundRow = false; foreach (InbAttribMapComboDto mapPhrase in resultComboList) { if (mapPhrase.PhraseId.Equals(testIdInsert2)) { Assert.AreEqual(INPUT_B, mapPhrase.Phrase, getMessage("MappedPhrase not found.")); foundRow = true; break; } } Assert.IsTrue(foundRow, getMessage("Row not found after insert.")); //Update parmData.InbAttribMapValId = mapValData.Id; parmData.Id = testIdInsert1; parmData.Phrase = INPUT_C; parmData.ActiveFlag = "Y"; int rowsUpdated = inbAttribMapPhraseDal.Update(parmData); resultDataList = inbAttribMapPhraseDal.GetPhrases(parmData.InbAttribMapValId); Assert.IsTrue(resultDataList.Count > 0, getMessage("No rows returned after update.")); foundRow = false; foreach (InbAttribMapPhraseDto mapPhrase in resultDataList) { if (mapPhrase.Id.Equals(testIdInsert1)) { Assert.AreEqual(INPUT_C, mapPhrase.Phrase, getMessage("MappedPhrase not found.")); foundRow = true; break; } } Assert.IsTrue(foundRow, getMessage("Row not found after update.")); //Update parmData.InbAttribMapValId = mapValData.Id; parmData.Id = testIdInsert2; parmData.Phrase = INPUT_D; parmData.ActiveFlag = "Y"; rowsUpdated = inbAttribMapPhraseDal.Update(parmData); resultDataList = inbAttribMapPhraseDal.GetPhrases(parmData.InbAttribMapValId); Assert.IsTrue(resultDataList.Count > 0, getMessage("No rows returned after update.")); foundRow = false; foreach (InbAttribMapPhraseDto mapPhrase in resultDataList) { if (mapPhrase.Id.Equals(testIdInsert2)) { Assert.AreEqual(INPUT_D, mapPhrase.Phrase, getMessage("MappedPhrase not found.")); foundRow = true; break; } } Assert.IsTrue(foundRow, getMessage("Row not found after update.")); //Delete rowsUpdated = inbAttribMapPhraseDal.Delete(testIdInsert1); Assert.IsTrue(rowsUpdated == 1, getMessage("Row not deleted.")); rowsUpdated = inbAttribMapPhraseDal.Delete(testIdInsert2); Assert.IsTrue(rowsUpdated == 1, getMessage("Row not deleted.")); }