private bool disposedValue = false; // To detect redundant calls public void Disconnect() { IsConnected = false; try { sH.DBLogout(); } catch (Exception e) { LastException = new SHConnectorException("Disonnect Method exception", e); }; }
public void Connect(string address, string port, string protocol, string user, string password) { string timeOut = "30000"; try { sH.SetServerName(address + protocol + port + "t" + timeOut); IsConnected = sH.DBLoginEx(user, password) == 0; if (!IsConnected) { throw new SHConnectorException(sH.GetExcMessage(), sH.GetExcCode()); } ; } catch (Exception e) { LastException = new SHConnectorException("Connect Method Exception", e); throw LastException; } }
public void Connect(string connectionString) { string[] connParamsArray; try { connParamsArray = connectionString.Split(';'); Dictionary <string, string> connectionParams = connParamsArray.Select(s => s.Split('=')).ToDictionary(arr => arr[0].ToLower(), arr => arr[1]); Connect( connectionParams["address"], connectionParams["port"], connectionParams["protocol"], connectionParams["user"], connectionParams["psw"] ); } catch (Exception e) { LastException = new SHConnectorException("Connect Method Exception", e); throw LastException; } }
public IEnumerable <StoreHouseData> GetGoodsWithCostPrice(DateTime beginDate, DateTime endDate) { List <StoreHouseData> result = new List <StoreHouseData>(); if (!IsConnected) { LastException = new SHConnectorException("Not connected", -1); throw LastException; } ; string period = $"{beginDate} - {endDate}:"; try { var shQuery = sH.DocFList(beginDate.ToOADate(), endDate.ToOADate(), 0, 1, 0); if (shQuery < 0) { LastException = new SHConnectorException(sH.GetExcMessage(), sH.GetExcCode()); throw LastException; } //int recordCount = sH.RecordCount(shQuery); //int countProcessed = 0; while (sH.EOF(shQuery) != 1) { //countProcessed ++; //if (countProcessed % 5 == 0) //{ // Console.SetCursorPosition(0, Console.CursorTop); // Console.Write($"{period} Processed {countProcessed} from {recordCount} records"); //}; int DocType = sH.ValByName(shQuery, "1.103.10.1"); if (DocType != 12) { sH.Next(shQuery); continue; } int docKey = sH.ValByName(shQuery, "1.103.1.1"); GetGoodsFromDoc(docKey, ref result); sH.Next(shQuery); } sH.CloseQuery(shQuery); } catch (Exception e) { lastException = new SHConnectorException("Connect Method Exception", e); throw LastException; }; result = (from item in result group item by new { Date = item.Date, Code = item.Code } into grouped select new StoreHouseData() { Date = grouped.Key.Date, Code = grouped.Key.Code, CostPrice = grouped.Average(x => x.CostPrice) }).ToList <StoreHouseData>(); return(result); }