public string UpdateMySQL() { try { using (MySQLBase.MySQL_Model db = new MySQLBase.MySQL_Model()) { string sFilePath = @"C:\Users\Pratik\Desktop\MySQL.txt"; System.IO.StreamReader or = new System.IO.StreamReader(sFilePath); do { qtype = or.ReadLine(); if (qtype == "Insert") { var p1 = new MySQLBase.patient { patientNo = Convert.ToInt32(or.ReadLine()), PatientName = or.ReadLine(), age = Convert.ToInt32(or.ReadLine()), sex = or.ReadLine(), address = or.ReadLine(), regDate = Convert.ToDateTime(or.ReadLine()).Date, disDate = Convert.ToDateTime(or.ReadLine()).Date, remarks = or.ReadLine(), empID = Convert.ToInt32(or.ReadLine()) }; db.patients.Add(p1); db.SaveChanges(); } else if (qtype == "Update") { var original = db.patients.Find(Convert.ToInt32(or.ReadLine())); if (original != null) { original.patientNo = Convert.ToInt32(or.ReadLine()); original.PatientName = or.ReadLine(); original.age = Convert.ToInt32(or.ReadLine()); original.address = or.ReadLine(); original.sex = or.ReadLine(); original.regDate = Convert.ToDateTime(or.ReadLine()).Date; original.disDate = Convert.ToDateTime(or.ReadLine()).Date; original.remarks = or.ReadLine(); } db.SaveChanges(); } } while (qtype != null); or.Close(); } return "done"; } catch (System.Data.Entity.Infrastructure.DbUpdateException ex) { return "notdone " + ex.Message; } }
public string InsertNewPatients(Class_Patient pa) { checkDB(); try { if (mysql == true) { using (MySQLBase.MySQL_Model db = new MySQLBase.MySQL_Model()) { var p = new MySQLBase.patient { patientNo = pa.patientNo, PatientName = pa.patientName, age = pa.Page, sex = pa.Psex, address = pa.Paddress, regDate = pa.PregDate.Date, disDate = pa.PdisDate.Date, remarks = pa.Premarks, empID = pa.PempID, }; db.patients.Add(p); db.SaveChanges(); } } else { string sFilePath1 = @"C:\Users\Pratik\Desktop\MySQL.txt"; string sDateTime = GetLogFor(pa); sDateTime.Remove((sDateTime.Length - 2), 1); System.IO.StreamWriter oFileWriter = new System.IO.StreamWriter(sFilePath1, true); oFileWriter.WriteLine("Insert"); oFileWriter.WriteLine(sDateTime); oFileWriter.Close(); } if (sql2008 == true) { using (SQL2008.hospitalEntities db = new SQL2008.hospitalEntities()) { var p = new SQL2008.DBpatient { patientNo = pa.patientNo, PatientName = pa.patientName, age = pa.Page, sex = pa.Psex, address = pa.Paddress, regDate = pa.PregDate, disDate = pa.PdisDate, remarks = pa.Premarks, empID = pa.PempID, }; db.DBpatients.Add(p); db.SaveChanges(); } } else { string sFilePath1 = @"C:\Users\Pratik\Desktop\SQL2008.txt"; string sDateTime = GetLogFor(pa); sDateTime.Remove((sDateTime.Length - 2), 1); System.IO.StreamWriter oFileWriter = new System.IO.StreamWriter(sFilePath1, true); oFileWriter.WriteLine("Insert"); oFileWriter.WriteLine(sDateTime); oFileWriter.Close(); } } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { return "Property: " + validationError.PropertyName + "Error: " + validationError.ErrorMessage; } } } catch (Exception ex) { return "not done" + ex.Message; } return "hell"; }