public object delete() { object res = null; bool ok = false; try { environment.docBegin(adapter.getDataSet()); adapter.delete(); environment.beginBatch(); res = adapter.update(); environment.commitBatch(); ok = true; } catch (Exception exc) { environment.rollbackBatch(); environment.getExceptionHandler().setException(exc); } finally { environment.docEnd(); } if (ok) { if (handlerReferenceInformer != null) { handlerReferenceInformer.Invoke(this, res); } } return(res); }
public void import(XmlDocument doc) { XmlElement rootNode = doc[_nodeRootName]; char sepChar = '\t'; string adpName = _userAdapter.getAdapterDataSet().getCode(); foreach (XmlNode itemNode in rootNode.ChildNodes) { if ((itemNode.Name == _nodeItemName) && (itemNode.Attributes[_attrRootCode].Value == adpName)) { _userAdapter.add(); DataSet dataSet = _userAdapter.getDataSet(); foreach (XmlNode itemNodeTable in itemNode.ChildNodes) { string colsList = itemNodeTable.Attributes[_attrItemTableCols].Value; string[] colsArr = ToolString.explodeList(sepChar, colsList); string tableName = itemNodeTable.Name; DataTable tableD = dataSet.Tables[tableName]; if (tableD == null) { throw new MyException.MyExceptionError(MessageCollection.T_MSG_ERROR_INNER, new object[] { tableName }); } tableD.Clear(); string data = itemNode.InnerText; // StringReader reader = new StringReader(data); var lineIndx = 0; var commitCounter = 0; string line; var listCode = new List <string>(); while ((line = reader.ReadLine()) != null) { ++lineIndx; try { if (line != string.Empty) { string[] arrData = ToolString.explodeList(sepChar, line); //line.Split(sepChar); if (arrData == null || arrData.Length != colsArr.Length) { throw new MyException.MyExceptionError(MessageCollection.T_MSG_ERROR_INVALID_ARGS_COUNT, new object[] { line }); } // if (lineIndx > 10) // break; var rowDic = new Dictionary <string, string>(); for (int indxColD = 0; indxColD < colsArr.Length; ++indxColD) { var col = colsArr[indxColD]; var colVal = arrData[indxColD]; if (col == "CODE") { var keyCode = colVal.ToUpperInvariant(); if (keyCode == "") { //throw new Exception("Record CODE is empty: index: " + lineIndx); colVal = "EMPTYCODE" + lineIndx; } else if (listCode.Contains(keyCode)) { throw new Exception("Record dublicate: " + keyCode); } else { listCode.Add(keyCode); } } rowDic[col] = colVal; } switch (tableName) { //case "FIRMPARAMS": // SqlExecute.executeNonQuery(_environment, "INSERT INTO L_FIRMPARAMS (LOGICALREF,CODE,VALUE) VALUES (@P1,@P2,@P3 )", // new object[] { rowDic["CODE"], rowDic["CODE"], rowDic["VALUE"] }); // break; //case "CLCARD": // SqlExecute.executeNonQuery(_environment, "INSERT INTO LG_$FIRM$_CLCARD (LOGICALREF,CODE,CLGRPCODE,CLGRPCODESUB) VALUES (@P1,@P2,@P3,@P4)", // new object[] { rowDic["LOGICALREF"], rowDic["CODE"], rowDic["CLGRPCODE"], rowDic["CLGRPCODESUB"] }); // break; //case "ITEMS": // SqlExecute.executeNonQuery(_environment, "INSERT INTO LG_$FIRM$_ITEMS (LOGICALREF,CODE,STGRPCODE,STGRPCODESUB) VALUES (@P1,@P2,@P3,@P4)", // new object[] { rowDic["LOGICALREF"], rowDic["CODE"], rowDic["STGRPCODE"], rowDic["STGRPCODESUB"] }); // break; default: { DataRow newRowD = _userAdapter.addRowToTable(tableD); foreach (var pair in rowDic) { DataColumn dCol = tableD.Columns[pair.Key]; if (dCol == null) { throw new MyException.MyExceptionError(MessageCollection.T_MSG_ERROR_INNER, new object[] { pair.Key }); } var value_ = _formating.parse(pair.Value, dCol.DataType); newRowD[dCol] = value_; } } break; } ++commitCounter; //if (commitCounter > 1) //{ // _userAdapter.update(); // _userAdapter.clear(); // tableD.Clear(); // // // // // commitCounter = 0; //} } } catch (Exception exc) { ToolMobile.setRuntimeMsg(line); ToolMobile.setRuntimeMsg(exc.ToString()); throw new Exception(exc.Message, exc); } } } _userAdapter.update(); } } }