protected void DeleteCheck(ref DataTable campus, ref DataTable Vkd, BaseCore campusBaseCore) { var employeesId = campus.AsEnumerable().Select(o => new { EmpId = o["ID_employee"], SubId = o["ID_Subdivision"] }).Distinct(); foreach (var ident in employeesId) { var empl = Vkd.AsEnumerable().Where(p => p["ID_employee"].ToString() == ident.EmpId.ToString() && p["ID_Subdivision"].ToString() == ident.SubId.ToString()) .Select(u => u["Surname"]).ToList(); if (!empl.Any()) { var employees = campus.Select("ID_employee=" + ident.EmpId.ToString()); foreach (var row in employees) { if (row["vcChangeStatus"].ToString() != "Видалено") { row["vcChangeStatus"] = "Видалено"; row["vcChangeDate"] = DateTime.Now; NLogCore.LogStatusAplication("Запис з ідентифікатором eEmployees1Id=" + row["eEmployees1Id"] + " видалено"); } } campusBaseCore.UpdateDataBase(campus); } } }
private void RowUpdate(DataRow oldRow, DataRow newRow) { List <string> columns = new List <string>(); List <string> newVals = new List <string>(); bool flag = false; foreach (var columname in CountNameColumn.NameColumn) { flag |= CellUpdate(ref oldRow, newRow, ref columns, ref newVals, columname); } if (flag) { oldRow["UserAccountId"] = GetUserAccountID(newRow); oldRow["vcChangeDate"] = DateTime.Now; oldRow["vcChangeStatus"] = "Оновлено"; for (int i = 0; i < newVals.Count; i++) { NLogCore.LogStatusAplication("Запис з ідентифікатором eEmployees1Id=" + oldRow["eEmployees1Id"].ToString() + " змінено: значення поля " + columns[i].ToString() + " замінено на " + newVals[i].ToString()); } } }
public void UpdateDataBase(DataTable t) { SqlCommandBuilder commandBuilder = new SqlCommandBuilder(baseCon1); NLogCore.LogStatusAplication("!----------------------!"); NLogCore.LogStatusAplication("Start updating database"); NLogCore.LogStatusAplication("!----------------------!"); baseCon1.Update(t); NLogCore.LogStatusAplication("!----------------------!"); NLogCore.LogStatusAplication("End updating database"); NLogCore.LogStatusAplication("!----------------------!"); }
public static bool TestConnection(string t) { try { using (var test = new SqlConnection(t)) { test.Open(); test.Close(); } } catch (SqlException ex) { NLogCore.LogAplicationError(ex.Message); return(false); } return(true); }
protected void DataCheck(ref DataTable campus, ref DataTable Vkd) { int _maximum = campus.Rows.Count == 0 ? 1 : campus.Rows.Cast <DataRow>().Select(p => Convert.ToInt32(p["eEmployees1Id"])).Max() + 1; bool check = false; var EmployeeIdlist = Vkd.AsEnumerable().Select(y => new { EmpId = y["ID_employee"], SubId = y["ID_Subdivision"] }).Distinct().ToList(); var vkdRows = Vkd.Rows.Cast <DataRow>().ToList(); var campusRows = campus.Rows.Cast <DataRow>().ToList(); for (int rowNumber = 0; rowNumber < EmployeeIdlist.Count; rowNumber++) { var row = EmployeeIdlist[rowNumber]; NLogCore.LogStatusAplication(String.Format("DataCheck : {0} of {1}", rowNumber, EmployeeIdlist.Count)); var gottenEmployes = vkdRows.Where(o => o["ID_employee"].ToString() == row.EmpId.ToString() && o["ID_Subdivision"].ToString() == row.SubId.ToString()) .OrderBy(e => e["RowNumber"].ToString()) .ToList(); var existingEmployes = campusRows.Where(t => t["ID_employee"].ToString() == row.EmpId.ToString() && t["ID_Subdivision"].ToString() == row.SubId.ToString()) // && t["vcChangeStatus"].ToString() != "Видалено") .OrderBy(e => e["eEmployees1Id"].ToString()) .ToList(); if (gottenEmployes.Count == existingEmployes.Count) { var indexis = gottenEmployes.Count; for (int i = 0; i < indexis; i++) { if (check) { i = 0; check = false; } if (existingEmployes[i]["ID_Duties"].ToString() == gottenEmployes[i]["ID_Duties"].ToString() && existingEmployes[i]["ID_Group"].ToString() == gottenEmployes[i]["ID_Group"].ToString() && existingEmployes[i]["IDEmploymentForm"].ToString() == gottenEmployes[i]["IDEmploymentForm"].ToString()) { RowUpdate(existingEmployes[i], gottenEmployes[i]); existingEmployes.RemoveAt(i); gottenEmployes.RemoveAt(i); indexis -= 1; check = true; } else { var getSameEmployee = existingEmployes.Find(t => t["ID_Duties"].ToString() == gottenEmployes[i]["ID_Duties"].ToString() && t["ID_Group"].ToString() == gottenEmployes[i]["ID_Group"].ToString() && t["IDEmploymentForm"].ToString() == gottenEmployes[i]["IDEmploymentForm"].ToString()); if (getSameEmployee != null) { var getSameEmployeeIndex = existingEmployes.FindIndex(t => t["ID_Duties"].ToString() == gottenEmployes[i]["ID_Duties"].ToString() && t["ID_Group"].ToString() == gottenEmployes[i]["ID_Group"].ToString() && t["IDEmploymentForm"].ToString() == gottenEmployes[i]["IDEmploymentForm"].ToString()); RowUpdate(existingEmployes[getSameEmployeeIndex], gottenEmployes[i]); existingEmployes.RemoveAt(getSameEmployeeIndex); gottenEmployes.RemoveAt(i); indexis -= 1; check = true; } } } if (gottenEmployes.Count != 0) { for (int i = 0; i < gottenEmployes.Count; i++) { RowUpdate(existingEmployes[i], gottenEmployes[i]); } } } if (gottenEmployes.Count > existingEmployes.Count) { int index = gottenEmployes.Count; for (int i = 0; i < index; i++) { if (check) { i = 0; check = false; } var getSameEmployee = existingEmployes.Find(t => t["ID_Duties"].ToString() == gottenEmployes[i]["ID_Duties"].ToString() && t["ID_Group"].ToString() == gottenEmployes[i]["ID_Group"].ToString() && t["IDEmploymentForm"].ToString() == gottenEmployes[i]["IDEmploymentForm"].ToString()); if (getSameEmployee != null) { var getSameEmployeeIndex = existingEmployes.FindIndex(t => t["ID_Duties"].ToString() == gottenEmployes[i]["ID_Duties"].ToString() && t["ID_Group"].ToString() == gottenEmployes[i]["ID_Group"].ToString() && t["IDEmploymentForm"].ToString() == gottenEmployes[i]["IDEmploymentForm"].ToString()); RowUpdate(existingEmployes[getSameEmployeeIndex], gottenEmployes[i]); existingEmployes.RemoveAt(getSameEmployeeIndex); gottenEmployes.RemoveAt(i); index -= 1; check = true; } } if (gottenEmployes.Count() != 0) { for (int i = 0; i < gottenEmployes.Count(); i++) { if (i + 1 < gottenEmployes.Count) { RowUpdate(existingEmployes[i], gottenEmployes[i]); } else { var sourceRow = gottenEmployes[i]; var newRow = campus.NewRow(); CloneRow(sourceRow, _maximum, ref newRow); campus.Rows.Add(newRow); NLogCore.LogStatusAplication( "Додано запис з ідентифікатором eEmployees1Id=" + _maximum.ToString()); _maximum = _maximum + 1; } } } } if (gottenEmployes.Count < existingEmployes.Count) { int index1 = existingEmployes.Count; int index2 = gottenEmployes.Count; //for (int i = 0; i < index1; i++) //{ // for (int j = 0; j < index2; j++) // { // if (check) // { // i = 0; j = 0; check = false; // } // if (existingEmployes[i]["ID_Subdivision"].ToString() == gottenEmployes[j]["ID_Subdivision"].ToString()) // { // RowUpdate(existingEmployes[i], gottenEmployes[j]); // existingEmployes.RemoveAt(i); // gottenEmployes.RemoveAt(j); // index1 = index1 - 1; // index2 = index2 - 1; // check = true; // } // } //} for (int i = 0; i < index1; i++) { for (int j = 0; j < index2; j++) { if (check) { j = 0; i = 0; check = false; } // int index2 = 0; // foreach (var gotEmployee in gottenEmployes.ToList()) // { if (existingEmployes[i]["ID_Duties"].ToString() == gottenEmployes[j]["ID_Duties"].ToString() && existingEmployes[i]["ID_Group"].ToString() == gottenEmployes[j]["ID_Group"].ToString() && existingEmployes[i]["IDEmploymentForm"].ToString() == gottenEmployes[j]["IDEmploymentForm"].ToString()) { //var getthis = existingEmployes.Find(r => // r["ID_Duties"].ToString() == gottenEmployes[i]["ID_Duties"].ToString() && // r["ID_Group"].ToString() == gottenEmployes[i]["ID_Group"].ToString() && // r["IDEmploymentForm"].ToString() == gottenEmployes[i]["IDEmploymentForm"].ToString()); //// var //var index = existingEmployes.FindIndex(r => // r["ID_Duties"].ToString() == gottenEmployes[i]["ID_Duties"].ToString() && // r["ID_Group"].ToString() == gottenEmployes[i]["ID_Group"].ToString() && // r["IDEmploymentForm"].ToString() == gottenEmployes[i]["IDEmploymentForm"].ToString()); RowUpdate(existingEmployes[i], gottenEmployes[j]); existingEmployes.RemoveAt(i); gottenEmployes.RemoveAt(j); index1 -= 1; index2 -= 1; check = true; } // index2++; } } if (existingEmployes.Count != 0) { for (int i = 0; i < existingEmployes.Count; i++) { if (existingEmployes[i]["vcChangeStatus"].ToString() != "Видалено") { existingEmployes[i]["vcChangeStatus"] = "Видалено"; existingEmployes[i]["vcChangeDate"] = DateTime.Now; NLogCore.LogStatusAplication("Запис з ідентифікатором eEmployees1Id=" + existingEmployes[i]["eEmployees1Id"].ToString() + " видалено"); } } } if (gottenEmployes.Count != 0) { for (int i = 0; i < gottenEmployes.Count; i++) { var sourceRow = gottenEmployes[i]; var newRow = campus.NewRow(); CloneRow(sourceRow, _maximum, ref newRow); campus.Rows.Add(newRow); NLogCore.LogStatusAplication("Додано запис з ідентифікатором eEmployees1Id=" + _maximum.ToString()); _maximum = _maximum + 1; } } } } }