protected void fvCommunication_PhoneNumber_ItemUpdating(object sender, FormViewUpdateEventArgs e) { TextBox tbAreaCode = fvCommunication_PhoneNumber.FindControl("tbAreaCode") as TextBox; TextBox tbPhoneNumber = fvCommunication_PhoneNumber.FindControl("tbPhoneNumber") as TextBox; StringBuilder sb = new StringBuilder(); using (WACDataClassesDataContext wDataContext = new WACDataClassesDataContext()) { var a = wDataContext.communications.Where(w => w.pk_communication == Convert.ToInt32(fvCommunication_PhoneNumber.DataKey.Value)).Select(s => s).Single(); if (!string.IsNullOrEmpty(tbAreaCode.Text)) { a.areacode = WACGlobal_Methods.Format_Global_PhoneNumber_StripToNumbers(tbAreaCode.Text, WACGlobal_Methods.Enum_Number_Type.AREACODE); } else { sb.Append("Area Code was not updated. Area Code is required. "); } if (!string.IsNullOrEmpty(tbPhoneNumber.Text)) { a.number = WACGlobal_Methods.Format_Global_PhoneNumber_StripToNumbers(tbPhoneNumber.Text, WACGlobal_Methods.Enum_Number_Type.PHONENUMBER); } else { sb.Append("Phone Number was not updated. Phone Number is required. "); } a.modified = DateTime.Now; a.modified_by = Session["userName"].ToString(); try { wDataContext.SubmitChanges(); fvCommunication_PhoneNumber.ChangeMode(FormViewMode.ReadOnly); BindCommunication_PhoneNumber(Convert.ToInt32(fvCommunication_PhoneNumber.DataKey.Value)); if (!string.IsNullOrEmpty(sb.ToString())) { WACAlert.Show(sb.ToString(), 0); } } catch (Exception ex) { WACAlert.Show(ex.Message, 0); } } }
private void Insert_Communications() { lblGlobal_Insert_Communications.ForeColor = System.Drawing.Color.ForestGreen; StringBuilder sb = new StringBuilder(); try { using (WACDataClassesDataContext wac = new WACDataClassesDataContext()) { string sAreaCode = null; if (!string.IsNullOrEmpty(tbCommunications_AreaCode.Text)) { sAreaCode = WACGlobal_Methods.Format_Global_PhoneNumber_StripToNumbers(tbCommunications_AreaCode.Text, WACGlobal_Methods.Enum_Number_Type.AREACODE); } else { sb.Append("Area Code is required. "); } if (string.IsNullOrEmpty(sAreaCode)) { sb.Append("Area Code not in correct format. "); } string sPhoneNumber = null; if (!string.IsNullOrEmpty(tbCommunications_PhoneNumber.Text)) { sPhoneNumber = WACGlobal_Methods.Format_Global_PhoneNumber_StripToNumbers(tbCommunications_PhoneNumber.Text, WACGlobal_Methods.Enum_Number_Type.PHONENUMBER); } else { sb.Append("Phone Number is required. "); } if (string.IsNullOrEmpty(sPhoneNumber)) { sb.Append("Phone Number not in correct format. "); } if (string.IsNullOrEmpty(sb.ToString())) { int?i = null; int iCode = wac.communication_add(sAreaCode, sPhoneNumber, Session["userName"].ToString(), ref i); if (iCode == 0) { tbCommunications_AreaCode.Text = ""; tbCommunications_PhoneNumber.Text = ""; lblGlobal_Insert_Communications.Text = "Successfully added Communication: " + WACGlobal_Methods.Format_Global_PhoneNumberSeparateAreaCode(sAreaCode, sPhoneNumber); } else { WACAlert.Show("Error Inserting Communication: ", iCode); } } else { WACAlert.Show(sb.ToString(), 0); } } } catch (Exception ex) { lblGlobal_Insert_Communications.ForeColor = System.Drawing.Color.Red; lblGlobal_Insert_Communications.Text = "Error Inserting Communication: " + ex.Message; } }
protected void fvCommunication_PhoneNumber_ItemInserting(object sender, FormViewInsertEventArgs e) { int?i = null; int iCode = 0; TextBox tbAreaCode = fvCommunication_PhoneNumber.FindControl("tbAreaCode") as TextBox; TextBox tbPhoneNumber = fvCommunication_PhoneNumber.FindControl("tbPhoneNumber") as TextBox; StringBuilder sb = new StringBuilder(); using (WACDataClassesDataContext wDataContext = new WACDataClassesDataContext()) { try { string sAreaCode = null; if (!string.IsNullOrEmpty(tbAreaCode.Text)) { sAreaCode = WACGlobal_Methods.Format_Global_PhoneNumber_StripToNumbers(tbAreaCode.Text, WACGlobal_Methods.Enum_Number_Type.AREACODE); } else { sb.Append("Area Code is required. "); } if (string.IsNullOrEmpty(sAreaCode)) { sb.Append("Area Code not in correct format. "); } string sPhoneNumber = null; if (!string.IsNullOrEmpty(tbPhoneNumber.Text)) { sPhoneNumber = WACGlobal_Methods.Format_Global_PhoneNumber_StripToNumbers(tbPhoneNumber.Text, WACGlobal_Methods.Enum_Number_Type.PHONENUMBER); } else { sb.Append("Phone Number is required. "); } if (string.IsNullOrEmpty(sPhoneNumber)) { sb.Append("Phone Number not in correct format. "); } if (string.IsNullOrEmpty(sb.ToString())) { iCode = wDataContext.communication_add(sAreaCode, sPhoneNumber, Session["userName"].ToString(), ref i); if (iCode == 0) { fvCommunication_PhoneNumber.ChangeMode(FormViewMode.ReadOnly); BindCommunication_PhoneNumber(Convert.ToInt32(i)); } else { WACAlert.Show("Error Returned from Database.", iCode); } } else { WACAlert.Show(sb.ToString(), 0); } } catch (Exception ex) { WACAlert.Show("Error: " + ex.Message, 0); } } }