public bool SetPreferencesV2(string RegistrationKey, webforms_preference prefObj) { long DentalOfficeID = util.GetDentalOfficeID(RegistrationKey); try { ODWebServiceEntities db = new ODWebServiceEntities(); if (DentalOfficeID == 0) { } var wspObj = db.webforms_preference.Where(wsp => wsp.DentalOfficeID == DentalOfficeID); //update preference if (wspObj.Count() > 0) { wspObj.First().ColorBorder = prefObj.ColorBorder; wspObj.First().CultureName = prefObj.CultureName; } // if there is no entry for that dental office make a new entry. if (wspObj.Count() == 0) { prefObj.DentalOfficeID = DentalOfficeID; db.AddTowebforms_preference(prefObj); } db.SaveChanges(); Logger.Information("Preferences saved IpAddress=" + HttpContext.Current.Request.UserHostAddress + " DentalOfficeID=" + DentalOfficeID); } catch (Exception ex) { Logger.LogError("IpAddress=" + HttpContext.Current.Request.UserHostAddress + " DentalOfficeID=" + DentalOfficeID, ex); return(false); } return(true); }
public void DeleteSheetData(string RegistrationKey, List <long> SheetsForDeletion) { long DentalOfficeID = util.GetDentalOfficeID(RegistrationKey); try { if (DentalOfficeID == 0) { return; } ODWebServiceEntities db = new ODWebServiceEntities(); for (int i = 0; i < SheetsForDeletion.Count(); i++) { long SheetID = SheetsForDeletion.ElementAt(i); // LINQ throws an error if this is directly put into the select expression // first delete all sheet field then delete the sheet so that a foreign key error is not thrown var delSheetField = from wsf in db.webforms_sheetfield where wsf.webforms_sheet.SheetID == SheetID select wsf; for (int j = 0; j < delSheetField.Count(); j++) { // the ElementAt operator only works with lists. Hence ToList() db.DeleteObject(delSheetField.ToList().ElementAt(j)); } var delSheet = from ws in db.webforms_sheet where ws.SheetID == SheetID select ws; db.DeleteObject(delSheet.First()); Logger.Information("deleted SheetID=" + SheetID + " DentalOfficeID=" + DentalOfficeID); } db.SaveChanges(); Logger.Information("In DeleteSheetData IpAddress=" + HttpContext.Current.Request.UserHostAddress + " DentalOfficeID=" + DentalOfficeID); } catch (Exception ex) { Logger.LogError("IpAddress=" + HttpContext.Current.Request.UserHostAddress + " DentalOfficeID=" + DentalOfficeID, ex); } }
public void DeleteSheetDef(string RegistrationKey, long WebSheetDefID) { long DentalOfficeID = util.GetDentalOfficeID(RegistrationKey); try { if (DentalOfficeID == 0) { return; } ODWebServiceEntities db = new ODWebServiceEntities(); webforms_sheetdef SheetDefObj = null; var SheetDefResult = db.webforms_sheetdef.Where(sd => sd.WebSheetDefID == WebSheetDefID); if (SheetDefResult.Count() > 0) { SheetDefObj = SheetDefResult.First(); //load and delete existing child objects i.e sheetfielddefs objects SheetDefObj.webforms_sheetfielddef.Load(); var SheetFieldDefResult = SheetDefObj.webforms_sheetfielddef; while (SheetFieldDefResult.Count() > 0) { db.DeleteObject(SheetFieldDefResult.First()); //Delete SheetFieldDefObj } db.DeleteObject(SheetDefResult.First()); //Delete SheetDefObj Logger.Information("deleted WebSheetDefID=" + WebSheetDefID + " DentalOfficeID=" + DentalOfficeID); } db.SaveChanges(); Logger.Information("In DeleteSheetDef IpAddress=" + HttpContext.Current.Request.UserHostAddress + " DentalOfficeID=" + DentalOfficeID); } catch (Exception ex) { Logger.LogError("IpAddress=" + HttpContext.Current.Request.UserHostAddress + " DentalOfficeID=" + DentalOfficeID, ex); } }
public void UpLoadSheetDef(string RegistrationKey, SheetDef sheetDef) { ODWebServiceEntities db = new ODWebServiceEntities(); long DentalOfficeID = util.GetDentalOfficeID(RegistrationKey); try{ if (DentalOfficeID == 0) { return; } var PreferenceResult = db.webforms_preference.Where(pref => pref.DentalOfficeID == DentalOfficeID); webforms_sheetdef SheetDefObj = null; SheetDefObj = new webforms_sheetdef(); PreferenceResult.First().webforms_sheetdef.Add(SheetDefObj); FillSheetDef(sheetDef, SheetDefObj); FillFieldSheetDef(sheetDef, SheetDefObj); db.SaveChanges(); } catch (Exception ex) { Logger.LogError("IpAddress=" + HttpContext.Current.Request.UserHostAddress + " DentalOfficeID=" + DentalOfficeID, ex); return; } }
private void SaveFieldValuesInDB(long DentalOfficeID, long WebSheetDefID) { try { Logger.Information("In SaveFieldValuesInDB" + " IpAddress=" + HttpContext.Current.Request.UserHostAddress + " DentalOfficeID=" + DentalOfficeID); ODWebServiceEntities db = new ODWebServiceEntities(); var SheetDefObj = db.webforms_sheetdef.Where(sd => sd.WebSheetDefID == WebSheetDefID && sd.webforms_preference.DentalOfficeID == DentalOfficeID).First(); webforms_sheet NewSheetObj = new webforms_sheet(); NewSheetObj.DateTimeSheet = DateTime.Now; NewSheetObj.Height = SheetDefObj.Height; NewSheetObj.Width = SheetDefObj.Width; NewSheetObj.FontName = SheetDefObj.FontName; NewSheetObj.FontSize = SheetDefObj.FontSize; NewSheetObj.SheetType = SheetDefObj.SheetType; NewSheetObj.Description = SheetDefObj.Description; NewSheetObj.IsLandscape = SheetDefObj.IsLandscape; SheetDefObj.webforms_sheetfielddef.Load(); var SheetFieldDefResult = SheetDefObj.webforms_sheetfielddef; //copy sheetfielddef values to sheetfield.The FieldValue, if any is overwritten from the hash table. for (int i = 0; i < SheetFieldDefResult.Count(); i++) { webforms_sheetfield NewSheetfieldObj = new webforms_sheetfield(); var SheetFieldDefObj = SheetFieldDefResult.ElementAt(i); NewSheetfieldObj.FieldName = SheetFieldDefObj.FieldName; NewSheetfieldObj.FieldType = SheetFieldDefObj.FieldType; NewSheetfieldObj.FontIsBold = SheetFieldDefObj.FontIsBold; NewSheetfieldObj.FontName = SheetFieldDefObj.FontName; NewSheetfieldObj.FontSize = SheetFieldDefObj.FontSize; NewSheetfieldObj.Height = SheetFieldDefObj.Height; NewSheetfieldObj.Width = SheetFieldDefObj.Width; NewSheetfieldObj.XPos = SheetFieldDefObj.XPos; NewSheetfieldObj.YPos = SheetFieldDefObj.YPos; NewSheetfieldObj.IsRequired = SheetFieldDefObj.IsRequired; NewSheetfieldObj.RadioButtonGroup = SheetFieldDefObj.RadioButtonGroup; NewSheetfieldObj.RadioButtonValue = SheetFieldDefObj.RadioButtonValue; NewSheetfieldObj.GrowthBehavior = SheetFieldDefObj.GrowthBehavior; NewSheetfieldObj.TabOrder = SheetFieldDefObj.TabOrder; NewSheetfieldObj.FieldValue = SheetFieldDefObj.FieldValue; long WebSheetFieldDefID = SheetFieldDefObj.WebSheetFieldDefID; if (FormValuesHashTable.ContainsKey(WebSheetFieldDefID + "")) { NewSheetfieldObj.FieldValue = FormValuesHashTable[WebSheetFieldDefID + ""].ToString(); } #region saving dates in right formats string FieldValue = NewSheetfieldObj.FieldValue; string FieldName = NewSheetfieldObj.FieldName; string CultureName = db.webforms_preference.Where(pref => pref.DentalOfficeID == DentalOfficeID).First().CultureName; // culture of the opendental installation if (String.IsNullOrEmpty(CultureName)) { CultureName = "en-US"; } if (FieldValue.Contains("[dateToday]")) { FieldValue = FieldValue.Replace("[dateToday]", ExtractBrowserDate().ToString("d", new CultureInfo(CultureName, false))); Logger.Information("FieldName=" + FieldName + " FieldValue=" + FieldValue); NewSheetfieldObj.FieldValue = FieldValue; } if (FieldName.ToLower() == "birthdate" || FieldName.ToLower() == "bdate") { Logger.Information("FieldName=" + FieldName + " FieldValue=" + FieldValue); DateTime birthdate = DateTime.Parse(FieldValue, System.Threading.Thread.CurrentThread.CurrentCulture); //use the browsers culture to get correct date. FieldValue = birthdate.ToString("d", new CultureInfo(CultureName, false)); //now convert the birthdate into a string using the culture of the corresponding opendental installation. NewSheetfieldObj.FieldValue = FieldValue; } #endregion NewSheetObj.webforms_sheetfield.Add(NewSheetfieldObj); } var PrefObj = db.webforms_preference.Where(wp => wp.DentalOfficeID == DentalOfficeID); if (PrefObj.Count() > 0) { PrefObj.First().webforms_sheet.Add(NewSheetObj); db.SaveChanges(); DisplayMessage("Your details have been successfully submitted"); Logger.Information("Form values saved from IpAddress=" + HttpContext.Current.Request.UserHostAddress + " DentalOfficeID=" + DentalOfficeID); } } catch (Exception ex) { Logger.LogError("IpAddress=" + HttpContext.Current.Request.UserHostAddress + " DentalOfficeID=" + DentalOfficeID + " WebSheetDefID=" + WebSheetDefID, ex); Panel1.Visible = false; DisplayMessage("There has been a problem submitting your details. <br /> We apologize for the inconvenience."); } }