public static void updateRepresentative(RepresentativeInfo info, List<string[]> emails, List<string[]> numbers, List<string[]> addresses, List<string[]> othercontacts) { DataSet ds = new DataSet(); MySqlDataReader reader = getRepresentative(info.RepresentativeId); string[] tbl = new string[6]; ds.Load(reader, LoadOption.OverwriteChanges, tbl); reader.Close(); reader.Dispose(); string sql = "update representatives set title=?title, firstname=?firstname, lastname=?lastname, positionTitle=?positionTitle, username=?username where representativeid=?representativeid"; DAO.ExecuteNonQuery(sql, new MySqlParameter("title", info.Title), new MySqlParameter("firstname", info.FirstName), new MySqlParameter("lastname", info.LastName), new MySqlParameter("positionTitle", info.PositionTitle), new MySqlParameter("username", info.UserName), new MySqlParameter("representativeid", info.RepresentativeId)); HistoryInfo historyInfo = new HistoryInfo(); HistoryDataProvider history = new HistoryDataProvider(); historyInfo.UserId = GPSession.UserId; historyInfo.ModuleId = (int)HistoryInfo.Module.Representaive; historyInfo.TypeId = (int)HistoryInfo.ActionType.Edit; historyInfo.RecordId = Convert.ToUInt32(info.RepresentativeId); historyInfo.ParentRecordId = Convert.ToUInt32(info.RepresentativeId); historyInfo.ModifiedDate = DateTime.Now; historyInfo.Details = new List<HistoryDetailInfo>(); if (ds.Tables[0].Rows[0]["title"].ToString() != info.Title) { historyInfo.Details.Add(new HistoryDetailInfo { ColumnName = "title", OldValue = ds.Tables[0].Rows[0]["title"].ToString(), NewValue = info.Title }); } if (ds.Tables[0].Rows[0]["firstname"].ToString() != info.FirstName) { historyInfo.Details.Add(new HistoryDetailInfo { ColumnName = "firstname", OldValue = ds.Tables[0].Rows[0]["firstname"].ToString(), NewValue = info.FirstName }); } if (ds.Tables[0].Rows[0]["lastname"].ToString() != info.LastName) { historyInfo.Details.Add(new HistoryDetailInfo { ColumnName = "lastname", OldValue = ds.Tables[0].Rows[0]["lastname"].ToString(), NewValue = info.LastName }); } if (ds.Tables[0].Rows[0]["positionTitle"].ToString() != info.PositionTitle) { historyInfo.Details.Add(new HistoryDetailInfo { ColumnName = "positionTitle", OldValue = ds.Tables[0].Rows[0]["positionTitle"].ToString(), NewValue = info.PositionTitle }); } if (ds.Tables[0].Rows[0]["username"].ToString() != info.UserName) { historyInfo.Details.Add(new HistoryDetailInfo { ColumnName = "username", OldValue = ds.Tables[0].Rows[0]["username"].ToString(), NewValue = info.UserName }); } if (historyInfo.Details.Count > 0) { history.insertHistory(historyInfo); } //emails foreach (string[] email in emails) { uint emailid = Convert.ToUInt32(email[0]); string address = email[1]; uint emailtypeid = Convert.ToUInt32(email[2]); bool defaultemail = Convert.ToBoolean(email[3]); updateEmail(info.RepresentativeId, emailid, address, emailtypeid, defaultemail); DataRow[] drSeq = ds.Tables[1].Select("emailid=" + emailid); if (drSeq.Length > 0) { historyInfo = new HistoryInfo(); historyInfo.UserId = GPSession.UserId; historyInfo.ModuleId = (int)HistoryInfo.Module.representatives_emails; historyInfo.TypeId = (int)HistoryInfo.ActionType.Edit; historyInfo.RecordId = emailid; historyInfo.ParentRecordId = Convert.ToUInt32(info.RepresentativeId); historyInfo.ModifiedDate = DateTime.Now; historyInfo.Details = new List<HistoryDetailInfo>(); if (drSeq[0]["email"].ToString() != address) { historyInfo.Details.Add(new HistoryDetailInfo { ColumnName = "email", OldValue = drSeq[0]["email"].ToString(), NewValue = address }); } if (drSeq[0]["emailtypeid"].ToString() != emailtypeid.ToString()) { historyInfo.Details.Add(new HistoryDetailInfo { ColumnName = "emailtypeid", OldValue = drSeq[0]["emailtypeid"].ToString(), NewValue = emailtypeid.ToString() }); } if (Convert.ToBoolean(drSeq[0]["defaultemail"]) != defaultemail) { historyInfo.Details.Add(new HistoryDetailInfo { ColumnName = "defaultemail", OldValue = drSeq[0]["defaultemail"].ToString(), NewValue = defaultemail.ToString() }); } if (historyInfo.Details.Count > 0) { history.insertHistory(historyInfo); } } } //numbers foreach (string[] number in numbers) { string countrycode = number[0]; uint phonenumberid = Convert.ToUInt32(number[1]); string phonenumber = number[2]; uint phonenumbertypeid = Convert.ToUInt32(number[3]); updatePhoneNumber(Convert.ToUInt32(info.RepresentativeId), phonenumberid, phonenumber, phonenumbertypeid, countrycode); DataRow[] drSeq = ds.Tables[2].Select("phonenumberid=" + phonenumberid); if (drSeq.Length > 0) { historyInfo = new HistoryInfo(); historyInfo.UserId = GPSession.UserId; historyInfo.ModuleId = (int)HistoryInfo.Module.representatives_phonenumbers; historyInfo.TypeId = (int)HistoryInfo.ActionType.Edit; historyInfo.RecordId = phonenumberid; historyInfo.ParentRecordId = Convert.ToUInt32(info.RepresentativeId); historyInfo.ModifiedDate = DateTime.Now; historyInfo.Details = new List<HistoryDetailInfo>(); if (drSeq[0]["number"].ToString() != phonenumber) { historyInfo.Details.Add(new HistoryDetailInfo { ColumnName = "number", OldValue = drSeq[0]["number"].ToString(), NewValue = phonenumber }); } if (drSeq[0]["phonenumbertypeid"].ToString() != phonenumbertypeid.ToString()) { historyInfo.Details.Add(new HistoryDetailInfo { ColumnName = "phonenumbertypeid", OldValue = drSeq[0]["phonenumbertypeid"].ToString(), NewValue = phonenumbertypeid.ToString() }); } if (drSeq[0]["countrycode"].ToString() != countrycode.ToString()) { historyInfo.Details.Add(new HistoryDetailInfo { ColumnName = "countrycode", OldValue = drSeq[0]["countrycode"].ToString(), NewValue = countrycode.ToString() }); } if (historyInfo.Details.Count > 0) { history.insertHistory(historyInfo); } } } //addresses foreach (string[] address in addresses) { uint addressid = Convert.ToUInt32(address[0]); uint addresstypeid = Convert.ToUInt32(address[1]); updateAddressType(Convert.ToUInt32(info.RepresentativeId), addressid, addresstypeid); DataRow[] drSeq = ds.Tables[3].Select("addressid=" + addressid); historyInfo = new HistoryInfo(); historyInfo.UserId = GPSession.UserId; historyInfo.ModuleId = (int)HistoryInfo.Module.representatives_address; historyInfo.TypeId = (int)HistoryInfo.ActionType.Edit; historyInfo.RecordId = addressid; historyInfo.ParentRecordId = Convert.ToUInt32(info.RepresentativeId); historyInfo.ModifiedDate = DateTime.Now; historyInfo.Details = new List<HistoryDetailInfo>(); if (drSeq[0]["addresstypeid"].ToString() != addresstypeid.ToString()) { historyInfo.Details.Add(new HistoryDetailInfo { ColumnName = "addresstypeid", NewValue = addresstypeid.ToString(), OldValue = drSeq[0]["addresstypeid"].ToString() }); } if (historyInfo.Details.Count > 0) { history.insertHistory(historyInfo); } } //othercontacts foreach (string[] othercontact in othercontacts) { uint othercontactid = Convert.ToUInt32(othercontact[0]); uint altertativecontactid = Convert.ToUInt32(othercontact[1]); string details = othercontact[2]; updateOtherContact(othercontactid, details, altertativecontactid); DataRow[] drSeq = ds.Tables[4].Select("representativeothercontactid=" + othercontactid); if (drSeq.Length > 0) { historyInfo = new HistoryInfo(); historyInfo.UserId = GPSession.UserId; historyInfo.ModuleId = (int)HistoryInfo.Module.representatives_othercontacts; historyInfo.TypeId = (int)HistoryInfo.ActionType.Edit; historyInfo.RecordId = othercontactid; historyInfo.ParentRecordId = Convert.ToUInt32(info.RepresentativeId); historyInfo.ModifiedDate = DateTime.Now; historyInfo.Details = new List<HistoryDetailInfo>(); if (drSeq[0]["alternativecontactid"].ToString() != altertativecontactid.ToString()) { historyInfo.Details.Add(new HistoryDetailInfo { ColumnName = "alternativecontactid", OldValue = drSeq[0]["alternativecontactid"].ToString(), NewValue = altertativecontactid.ToString() }); } if (drSeq[0]["details"].ToString() != details) { historyInfo.Details.Add(new HistoryDetailInfo { ColumnName = "details", OldValue = drSeq[0]["details"].ToString(), NewValue = details }); } if (historyInfo.Details.Count > 0) { history.insertHistory(historyInfo); } } } }
public static uint insertRepresentative(RepresentativeInfo info) { string sql = "insert into representatives (title, firstname, lastname, positionTitle, username, createdDate) values (?title, ?firstname, ?lastname, ?positionTitle, ?username, ?createdDate); select last_insert_id()"; uint representativeId = Convert.ToUInt32(DAO.ExecuteScalar(sql, new MySqlParameter("title", info.Title), new MySqlParameter("firstname", info.FirstName), new MySqlParameter("lastname", info.LastName), new MySqlParameter("positionTitle", info.PositionTitle), new MySqlParameter("username", info.UserName), new MySqlParameter("createdDate", info.CreatedDate))); HistoryDataProvider history = new HistoryDataProvider(); HistoryInfo historyInfo = new HistoryInfo(); historyInfo.UserId = GPSession.UserId; historyInfo.ModuleId = (int)HistoryInfo.Module.Representaive; historyInfo.TypeId = (int)HistoryInfo.ActionType.Add; historyInfo.RecordId = representativeId; historyInfo.ParentRecordId = representativeId; historyInfo.ModifiedDate = DateTime.Now; historyInfo.Details = new List<HistoryDetailInfo>(); historyInfo.Details.Add(new HistoryDetailInfo { ColumnName = "All", NewValue = "title:" + info.Title + " ,first:" + info.FirstName + " ,last:" + info.LastName + " ,positiontitle:" + info.PositionTitle + " ,username:" + info.UserName }); history.insertHistory(historyInfo); return representativeId; }