public void AcceptChanges() { Records.RemoveRecords(); //optimize record uploads List <IQRecord> addList = Records.Where(record => record.RecordState == RecordState.New && record.UncleanState == false).ToList(); List <IQRecord> modList = Records.Where(record => record.RecordState == RecordState.Modified && record.UncleanState == false).ToList(); List <IQRecord> uncleanList = Records.Where(record => record.UncleanState).ToList(); int acnt = addList.Count; int mcnt = modList.Count; bool hasFileColumn = Columns.Any(c => c.ColumnType == FieldType.file); if (!hasFileColumn && (acnt + mcnt > 0)) // if no file-type columns involved, use csv upload method for reducing API calls and speeding processing. { List <String> csvLines = new List <string>(acnt + mcnt); String clist = String.Join(".", KeyFID == -1 ? Columns.Where(col => (col.ColumnVirtual == false && col.ColumnLookup == false) || col.ColumnType == FieldType.recordid).Select(col => col.ColumnId.ToString()) : Columns.Where(col => (col.ColumnVirtual == false && col.ColumnLookup == false) || col.ColumnId == KeyFID).Select(col => col.ColumnId.ToString())); if (acnt > 0) { csvLines.AddRange(addList.Select(record => record.GetAsCSV(clist))); } if (mcnt > 0) { csvLines.AddRange(modList.Select(record => record.GetAsCSV(clist))); } var csvBuilder = new ImportFromCSV.Builder(Application.Client.Ticket, Application.Token, Application.Client.AccountDomain, TableId, String.Join("\r\n", csvLines.ToArray())); csvBuilder.SetCList(clist); csvBuilder.SetTimeInUtc(true); var csvUpload = csvBuilder.Build(); var xml = csvUpload.Post().CreateNavigator(); XPathNodeIterator xNodes = xml.Select("/qdbapi/rids/rid"); //set records as in server now foreach (IQRecord rec in addList) { xNodes.MoveNext(); ((IQRecord_int)rec).ForceUpdateState(Int32.Parse(xNodes.Current.Value)); //set in-memory recordid to new server value } foreach (IQRecord rec in modList) { ((IQRecord_int)rec).ForceUpdateState(); } } else { foreach (IQRecord rec in addList) { rec.AcceptChanges(); } foreach (IQRecord rec in modList) { rec.AcceptChanges(); } } foreach (IQRecord rec in uncleanList) { rec.AcceptChanges(); } }
//---------------------------------------------------- public bool ImportFromCSV(string db, string csv, string cList) { try { ImportFromCSV.Builder builder = new ImportFromCSV.Builder(__ticket, __token, __domain, db, csv); builder.SetCList(cList); var response = builder.Build().Post().CreateNavigator(); var errcode = response.SelectSingleNode("/qdbapi/errcode").ToString(); if (errcode == "0") { return(true); } else { message = "Error " + response.SelectSingleNode("/qdbapi/errcode").ToString() + ": " + response.SelectSingleNode("/qdbapi/errtext").ToString(); } } catch (Exception e) { message = e.Message; } return(false); }