Last active
August 29, 2015 14:15
-
-
Save klondaiker/f90dd013ea9d2b2aa7ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Dictionary<string, object> SaveReviz(Dictionary<string, object> value) | |
{ | |
var rlc = (RevizListController) Controller(Code); | |
RevizUpdController ruc = rlc.UpdController; | |
var result = new Dictionary<string, object> {{"result", false}}; | |
try | |
{ | |
/* | |
+ [1] {LINK_SELF} object {System.Data.DataColumn} | |
+ [4] {PLANREVIZ} object {System.Data.DataColumn} | |
+ [7] {STATUS} object {System.Data.DataColumn} | |
+ [12] {STAMP} object {System.Data.DataColumn} | |
+ [16] {USERS} object {System.Data.DataColumn} | |
*/ | |
// при любой ситуации убираем кэш, лучше заново получить его! | |
int link = int.Parse(value["link"].ToString()); | |
string key = string.Format("{0}_{1}", "RevizEdit", link); | |
if (Cache.Contains(key)) Cache.Remove(key); | |
if ((link == 0) && (value["sameLink"].ToString() != "0") | |
? ruc.AddSame(Convert.ToInt32(value["sameLink"].ToString())) | |
: ruc.AddOrEdit(link)) | |
{ | |
DataSet ds = ruc.Row.Table.DataSet; | |
var delRows = new List<DataRow>(); | |
ruc.Row["S_PERSON_CLOSED"] = value["closePerson"].ToString() == "0" | |
? (object) DBNull.Value | |
: Convert.ToInt32(value["closePerson"].ToString()); | |
#region Общие | |
ruc.Row["NUMBER"] = value["NUMBER"]; | |
ruc.Row["DT"] = DateTimeParse(value["DT"].ToString()); | |
ruc.Row["EXTOSNOV"] = value["EXTOSNOV"]; | |
ruc.Row["DT1"] = DateTimeParse(value["DT1"].ToString()); | |
ruc.Row["DT2"] = DateTimeParse(value["DT2"].ToString()); | |
ruc.Row["DTMONEY1"] = DateTimeParse(value["DTMONEY1"].ToString()); | |
ruc.Row["DTMONEY2"] = DateTimeParse(value["DTMONEY2"].ToString()); | |
ruc.Row["S_WORK"] = value["S_WORK"]; | |
ruc.Row["S_ROSNOV"] = value["S_ROSNOV"]; | |
var bindTRevizObjects = new Dictionary<string, object>(); | |
var tRevizObjects = | |
JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(value["T_REVIZ_OBJECTS"].ToString()); | |
foreach (DataRow row in ds.Tables["T_REVIZ_OBJECTS"].Rows) | |
{ | |
bool flag = true; | |
for (int j = tRevizObjects.Count - 1; j >= 0; j--) | |
{ | |
Dictionary<string, object> dict = tRevizObjects[j]; | |
if ((int) (long) dict["LINK"] == (int) row["LINK"]) | |
{ | |
tRevizObjects.RemoveAt(j); | |
flag = false; | |
break; | |
} | |
} | |
if (flag) | |
{ | |
delRows.Add(row); | |
} | |
} | |
foreach (Dictionary<string, object> dict in tRevizObjects) | |
{ | |
DataRow row = ds.Tables["T_REVIZ_OBJECTS"].NewRow(); | |
bindTRevizObjects[dict["LINK"].ToString()] = row["LINK"]; | |
row["LINK_SELF"] = dict["LINK_SELF"] == null | |
? DBNull.Value | |
: bindTRevizObjects.ContainsKey(dict["LINK_SELF"].ToString()) | |
? bindTRevizObjects[dict["LINK_SELF"].ToString()] | |
: dict["LINK_SELF"]; | |
row["REVIZ"] = ruc.Row["LINK"]; | |
row["TTABLE"] = dict["TTABLE"]; | |
row["TLINK"] = dict["TLINK"]; | |
row["TYPE"] = dict["TYPE"]; | |
row["MAIN"] = !dict.ContainsKey("MAIN") || dict["MAIN"].IsNullOrDBNullOrEmpty() ? false : dict["MAIN"]; | |
row["TEMP_INN"] = !dict.ContainsKey("TEMP_INN") || dict["TEMP_INN"] == null ? DBNull.Value : dict["TEMP_INN"]; | |
row["TEMP_CODE"] = !dict.ContainsKey("TEMP_CODE") || dict["TEMP_CODE"] == null ? DBNull.Value : dict["TEMP_CODE"]; | |
row["TEMP_NAME"] = !dict.ContainsKey("TEMP_NAME") || dict["TEMP_NAME"] == null | |
? DBNull.Value | |
: dict["TEMP_NAME"]; | |
row["TEMP_SNAME"] = !dict.ContainsKey("TEMP_SNAME") || dict["TEMP_SNAME"] == null | |
? DBNull.Value | |
: dict["TEMP_SNAME"]; | |
ds.Tables["T_REVIZ_OBJECTS"].Rows.Add(row); | |
} | |
var bindTRevizAudit = new Dictionary<string, object>(); | |
var tRevizAudit = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(value["T_REVIZ_AUDIT"].ToString()); | |
foreach (DataRow row in ds.Tables["T_REVIZ_AUDIT"].Rows) | |
{ | |
bool flag = true; | |
for (int j = tRevizAudit.Count - 1; j >= 0; j--) | |
{ | |
Dictionary<string, object> dict = tRevizAudit[j]; | |
if ((int) (long) dict["LINK"] == (int) row["LINK"]) | |
{ | |
object tro = bindTRevizObjects.ContainsKey(dict["T_REVIZ_OBJECTS"].ToString()) | |
? bindTRevizObjects[dict["T_REVIZ_OBJECTS"].ToString()] | |
: dict["T_REVIZ_OBJECTS"]; | |
if (row["T_REVIZ_OBJECTS"] != tro) row["T_REVIZ_OBJECTS"] = tro; | |
tRevizAudit.RemoveAt(j); | |
flag = false; | |
break; | |
} | |
} | |
if (flag) | |
{ | |
delRows.Add(row); | |
} | |
} | |
foreach (Dictionary<string, object> dict in tRevizAudit) | |
{ | |
DataRow row = ds.Tables["T_REVIZ_AUDIT"].NewRow(); | |
bindTRevizAudit[dict["LINK"].ToString()] = row["LINK"]; | |
row["S_ORG"] = dict["S_ORG"]; | |
row["T_REVIZ_OBJECTS"] = bindTRevizObjects.ContainsKey(dict["T_REVIZ_OBJECTS"].ToString()) | |
? bindTRevizObjects[dict["T_REVIZ_OBJECTS"].ToString()] | |
: dict["T_REVIZ_OBJECTS"]; | |
row["REVIZ"] = ruc.Row["LINK"]; | |
ds.Tables["T_REVIZ_AUDIT"].Rows.Add(row); | |
} | |
#region S_PERSON | |
var bindPerson = new Dictionary<string, object>(); | |
if (value.ContainsKey("S_PERSON")) | |
{ | |
var sPerson = JsonConvert.DeserializeObject<List<Dictionary<string, int>>>(value["S_PERSON"].ToString()); | |
var sPersonPart = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(value["S_PERSONPART"].ToString()); | |
for (int i = ds.Tables["PERSON_PART"].Rows.Count - 1; i >= 0; i--) | |
{ | |
ds.Tables["PERSON_PART"].Rows[i].Delete(); | |
} | |
foreach (DataRow row in ds.Tables["T_REVIZ_SPERSON"].Rows) | |
{ | |
bool flag = true; | |
for (int j = sPerson.Count - 1; j >= 0; j--) | |
{ | |
Dictionary<string, int> dict = sPerson[j]; | |
if (dict["LINK"] == (int) row["LINK"]) | |
{ | |
SetRevizSPersonRow(row, dict, sPersonPart, ds.Tables["PERSON_PART"], bindPerson); | |
sPerson.RemoveAt(j); | |
flag = false; | |
break; | |
} | |
} | |
if (flag) | |
{ | |
delRows.Add(row); | |
//row.Delete(); | |
} | |
} | |
foreach (Dictionary<string, int> dict in sPerson) | |
{ | |
DataRow row = ds.Tables["T_REVIZ_SPERSON"].NewRow(); | |
row["REVIZ"] = ruc.Row["LINK"]; | |
row["S_PERSON"] = dict["S_PERSON"]; | |
bindPerson[dict["LINK"].ToString(CultureInfo.InvariantCulture)] = row["LINK"]; | |
ds.Tables["T_REVIZ_SPERSON"].Rows.Add(row); | |
SetRevizSPersonRow(row, dict, sPersonPart, ds.Tables["PERSON_PART"], bindPerson); | |
} | |
} | |
#endregion S_PERSON | |
if (value.ContainsKey("REVIZCOST") && value.ContainsKey("PERSONCOST")) | |
{ | |
var bindRevizCost = new Dictionary<string, object>(); | |
var revizCost = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(value["REVIZCOST"].ToString()); | |
foreach (DataRow row in ds.Tables["REVIZCOST"].Rows) | |
{ | |
bool flag = true; | |
for (int j = revizCost.Count - 1; j >= 0; j--) | |
{ | |
Dictionary<string, object> dict = revizCost[j]; | |
if ((int) (long) dict["S_RNORM"] == (int) row["S_RNORM"]) | |
{ | |
bindRevizCost[dict["LINK"].ToString()] = row["LINK"]; | |
row["VAL"] = dict["VAL"] ?? DBNull.Value; | |
revizCost.RemoveAt(j); | |
flag = false; | |
break; | |
} | |
} | |
if (flag) | |
{ | |
delRows.Add(row); | |
} | |
} | |
foreach (Dictionary<string, object> dict in revizCost) | |
{ | |
DataRow row = ds.Tables["REVIZCOST"].NewRow(); | |
bindRevizCost[dict["LINK"].ToString()] = row["LINK"]; | |
row["S_RNORM"] = dict["S_RNORM"]; | |
row["VAL"] = dict["VAL"] ?? DBNull.Value; | |
row["S_ORG"] = User.Instance.Org; | |
row["REVIZ"] = ruc.Row["LINK"]; | |
ds.Tables["REVIZCOST"].Rows.Add(row); | |
} | |
var personCost = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(value["PERSONCOST"].ToString()); | |
foreach (DataRow row in ds.Tables["PERSON_COST"].Rows) | |
{ | |
bool flag = true; | |
for (int j = personCost.Count - 1; j >= 0; j--) | |
{ | |
Dictionary<string, object> dict = personCost[j]; | |
int linkCost = Convert.ToInt32((bindRevizCost.ContainsKey(dict["REVIZCOST"].ToString()) | |
? bindRevizCost[dict["REVIZCOST"].ToString()] | |
: dict["REVIZCOST"]).ToString()); | |
if (linkCost == (int) row["REVIZCOST"]) | |
{ | |
row["T_REVIZ_SPERSON"] = bindPerson.ContainsKey(dict["T_REVIZ_SPERSON"].ToString()) | |
? bindPerson[dict["T_REVIZ_SPERSON"].ToString()] | |
: dict["T_REVIZ_SPERSON"]; | |
row["VAL"] = dict["VAL"] ?? DBNull.Value; | |
personCost.RemoveAt(j); | |
flag = false; | |
break; | |
} | |
} | |
if (flag) | |
{ | |
delRows.Add(row); | |
} | |
} | |
foreach (Dictionary<string, object> dict in personCost) | |
{ | |
DataRow row = ds.Tables["PERSON_COST"].NewRow(); | |
row["REVIZCOST"] = bindRevizCost.ContainsKey(dict["REVIZCOST"].ToString()) | |
? bindRevizCost[dict["REVIZCOST"].ToString()] | |
: dict["REVIZCOST"]; | |
row["T_REVIZ_SPERSON"] = bindPerson.ContainsKey(dict["T_REVIZ_SPERSON"].ToString()) | |
? bindPerson[dict["T_REVIZ_SPERSON"].ToString()] | |
: dict["T_REVIZ_SPERSON"]; | |
row["VAL"] = dict["VAL"] ?? DBNull.Value; | |
ds.Tables["PERSON_COST"].Rows.Add(row); | |
} | |
} | |
/* | |
//ruc.Row["DOCOSNOVNUMBER"] = value["DOCOSNOVNUMBER"]; | |
params['DOCOSNOVDT'] = objs['DOCOSNOVDT'].getValue(); | |
params['DOCOSNOVFILE'] = objs['DOCOSNOVFILE']; | |
params['DOCOSNOV'] = objs['DOCOSNOV']; | |
*/ | |
#endregion Общие | |
#region Подготовка | |
var rTema = JsonConvert.DeserializeObject<List<int>>(value["S_RTEMA"].ToString()); | |
DictEditor.Bind(rlc, ruc.Row, "S_RTEMA", "T_REVIZ_SRTEMA"); | |
DictionaryUpdController.AfterBind(DictEditor, ruc.Row); | |
DictionaryUpdController.ChangeBoundData(DictEditor, rTema); | |
var rProg = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(value["S_RPROG"].ToString()); | |
var progPerson = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(value["PROGPERSON"].ToString()); | |
foreach ( | |
DataRow row in ds.Tables["T_REVIZ_SRPROG"].Rows.Cast<DataRow>().Where(row => row.RowState != DataRowState.Deleted) | |
) | |
{ | |
bool flag = true; | |
string sRprog1 = row["S_RPROG"].IsNullOrDBNull() ? "" : row["S_RPROG"].ToString(); | |
string tRevizObjects1 = row["T_REVIZ_OBJECTS"].IsNullOrDBNull() ? "0" : row["T_REVIZ_OBJECTS"].ToString(); | |
for (int j = rProg.Count - 1; j >= 0; j--) | |
{ | |
string sRprog2 = rProg[j]["S_RPROG"] == null ? "" : rProg[j]["S_RPROG"].ToString(); | |
string tRevizObjects2 = (rProg[j]["T_REVIZ_OBJECTS"].ToString() == "0" | |
? "0" | |
: bindTRevizObjects.ContainsKey(rProg[j]["T_REVIZ_OBJECTS"].ToString()) | |
? bindTRevizObjects[rProg[j]["T_REVIZ_OBJECTS"].ToString()] | |
: rProg[j]["T_REVIZ_OBJECTS"]).ToString(); | |
if ((sRprog1 != sRprog2) || (tRevizObjects1 != tRevizObjects2)) continue; | |
SetRevizProgPersonRow(ds.Tables["PROGPERSON"], progPerson, (int) row["LINK"], (int) (long) rProg[j]["LINK"]); | |
row["METHOD"] = rProg[j]["METHOD"] ?? DBNull.Value; | |
row["DT1"] = ToDateTimeParse(rProg[j]["DT1"].ToString()); | |
row["DT2"] = ToDateTimeParse(rProg[j]["DT2"].ToString()); | |
row["ORD"] = rProg[j]["ORD"]; | |
flag = false; | |
rProg.RemoveAt(j); | |
break; | |
} | |
if (flag) | |
{ | |
delRows.Add(row); | |
//row.Delete(); | |
} | |
} | |
foreach (Dictionary<string, object> dict in rProg) | |
{ | |
DataRow newRow = ds.Tables["T_REVIZ_SRPROG"].NewRow(); | |
newRow["METHOD"] = dict["METHOD"] ?? DBNull.Value; | |
newRow["DT1"] = ToDateTimeParse(dict["DT1"].ToString()); | |
newRow["DT2"] = ToDateTimeParse(dict["DT2"].ToString()); | |
newRow["ORD"] = dict["ORD"]; | |
newRow["S_RPROG"] = Convert.ToInt32(dict["S_RPROG"].ToString()); | |
newRow["REVIZ"] = ruc.Row["LINK"]; | |
newRow["T_REVIZ_OBJECTS"] = dict["T_REVIZ_OBJECTS"].ToString() == "0" | |
? DBNull.Value | |
: bindTRevizObjects.ContainsKey(dict["T_REVIZ_OBJECTS"].ToString()) | |
? bindTRevizObjects[dict["T_REVIZ_OBJECTS"].ToString()] | |
: dict["T_REVIZ_OBJECTS"]; | |
ds.Tables["T_REVIZ_SRPROG"].Rows.Add(newRow); | |
SetRevizProgPersonRow(ds.Tables["PROGPERSON"], progPerson, (int) newRow["LINK"], (int) (long) dict["LINK"]); | |
} | |
#endregion Подготовка | |
#region Нарушения | |
#region FactNar | |
var bindFactNar = new Dictionary<string, object>(); | |
if (value.ContainsKey("factNar")) | |
{ | |
var factNar = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(value["factNar"].ToString()); | |
foreach (DataRow row in ds.Tables["FACTNAR"].Rows) | |
{ | |
bool flag = true; | |
for (int j = factNar.Count - 1; j >= 0; j--) | |
{ | |
Dictionary<string, object> dict = factNar[j]; | |
if ((int) (long) dict["LINK"] == (int) row["LINK"]) | |
{ | |
SetRevizFactNarRow(row, dict, bindTRevizAudit); | |
factNar.RemoveAt(j); | |
flag = false; | |
break; | |
} | |
} | |
if (flag) | |
{ | |
delRows.Add(row); | |
//row.Delete(); | |
} | |
} | |
foreach (Dictionary<string, object> dict in factNar) | |
{ | |
DataRow row = ds.Tables["FACTNAR"].NewRow(); | |
bindFactNar[dict["LINK"].ToString()] = row["LINK"]; | |
SetRevizFactNarRow(row, dict, bindTRevizAudit); | |
ds.Tables["FACTNAR"].Rows.Add(row); | |
} | |
if (value.ContainsKey("factNarNpa")) | |
{ | |
var factNarNpa = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(value["factNarNpa"].ToString()); | |
foreach (DataRow row in ds.Tables["FACTNARNPA"].Rows) | |
{ | |
if (row.RowState == DataRowState.Deleted) continue; | |
bool flag = true; | |
for (int j = factNarNpa.Count - 1; j >= 0; j--) | |
{ | |
Dictionary<string, object> dict = factNarNpa[j]; | |
if ((int) (long) dict["LINK"] == (int) row["LINK"]) | |
{ | |
row["S_NPA"] = dict["S_NPA"]; | |
factNarNpa.RemoveAt(j); | |
flag = false; | |
break; | |
} | |
} | |
if (flag) | |
{ | |
delRows.Add(row); | |
//row.Delete(); | |
} | |
} | |
foreach (Dictionary<string, object> dict in factNarNpa) | |
{ | |
DataRow row = ds.Tables["FACTNARNPA"].NewRow(); | |
row["S_NPA"] = dict["S_NPA"]; | |
row["FACTNAR"] = bindFactNar.ContainsKey(dict["FACTNAR"].ToString()) | |
? bindFactNar[dict["FACTNAR"].ToString()] | |
: dict["FACTNAR"]; | |
ds.Tables["FACTNARNPA"].Rows.Add(row); | |
} | |
} | |
if (value.ContainsKey("factNarRem")) | |
{ | |
var factNarRem = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(value["factNarRem"].ToString()); | |
foreach (DataRow row in ds.Tables["FACTNARREM"].Rows) | |
{ | |
if (row.RowState == DataRowState.Deleted) continue; | |
bool flag = true; | |
for (int j = factNarRem.Count - 1; j >= 0; j--) | |
{ | |
Dictionary<string, object> dict = factNarRem[j]; | |
if ((int) (long) dict["LINK"] == (int) row["LINK"]) | |
{ | |
SetRevizFactNarRemRow(row, dict); | |
factNarRem.RemoveAt(j); | |
flag = false; | |
break; | |
} | |
} | |
if (flag) | |
{ | |
delRows.Add(row); | |
//row.Delete(); | |
} | |
} | |
foreach (Dictionary<string, object> dict in factNarRem) | |
{ | |
DataRow row = ds.Tables["FACTNARREM"].NewRow(); | |
row["FACTNAR"] = bindFactNar.ContainsKey(dict["FACTNAR"].ToString()) | |
? bindFactNar[dict["FACTNAR"].ToString()] | |
: dict["FACTNAR"]; | |
SetRevizFactNarRemRow(row, dict); | |
ds.Tables["FACTNARREM"].Rows.Add(row); | |
} | |
} | |
if (value.ContainsKey("tFactNarObjects")) | |
{ | |
var tFactNarObjects = | |
JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(value["tFactNarObjects"].ToString()); | |
foreach (DataRow row in ds.Tables["T_FACTNAR_OBJECTS"].Rows) | |
{ | |
if (row.RowState == DataRowState.Deleted) continue; | |
bool flag = true; | |
for (int j = tFactNarObjects.Count - 1; j >= 0; j--) | |
{ | |
Dictionary<string, object> dict = tFactNarObjects[j]; | |
if ((int) (long) dict["LINK"] == (int) row["LINK"]) | |
{ | |
row["T_REVIZ_OBJECTS"] = bindTRevizObjects.ContainsKey(dict["T_REVIZ_OBJECTS"].ToString()) | |
? bindTRevizObjects[dict["T_REVIZ_OBJECTS"].ToString()] | |
: dict["T_REVIZ_OBJECTS"]; | |
tFactNarObjects.RemoveAt(j); | |
flag = false; | |
break; | |
} | |
} | |
if (flag) | |
{ | |
delRows.Add(row); | |
//row.Delete(); | |
} | |
} | |
foreach (Dictionary<string, object> dict in tFactNarObjects) | |
{ | |
DataRow row = ds.Tables["T_FACTNAR_OBJECTS"].NewRow(); | |
row["FACTNAR"] = bindFactNar.ContainsKey(dict["FACTNAR"].ToString()) | |
? bindFactNar[dict["FACTNAR"].ToString()] | |
: dict["FACTNAR"]; | |
row["T_REVIZ_OBJECTS"] = bindTRevizObjects.ContainsKey(dict["T_REVIZ_OBJECTS"].ToString()) | |
? bindTRevizObjects[dict["T_REVIZ_OBJECTS"].ToString()] | |
: dict["T_REVIZ_OBJECTS"]; | |
ds.Tables["T_FACTNAR_OBJECTS"].Rows.Add(row); | |
} | |
} | |
} | |
#endregion FactNar | |
#region Проверенная продукция | |
var bindOkp = new Dictionary<string, object>(); | |
if (value.ContainsKey("okp")) | |
{ | |
var okp = JsonConvert.DeserializeObject<List<Dictionary<string, int?>>>(value["okp"].ToString()); | |
foreach (DataRow row in ds.Tables["REVIZOKP"].Rows) | |
{ | |
bool flag = true; | |
for (int j = okp.Count - 1; j >= 0; j--) | |
{ | |
Dictionary<string, int?> dict = okp[j]; | |
if ((int) dict["LINK"] == (int) row["LINK"]) | |
{ | |
SetRevizOkpRow(row, dict); | |
okp.RemoveAt(j); | |
flag = false; | |
break; | |
} | |
} | |
if (flag) | |
{ | |
delRows.Add(row); | |
//row.Delete(); | |
} | |
} | |
foreach (Dictionary<string, int?> dict in okp) | |
{ | |
DataRow row = ds.Tables["REVIZOKP"].NewRow(); | |
row["REVIZ"] = ruc.Row["LINK"]; | |
bindOkp[dict["LINK"].ToString()] = row["LINK"]; | |
SetRevizOkpRow(row, dict); | |
ds.Tables["REVIZOKP"].Rows.Add(row); | |
} | |
if (value.ContainsKey("tFactNarRevizOkp")) | |
{ | |
var tFactNarRevizOkp = | |
JsonConvert.DeserializeObject<List<Dictionary<string, int>>>(value["tFactNarRevizOkp"].ToString()); | |
foreach (DataRow row in ds.Tables["T_FACTNAR_REVIZOKP"].Rows) | |
{ | |
bool flag = true; | |
for (int j = tFactNarRevizOkp.Count - 1; j >= 0; j--) | |
{ | |
Dictionary<string, int> dict = tFactNarRevizOkp[j]; | |
if (dict["LINK"] == (int) row["LINK"]) | |
{ | |
tFactNarRevizOkp.RemoveAt(j); | |
flag = false; | |
break; | |
} | |
} | |
if (flag) | |
{ | |
delRows.Add(row); | |
//row.Delete(); | |
} | |
} | |
foreach (Dictionary<string, int> dict in tFactNarRevizOkp) | |
{ | |
DataRow row = ds.Tables["T_FACTNAR_REVIZOKP"].NewRow(); | |
row["REVIZOKP"] = bindOkp.ContainsKey(dict["REVIZOKP"].ToString()) | |
? bindOkp[dict["REVIZOKP"].ToString()] | |
: dict["REVIZOKP"]; | |
row["FACTNAR"] = bindFactNar.ContainsKey(dict["FACTNAR"].ToString()) | |
? bindFactNar[dict["FACTNAR"].ToString()] | |
: dict["FACTNAR"]; | |
ds.Tables["T_FACTNAR_REVIZOKP"].Rows.Add(row); | |
} | |
} | |
} | |
#endregion Проверенная продукция | |
#region Проверенные документы | |
var bindDoc = new Dictionary<string, object>(); | |
if (value.ContainsKey("rDoc")) | |
{ | |
var rDoc = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(value["rDoc"].ToString()); | |
foreach (DataRow row in ds.Tables["REVIZDOC"].Rows) | |
{ | |
bool flag = true; | |
for (int j = rDoc.Count - 1; j >= 0; j--) | |
{ | |
Dictionary<string, object> dict = rDoc[j]; | |
if ((int) (long) dict["LINK"] == (int) row["LINK"]) | |
{ | |
SetRevizRDocRow(row, dict); | |
rDoc.RemoveAt(j); | |
flag = false; | |
break; | |
} | |
} | |
if (flag) | |
{ | |
delRows.Add(row); | |
//row.Delete(); | |
} | |
} | |
foreach (Dictionary<string, object> dict in rDoc) | |
{ | |
DataRow row = ds.Tables["REVIZDOC"].NewRow(); | |
row["REVIZ"] = ruc.Row["LINK"]; | |
bindDoc[dict["LINK"].ToString()] = row["LINK"]; | |
SetRevizRDocRow(row, dict); | |
ds.Tables["REVIZDOC"].Rows.Add(row); | |
} | |
if (value.ContainsKey("tFactNarRevizDoc")) | |
{ | |
var tFactNarRevizDoc = | |
JsonConvert.DeserializeObject<List<Dictionary<string, int>>>(value["tFactNarRevizDoc"].ToString()); | |
foreach (DataRow row in ds.Tables["T_FACTNAR_REVIZDOC"].Rows) | |
{ | |
bool flag = true; | |
for (int j = tFactNarRevizDoc.Count - 1; j >= 0; j--) | |
{ | |
Dictionary<string, int> dict = tFactNarRevizDoc[j]; | |
if (dict["LINK"] == (int) row["LINK"]) | |
{ | |
tFactNarRevizDoc.RemoveAt(j); | |
flag = false; | |
break; | |
} | |
} | |
if (flag) | |
{ | |
delRows.Add(row); | |
//row.Delete(); | |
} | |
} | |
foreach (Dictionary<string, int> dict in tFactNarRevizDoc) | |
{ | |
DataRow row = ds.Tables["T_FACTNAR_REVIZDOC"].NewRow(); | |
row["REVIZDOC"] = bindDoc.ContainsKey(dict["REVIZDOC"].ToString()) | |
? bindDoc[dict["REVIZDOC"].ToString()] | |
: dict["REVIZDOC"]; | |
row["FACTNAR"] = bindFactNar.ContainsKey(dict["FACTNAR"].ToString()) | |
? bindFactNar[dict["FACTNAR"].ToString()] | |
: dict["FACTNAR"]; | |
ds.Tables["T_FACTNAR_REVIZDOC"].Rows.Add(row); | |
} | |
} | |
} | |
#endregion Проверенные документы | |
#endregion Нарушения | |
#region Оформление | |
if (value.ContainsKey("calc")) | |
{ | |
var calc = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(value["calc"].ToString()); | |
foreach (DataRow row in ds.Tables["CALC"].Rows) | |
{ | |
bool flag = true; | |
for (int j = calc.Count - 1; j >= 0; j--) | |
{ | |
Dictionary<string, object> dict = calc[j]; | |
if ((int) (long) dict["LINK"] == (int) row["LINK"]) | |
{ | |
SetRevizCalcRow(row, dict, ruc.Row, bindPerson); | |
calc.RemoveAt(j); | |
flag = false; | |
break; | |
} | |
} | |
if (flag) | |
{ | |
delRows.Add(row); | |
//row.Delete(); | |
} | |
} | |
foreach (Dictionary<string, object> dict in calc) | |
{ | |
DataRow row = ds.Tables["CALC"].NewRow(); | |
SetRevizCalcRow(row, dict, ruc.Row, bindPerson); | |
row["S_CALC"] = dict["S_CALC"]; | |
row["T_REVIZ_AUDIT"] = bindTRevizAudit.ContainsKey(dict["T_REVIZ_AUDIT"].ToString()) | |
? bindTRevizAudit[dict["T_REVIZ_AUDIT"].ToString()] | |
: dict["T_REVIZ_AUDIT"]; | |
ds.Tables["CALC"].Rows.Add(row); | |
} | |
} | |
#endregion Оформление | |
for (int i = 0, len = delRows.Count(); i < len; i++) | |
{ | |
delRows[i].Delete(); | |
} | |
Save(ruc, result); | |
} | |
} | |
catch (Exception ex) | |
{ | |
result["ErrorMsg"] = ex.Message; | |
ruc.Cancel(); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment