ServiceConnection.cs
DrawDownLine.cs
DMSServiceAdmin.cs
Scroll.cs
GetBimap.cs
LoadFile.cs
Database Insert
Database Get
Database Update
ServiceConnection.cs
/******************************************************************************* File : ServiceConnection.cs Description : Connection to the WCF service that is the Time Clock Server -------------------------------------------------------------------------------- Functions: Close() - clean up clsServiceConnection() - Connection to the WCF service that is the Time Clock Server Log() - Log stuff OpenAdmin() - OpenServer() - Open the connection -------------------------------------------------------------------------------- History: 2012/08/17 TPR Created *******************************************************************************/ using System; using System.Diagnostics; using System.ServiceModel; namespace nsIService { /******************************************************************************* Class : clsServiceConnection Description : Connection to the WCF service that is the Time Clock Server -------------------------------------------------------------------------------- History: 2012/08/17 TPR Created *******************************************************************************/ public class clsServiceConnection { public bool Connected; public IServer ServerInterface; public IAdmin AdminInterface; ChannelFactory<IServer> Factory; ChannelFactory<IAdmin> FactoryAdmin; /******************************************************************************* Constructor : clsServiceConnection() Description : Connection to the WCF service that is the Time Clock Server Parameters : None -------------------------------------------------------------------------------- History: 2012/08/17 TPR Created *******************************************************************************/ public clsServiceConnection() { Connected = false; } /******************************************************************************* Function : OpenService() Description : Parameters : string ipAddress - : int port - : out Exception exceptionResult - Returns : bool -------------------------------------------------------------------------------- History: 2015/02/03 WLM Created *******************************************************************************/ public bool OpenService(string ipAddress, int port, out Exception exceptionResult) { string Str; NetTcpBinding Bind; exceptionResult = null; try { Bind = new NetTcpBinding(); Bind.MaxReceivedMessageSize = int.MaxValue; Bind.ReaderQuotas.MaxStringContentLength = int.MaxValue; Bind.ReaderQuotas.MaxArrayLength = int.MaxValue; Bind.MaxConnections = 100; Bind.CloseTimeout = new TimeSpan(0, 0, 30); Bind.OpenTimeout = new TimeSpan(0, 0, 30); Bind.ReceiveTimeout = new TimeSpan(0, 0, 600); Bind.SendTimeout = new TimeSpan(0, 0, 300); Bind.Security.Mode = SecurityMode.None; Bind.MaxBufferSize = int.MaxValue; Bind.ListenBacklog = int.MaxValue; Factory = new ChannelFactory<IServer>(Bind, new EndpointAddress($"net.tcp://{ipAddress}:{port}/CustomeriZer")); ServerInterface = Factory.CreateChannel(); //Connected = ServerInterface.StartSession(); return(true); } catch (Exception ex) { Connected = false; exceptionResult = ex; Str = $"OpenService({ipAddress}, {port})"; Log(Str, ex); return(false); } } /******************************************************************************* Function : OpenAdmin() Description : Parameters : string ipAddress - : int port - : out Exception exceptionResult - Returns : bool -------------------------------------------------------------------------------- History: 2014/10/02 WLM Created *******************************************************************************/ public bool OpenAdmin(string ipAddress, int port, out Exception exceptionResult) { string Str; NetTcpBinding Bind; exceptionResult = null; try { Bind = new NetTcpBinding(); Bind.MaxReceivedMessageSize = int.MaxValue; Bind.ReaderQuotas.MaxStringContentLength = int.MaxValue; Bind.ReaderQuotas.MaxArrayLength = int.MaxValue; Bind.MaxConnections = 100; Bind.CloseTimeout = new TimeSpan(0, 0, 30); Bind.OpenTimeout = new TimeSpan(0, 0, 30); Bind.ReceiveTimeout = new TimeSpan(0, 0, 600); Bind.SendTimeout = new TimeSpan(0, 0, 300); Bind.Security.Mode = SecurityMode.None; Bind.MaxBufferSize = int.MaxValue; Bind.ListenBacklog = int.MaxValue; FactoryAdmin = new ChannelFactory<IAdmin>(Bind, new EndpointAddress($"net.tcp://{ipAddress}:{port}/CustomeriZerAdmin")); AdminInterface = FactoryAdmin.CreateChannel(); return(true); } catch (Exception ex) { Connected = false; exceptionResult = ex; Str = $"OpenAdmin({ipAddress}, {port})"; Log(Str, ex); return(false); } } /******************************************************************************* Function : Close() Description : clean up Parameters : None Returns : void -------------------------------------------------------------------------------- History: 2012/08/17 TPR Created *******************************************************************************/ public void Close() { Connected = false; try { if (ServerInterface != null) { ((IClientChannel)ServerInterface).Close(); ((IClientChannel)ServerInterface).Dispose(); ((IDisposable)ServerInterface).Dispose(); ServerInterface = null; } if (Factory != null) { if (Factory.State == CommunicationState.Opened) Factory.Close(); ((IDisposable)Factory).Dispose(); Factory = null; } if (FactoryAdmin != null) { if (FactoryAdmin.State == CommunicationState.Opened) FactoryAdmin.Close(); ((IDisposable)FactoryAdmin).Dispose(); FactoryAdmin = null; } } catch (CommunicationObjectFaultedException ec) { Log("Close(CommunicationObjectFaultedException)", ec); } catch (Exception ex) { Log("Close()", ex); } } /******************************************************************************* Function : Log() Description : Log stuff Parameters : string text - : Exception e - Returns : void -------------------------------------------------------------------------------- History: 2012/08/17 TPR Created *******************************************************************************/ static public void Log(string text, Exception e) { try { if (e != null) EventLog.WriteEntry("ICustomeriZerService.dll", text + ": " + e.Message, EventLogEntryType.Error); else EventLog.WriteEntry("ICustomeriZerService.dll", text, EventLogEntryType.Error); } catch { } } } /* End Of Class clsServiceConnection */ } /* End Of NameSpace nsITimeClockServer */
DrawDownLine.cs
/******************************************************************************* File : DrawDownLine.cs Description : -------------------------------------------------------------------------------- Functions: -------------------------------------------------------------------------------- History: 2016/01/05 WLM Created *******************************************************************************/ using System; using System.Threading.Tasks; namespace nsL4Sonar { /******************************************************************************* Class : ctlPanelSonar Description : -------------------------------------------------------------------------------- History: 2015/10/02 WLM Created *******************************************************************************/ public partial class ctlPanelSonar { /******************************************************************************* Function : DrawDownLine() Description : Parameters : int x - : int stride - : int sonIdx - : eSonarView sonarView - Returns : bool -------------------------------------------------------------------------------- History: 2017/08/17 WLM Created *******************************************************************************/ unsafe bool DrawDownLine(int x, clsFastBitmap fastBmp, int sonIdx, eSonarView sonarView) { try { if (SonDatas[sonIdx] == null) return(true); Parallel.For(0, fastBmp.Stride, Y => { int YIdx; YIdx = (int)(Y * RangeScale); if (YIdx >= SonDatas[sonIdx].Data.Length) return; if (sonarView == eSonarView.Down) /* Merge Port & Starboard side imaging */ fastBmp.SetPixel(x, Y, (byte)((GLOBALS.SonDataPort[sonIdx].Data[YIdx] + GLOBALS.SonDataStarboard[sonIdx].Data[YIdx]) / 2)); else fastBmp.SetPixel(x, Y, SonDatas[sonIdx].Data[YIdx]); }); return(true); } catch(Exception ex) { UTIL.LogError("DrawDownLine()", ex.Message); return(false); } } } /* End Of Class ctlPanelSonar */ } /* End Of NameSpace nsL4Sonar */
DMSServiceAdmin.cs
/******************************************************************************* File : DMSServiceAdmin.cs Description : -------------------------------------------------------------------------------- Functions: clsDMS_Service_Admin() - ConnectToDMS() - connects to the DMS admin port ctrlA_KeyDown() - enable ctrl-A on the textbox DisconnectFromDMS() - disconnect from the DMS admin port Init() - inits the plugin IsIpValid() - determines if the IP entered is in a Valid format. UpdateLabel() - -------------------------------------------------------------------------------- History: 2018/01/18 WLM Created *******************************************************************************/ using System; using System.Net.Sockets; using System.Text.RegularExpressions; using System.Windows.Forms; using nsUtil; namespace nsDMSServiceAdmin { /******************************************************************************* Class : DMSServiceAdmin Description : -------------------------------------------------------------------------------- History: 2018/05/08 WLM Created 2018/04/01 WLM Changed to reflect removal of PVSuiteInterface/nsStruct repeated enums *******************************************************************************/ public partial class DMSServiceAdmin : PVSuiteInterface.SuiteUserControl { /* Class Globals */ private TcpClient TCPMonitor, TCPCanned, TCPControl; private NetworkStream NetStreamMonitor, NetStreamCanned, NetStreamControl; private bool Connected; public delegate void UpdateLabelDelegate(Label label, string info); public UpdateLabelDelegate UpdateLabelDel; /******************************************************************************* Constructor : clsDMS_Service_Admin() Description : Parameters : None -------------------------------------------------------------------------------- History: 2018/05/08 WLM Created *******************************************************************************/ public clsDMS_Service_Admin() { stFileDescription FileDescription; InitializeComponent(); ProgramInfo.MinPVVersion = "2.10.05.04"; FileDescription = new stFileDescription(); FileDescription.Language = eLanguages.English; FileDescription.ShortDescription = "DMS Service Admin"; FileDescription.LongDescription = "Connects to the PVA sample DMS service to monitor and control it."; ProgramInfo.FileDescriptions.Add(FileDescription); } /******************************************************************************* Function : Init() Description : inits the plugin Parameters : None Returns : void -------------------------------------------------------------------------------- History: 2018/05/08 WLM Created inits the plugin *******************************************************************************/ public override void Init() { InitCanned(); InitMonitor(); InitControl(); DoLabelsCanned(); UpdateLabelDel = UpdateLabel; } /******************************************************************************* Function : UpdateLabel() Description : Parameters : TextBox textBox - : string info - : bool append - : bool scrollToEnd - Returns : void -------------------------------------------------------------------------------- History: 2018/05/20 WLM Created *******************************************************************************/ private void UpdateLabel(Label label, string info) { if (label.InvokeRequired) { label.Invoke(new EventHandler(delegate { UpdateLabel(label, info); })); return; } label.Text = info; } /******************************************************************************* Function : ctrlA_KeyDown() Description : enable ctrl-A on the textbox Parameters : object sender - : KeyEventArgs e - Returns : void -------------------------------------------------------------------------------- History: 2018/05/12 WLM Created *******************************************************************************/ private void ctrlA_KeyDown(object sender, KeyEventArgs e) { TextBox TxtBox; TxtBox = sender as TextBox; if (TxtBox == null) return; if (e.Control && e.KeyCode == Keys.A) { TxtBox.SelectionStart = 0; TxtBox.SelectionLength = TxtBox.Text.Length; } } /******************************************************************************* Function : DisconnectFromDMS() Description : disconnect from the DMS admin port Parameters : None Returns : void -------------------------------------------------------------------------------- History: 2018/05/12 WLM Created disconnect from the DMS admin port *******************************************************************************/ private void DisconnectFromDMS() { if (TCPMonitor != null) { Send(TCPMonitor, NetStreamMonitor, "EOS|*"); System.Threading.Thread.Sleep(2); TCPMonitor.Close(); } if (TCPCanned != null) { Send(TCPCanned, NetStreamCanned, "EOS|*"); System.Threading.Thread.Sleep(2); TCPCanned.Close(); } UpdateLabel(labelConnState, "Disconnected"); SetControlButtons(false, false, false); } /******************************************************************************* Function : IsIpValid() Description : determines if the IP entered is in a Valid format. Parameters : None Returns : bool -------------------------------------------------------------------------------- History: 2018/05/20 WLM Created *******************************************************************************/ private bool IsIpValid() { Regex regex; Match match; string pattern = @"^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\. ([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$"; regex = new Regex(pattern); match = regex.Match(textBoxDMSIP.Text); return(match.Success); } /******************************************************************************* Function : ConnectToDMS() Description : connects to the DMS admin port Parameters : None Returns : bool -------------------------------------------------------------------------------- History: 2018/05/12 WLM Created connects to the DMS admin port *******************************************************************************/ private bool ConnectToDMS() { /* Make sure IP address is valid. */ if (!IsIpValid()) { clsUtil.DisplayMessage("Please enter a properly formatted IP address."); textBoxDMSIP.Focus(); return(false); } TCPMonitor = new TcpClient(); TCPCanned = new TcpClient(); TCPControl = new TcpClient(); if (TCPMonitor == null || TCPCanned == null) return(false); try { /* Setup monitor */ TCPMonitor.Connect(textBoxDMSIP.Text, Convert.ToInt32(textBoxDMSPort.Text)); NetStreamMonitor = TCPMonitor.GetStream(); NetStreamMonitor.Flush(); /* Setup Canned */ TCPCanned.Connect(textBoxDMSIP.Text, Convert.ToInt32(textBoxDMSPort.Text)); NetStreamCanned = TCPCanned.GetStream(); NetStreamCanned.Flush(); return(true); } catch (Exception ex) { clsUtil.DisplayMessage($"Following error occurred:\n{ex.Message}"; return(false); } } } /* End Of Class DMSServiceAdmin */ } /* End Of Namespace nsDMSServiceAdmin */
Scroll.cs
/******************************************************************************* File : Scroll.cs Description : -------------------------------------------------------------------------------- Functions: -------------------------------------------------------------------------------- History: 2015/10/14 WLM Created *******************************************************************************/ using System; using System.Collections.Generic; using System.Drawing; using System.Threading.Tasks; using System.Windows.Input; using nsL4Util; namespace nsL4Sonar { /******************************************************************************* Class : ctlPanelSonar Description : -------------------------------------------------------------------------------- History: 2015/10/02 WLM Created *******************************************************************************/ public partial class ctlPanelSonar { /******************************************************************************* Function : Scroll() Description : Parameters : Returns : bool -------------------------------------------------------------------------------- History: 2016/02/08 WLM Created *******************************************************************************/ unsafe public bool Scroll() { int SonIdx, StartX, StartY; Rectangle SrcRect, DestRect; string ErrorOccurredMsg; Dictionary<int, int>WayPoints; clsFastBitmap FastBitmap; if (!GLOBALS.IsFileOpen) return(false); if (SonarView == eSonarView.None) /* Don't Display. Used with viewing only Port or Starboard */ return(true); if (BmpSonar == null) return(false); FastBitmap = null; try { DisplayedWaypoints.Clear(); if (SonarView == eSonarView.Aerial) return(ScrollAerial()); //Stopwatch SW = new Stopwatch(); //SW.Start(); UTIL.CursorWait(this); /*----------------------------------------------------------------------------*/ WayPoints = new Dictionary<int, int>(); FastBitmap = new clsFastBitmap(BmpSonar); FastBitmap.Lock(); if (!FastBitmap.Clear()) { FastBitmap.Unlock(); return(false); } SonDataIdx = GLOBALS.MasterSonIdx; /* Update SonDataIdx */ SonIdx = SonDataIdx; if (SonIdx >= SonDatas.Length) /* Ran out of Sonar Data */ SonIdx = SonDatas.Length - 1; /******************************************************************************/ StartX = 0; StartY = 0; ErrorOccurredMsg = ""; if (UTIL.IsSideImaging(SonarView)) /* Side Imaging */ { StartY = (BmpSonar.Height / 2) - SonIdx; if (StartY > 0) SonIdx = 0; else { StartY = 0; SonIdx -= BmpSonar.Height / 2; } /*----------------------------------------------------------------------------*/ Parallel.For(StartY, BmpSonar.Height, Y => /* Side Imaging */ { int YIdx, SIdx; YIdx = Y - StartY; if (YIdx < 0) YIdx = 0; SIdx = YIdx + SonIdx; if (SIdx >= SonDatas.Length) /* Ran out of Sonar Data */ return; if (SonDatas[SIdx] == null) return; if (!DrawSideLine(Y, FastBitmap, SIdx)) { ErrorOccurredMsg = GLOBALS.LangLabels.Messages[25]; // An error occurred drawing Sonar image return; } /* Check for WayPoint */ if (SETTINGS.DisplayWaypoints && SIdx < GLOBALS.SonDataSonar.Length && GLOBALS.SonDataSonar[SIdx].Header.WayPointID != DEFINE.NO_WAYPOINT) { if (DisplayedWaypoints.Contains(GLOBALS.SonDataSonar[SIdx].Header.WayPointID)) return; DisplayedWaypoints.Add(GLOBALS.SonDataSonar[SIdx].Header.WayPointID); WayPoints.Add(SIdx, BmpSonar.Height - Y); } }); } /******************************************************************************/ else /* Down Imaging */ { StartX = (BmpSonar.Width / 2) - SonIdx; if (StartX > 0) SonIdx = 0; else { StartX = 0; SonIdx -= BmpSonar.Width / 2; } // for (int X = StartX; X < BmpSonar.Width; X ++) Parallel.For(StartX, BmpSonar.Width, X => { int XIdx, SIdx; XIdx = X - StartX; if (XIdx < 0) XIdx = 0; SIdx = XIdx + SonIdx; if (SIdx >= SonDatas.Length) /* Ran out of Sonar Data */ return; if (SonDatas[SIdx] == null) return; if (!DrawDownLine(X, FastBitmap, SIdx, SonarView)) { ErrorOccurredMsg = GLOBALS.LangLabels.Messages[25]; // An error occurred drawing Sonar image return; } /* Check for WayPoint */ if (SIdx < GLOBALS.SonDataSonar.Length && GLOBALS.SonDataSonar[SIdx].Header.WayPointID != DEFINE.NO_WAYPOINT) { if (!DisplayedWaypoints.Contains(GLOBALS.SonDataSonar[SIdx].Header.WayPointID)) { DisplayedWaypoints.Add(GLOBALS.SonDataSonar[SIdx].Header.WayPointID); WayPoints.Add(SIdx, X - DEFINE.WAYPOINT_SIZE); } } }); } FastBitmap.Unlock(); /*----------------------------------------------------------------------------*/ /* Copy from main sonar image to screen */ if (UTIL.IsSideImaging(SonarView)) SrcRect = new Rectangle((int)(BmpSonarWidth - CropMaxRange), 0, (int)(CropMaxRange - CropMinRange), BmpSonarHeight); else /* Down Imaging */ SrcRect = new Rectangle(0, (int)CropMinRange, BmpSonarWidth, (int)(CropMaxRange - CropMinRange)); DestRect = new Rectangle(0, 0, BmpSonarWidth, BmpSonarHeight); GBmpDisplay.DrawImage(BmpSonar, DestRect, SrcRect, GraphicsUnit.Pixel); /*----------------------------------------------------------------------------*/ if (SETTINGS.DisplayWaypoints) GLOBALS.Waypoints.DrawSonar(WayPoints, GBmpDisplay, this); if (SonarView == eSonarView.Starboard) /* Flip Starboard image */ BmpDisplay.RotateFlip(RotateFlipType.RotateNoneFlipX); ImageSonar.Source = L4Imaging.BitmapToImageSource(BmpDisplay); if (!string.IsNullOrEmpty(ErrorOccurredMsg)) { UTIL.Message(ErrorOccurredMsg); UTIL.SendSonarFile(true); GLOBALS.MainWindow.CloseFile(); } //SW.Stop(); //Debug.WriteLine(string.Format("{0} {1} ms", SonarView.ToString(), SW.ElapsedMilliseconds)); return(true); } catch (Exception ex) { FastBitmap.Unlock(); UTIL.Message(string.Format(GLOBALS.LangLabels.Messages[26], ex.Message), true); // Exception occurred scrolling Sonar Panel\n{0} UTIL.SendSonarFile(true); GLOBALS.MainWindow.CloseFile(); return(false); } finally { UTIL.CursorNormal(this); } } } /* End Of Class ctlPanelSonar */ } /* End Of NameSpace nsL4Sonar */
GetBimap.cs
/******************************************************************************* File : GetBitmap.cs Description : -------------------------------------------------------------------------------- Functions: -------------------------------------------------------------------------------- History: 2017/07/23 WLM Created *******************************************************************************/ using System; using System.Linq; using System.Drawing; using System.IO; using System.Net; using nsL4Util; namespace nsL4Sonar { /******************************************************************************* Class : clsMap Description : -------------------------------------------------------------------------------- History: 2017/07/23 WLM Created *******************************************************************************/ public partial class clsMap { /******************************************************************************* Function : GetBitmap() Description : Parameters : int x - : int y - : int zoom - : eMapping mapping - Returns : Bitmap -------------------------------------------------------------------------------- History: 2017/07/23 WLM Created *******************************************************************************/ public Bitmap GetBitmap(int longitude, int latitude, int zoom, eMapping mapping) { WebClient WClient; string URL; string AppPath, ZoomPath, XPath; string FileName, BingQuad; Bitmap Bmp; try { BingQuad = TileXYToQuadKey(longitude, latitude, zoom); AppPath = string.Format("{0}\\Lock 4 Software\\L4Sonar", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)); L4IO.CreateDirectory(AppPath); ZoomPath = $"{AppPath}\\{zoom}\\"; L4IO.CreateDirectory(ZoomPath); XPath = $"{ZoomPath}{mapping.ToString()}\\{latitude}"; if (mapping == eMapping.Terrain) FileName = $"{XPath}\\{longitude}.png"; else /* Get Bing maps */ FileName = $"{XPath}\\{BingQuad}.jpeg"; L4IO.CreateDirectory(XPath); /*----------------------------------------------------------------------------*/ if (File.Exists(FileName)) { Bmp = GetBitmapFromFile(FileName); return(Bmp); } /*----------------------------------------------------------------------------*/ if (!InternetConnected) /* No Internet connection so don't try to get image */ return(null); URL = GetURL(longitude, latitude, zoom, BingQuad, mapping); WClient = new WebClient(); WClient.DownloadFile(URL, FileName); WClient.Dispose(); Bmp = (Bitmap)Image.FromFile(FileName); return(Bmp); } catch//(Exception ex) { return(null); } finally { } } /******************************************************************************* Function : GetBitmapFromFile() Description : Parameters : string fileName - : out Bitmap bmp - Returns : Bitmap -------------------------------------------------------------------------------- History: 2019/04/25 WLM Created *******************************************************************************/ Bitmap GetBitmapFromFile(string fileName) { try { return((Bitmap)Bitmap.FromFile(fileName)); } catch { return(null); } } } /* End Of Class clsMap */ } /* End Of NameSpace nsL4Sonar */
LoadFile.cs
/******************************************************************************* File : LoadFile.cs Description : -------------------------------------------------------------------------------- Functions: -------------------------------------------------------------------------------- History: 2014/03/26 WLM Created *******************************************************************************/ using System; using System.IO; namespace nsL4Util { /******************************************************************************* Class : L4IniFile Description : -------------------------------------------------------------------------------- History: 2014/03/26 WLM Created *******************************************************************************/ public partial class L4IniFile { /******************************************************************************* Function : LoadFile() Description : Read Entire .Ini File Parsing Into Items Collection Parameters : None Returns : bool -------------------------------------------------------------------------------- History: 2008/09/15 WLM Fixed Comment on first char (whole line commented out) 2010/08/31 WLM Fix for = in Value section 2010/11/23 WLM Added Header Loading *******************************************************************************/ bool LoadFile() { TextReader Reader; string Str, Section, Key, Value; int Idx, Idx2; bool DoingHeader; Items.Clear(); Reader = null; try { Reader = new StreamReader(FileName); Section = ""; DoingHeader = true; while((Str = Reader.ReadLine()) != null) { Key = ""; Value = ""; Str = Str.Trim(); Idx = Str.IndexOf(';'); /* Drop Any Comments */ if (Idx == 0) /* Whole Line Is Commented */ { if (DoingHeader) Header.AppendLine(Str); continue; } if (Idx != -1) Str = Str.Substring(0, Idx - 1).Trim(); if (Str.Length < 1) { if (DoingHeader) Header.AppendLine(Str); continue; } DoingHeader = false; if (Str[0] == '[') /* Found Section */ Section = Str.Substring(1, Str.Length - 2); else { Idx2 = Str.IndexOf('='); if (Idx2 != -1) { Key = Str.Substring(0, Idx2).Trim(); Value = Str.Substring(Idx2 + 1).Trim(); Add(Section, Key, Value); } } } Reader.Close(); } catch (Exception ex) { if (Reader != null) Reader.Close(); L4Message.Show("ERROR - Load()\n" + ex.Message); L4Logging.Log(eLoggingLevel.Error, "L4IniFile", "Load()", ex); return(false); } return(true); } } /* End Of Class L4IniFile */ } /* End Of NameSpace nsL4Util */
Database Insert
/******************************************************************************* File : Insert.cs Description : -------------------------------------------------------------------------------- Functions: -------------------------------------------------------------------------------- History: 2017/04/21 WLM Created *******************************************************************************/ using System; using System.Collections.Generic; using MySql.Data.MySqlClient; namespace nsL4DB { /******************************************************************************* Class : clsSonarMasterFile Description : -------------------------------------------------------------------------------- History: 2017/04/21 WLM Created *******************************************************************************/ public partial class clsSonarMasterFile { /******************************************************************************* Function : Insert() Description : Parameters : stSonarFile sonarFile - : out int newID - : out string errMsg - Returns : bool -------------------------------------------------------------------------------- History: 2017/04/21 WLM Created *******************************************************************************/ public bool Insert(stSonarMasterFile sonarMasterFile, out int newID, out string errMsg) { string SqlQuery; List<MySqlParameter> SqlParms; newID = 0; try { SqlQuery = @" INSERT INTO tblSonarMasterFile ( GUID, TimeStamp, Email, TmpDirectory ) VALUES ( @GUID, @TimeStamp, @Email, @TmpDirectory ); "; /*----------------------------------------------------------------------------*/ SqlParms = new List<MySqlParameter>(); SqlParms.Add(new MySqlParameter("GUID", sonarMasterFile.GUID)); SqlParms.Add(new MySqlParameter("TimeStamp", sonarMasterFile.TimeStamp)); SqlParms.Add(new MySqlParameter("Email", sonarMasterFile.Email)); SqlParms.Add(new MySqlParameter("TmpDirectory", sonarMasterFile.TmpDirectory)); if (!L4DB.DBInfo.ExecuteQuery(SqlQuery, SqlParms, out newID, out errMsg)) return(false); return(true); } catch (Exception ex) { errMsg = $"SonarMasterFile.Insert() - Exception Occurred\n{ex.Message}"; return(false); } } } /* End Of Class clsSonarMasterFile */ } /* End Of NameSpace nsL4DB */
Database Get
/******************************************************************************* File : Get.cs Description : -------------------------------------------------------------------------------- Functions: -------------------------------------------------------------------------------- History: 2017/04/21 WLM Created *******************************************************************************/ using System; namespace nsL4DB { /******************************************************************************* Class : clsSonarMasterFile Description : -------------------------------------------------------------------------------- History: 2017/04/21 WLM Created *******************************************************************************/ public partial class clsSonarMasterFile { /******************************************************************************* Function : Get() Description : Parameters : int id - : stSonarMasterFile sonarMasterFile - : out string errMsg - Returns : bool -------------------------------------------------------------------------------- History: 2017/04/21 WLM Created *******************************************************************************/ public bool Get(int id, stSonarMasterFile sonarMasterFile, out string errMsg) { string SqlQuery; errMsg = ""; try { SqlQuery = string.Format( @" SELECT GUID, TimeStamp, Email, TmpDirectory FROM tblSonarMasterFile WHERE ID = {0} ", id); /*----------------------------------------------------------------------------*/ if (!L4DB.DBInfo.OpenReader(SqlQuery, out errMsg)) return(false); if (L4DB.DBInfo.Read()) { sonarMasterFile.ID = id; sonarMasterFile.GUID = L4DB.DBInfo.GetString("GUID"); sonarMasterFile.TimeStamp = (DateTime)L4DB.DBInfo.GetDateTime("TimeStamp"); sonarMasterFile.Email = L4DB.DBInfo.GetString("Email"); sonarMasterFile.TmpDirectory = L4DB.DBInfo.GetString("TmpDirectory"); } return(true); } catch (Exception ex) { errMsg = string.Format("SonarMasterFile.Get() - Exception Occurred\n{0}", ex.Message); return(false); } } } /* End Of Class clsSonarMasterFile */ } /* End Of NameSpace nsL4DB */
Database Update
/******************************************************************************* File : Update.cs Description : -------------------------------------------------------------------------------- Functions: -------------------------------------------------------------------------------- History: 2017/06/22 WLM Created *******************************************************************************/ using System; using System.Collections.Generic; using MySql.Data.MySqlClient; namespace nsL4DB { /******************************************************************************* Class : clsLicense Description : -------------------------------------------------------------------------------- History: 2017/06/22 WLM Created *******************************************************************************/ public partial class clsLicense { /******************************************************************************* Function : Update() Description : Parameters : stLicense license - : out string errMsg - Returns : bool -------------------------------------------------------------------------------- History: 2017/06/22 WLM Created *******************************************************************************/ public bool Update(stLicense license, out string errMsg) { string SqlQuery; List<MySqlParameter> SqlParms; int Cnt; try { SqlQuery = string.Format( @" UPDATE tblLicense SET FirstName = @FirstName, LastName = @LastName, Email = @Email, Date = @Date WHERE GUID = '{0}' ", license.GUID); SqlParms = new List<MySqlParameter>(); SqlParms.Add(new MySqlParameter("FirstName", license.FirstName)); SqlParms.Add(new MySqlParameter("LastName", license.LastName)); SqlParms.Add(new MySqlParameter("Email", license.Email)); SqlParms.Add(new MySqlParameter("Date", license.Date)); if (!L4DB.DBInfo.ExecuteNonQuery(SqlQuery, SqlParms, out Cnt, out errMsg)) return(false); if (Cnt != 1) { errMsg = $"License.Update() - Error updating Instance.ID {license.GUID}"; return(false); } return(true); } catch (Exception ex) { errMsg = $"License.Update() - Exception Occurred\n{ex.Message}"; return(false); } } } /* End Of Class clsLicense */ } /* End Of NameSpace nsL4DB */
