C# MessageBox not working - c#

I've been working on this for a project and the messagebox not showing
Could someone please help me?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MaterialSkin.Controls;
using MaterialSkin.Animations;
using MaterialSkin;
using System.Web;
using System.Net;
using System.IO;
using System.Management;
using System.Windows;
namespace Liquid_Reborn
{
public partial class Login : MaterialForm
{
public Login()
{
InitializeComponent();
var materialSkinManager = MaterialSkinManager.Instance;
materialSkinManager.AddFormToManage(this);
materialSkinManager.Theme = MaterialSkinManager.Themes.LIGHT;
materialSkinManager.ColorScheme = new ColorScheme(Primary.LightBlue200, Primary.LightBlue300, Primary.LightBlue300, Accent.LightBlue200, TextShade.WHITE);
}
private void Form1_Load(object sender, EventArgs e)
{
string cpuInfo = string.Empty;
ManagementClass mc = new ManagementClass("win32_processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if (cpuInfo == "")
{
//Get only the first CPU's ID
cpuInfo = mo.Properties["processorID"].Value.ToString();
break;
}
var plainTextBytes = Encoding.UTF8.GetBytes(cpuInfo);
String hwid = Convert.ToBase64String(plainTextBytes);
WebClient client = new WebClient();
Stream stream = client.OpenRead("http://techshow.us/liquid/hwid.txt/");
StreamReader reader = new StreamReader(stream);
String content = reader.ReadToEnd();
if (content.Contains(hwid))
{
}
MessageBox.Show("ok");
}
}
}
}
why doesnt the messagebox display?
ive tried most things and none work
Nothing happens the ui just shows and idk what to do\
please help me i need this for my project

if (cpuInfo == "") will always be true because the value doesn't change after initializing. The loop breaks before the MessageBox code is reached.
Remove break; to allow the code to continue, or
Use continue; instead to skip to the next value in the loop.

Related

RTSP Streaming in Microsoft Dynamics Nav 2016 using Control add In

I am trying to do rtsp streaming in Nav 2016 using control add in using VLC player for dotnet. The control gets added on Nav page but i am not able to stream video from IP camera. The same code works fine on windows application but it does not work in Nav. Here is my sample code. please help me if i am doing anything wrong here.
using System;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Dynamics.Framework.UI.Extensibility;
using Microsoft.Dynamics.Framework.UI.Extensibility.WinForms;
using System.Text.RegularExpressions;
using System.IO.Ports;
using WebEye.Controls.WinForms.StreamPlayerControl;
using Vlc.DotNet.Forms;
namespace WeighControl
{
[ControlAddInExport("CamControl")]
public class CamControl : WinFormsControlAddInBase
{
private VlcControl streamCam1;
private delegate void myDelegate(string str);
[ApplicationVisible]
public event MethodInvoker CamControlAddInReady;
[ApplicationVisible]
public void ShowCameraControl()
{
ShowCamera();
}
public CamControl()
{
}
private void ShowCamera()
{
try
{
streamCam1.Play(new Uri("rtsp://admin:admin#192.168.0.171/"));
}
catch(Exception ex)
{
}
}
protected override Control CreateControl()
{
streamCam1 = new VlcControl();
this.streamCam1.AutoSize = true;
this.streamCam1.BackColor = System.Drawing.Color.Black;
this.streamCam1.Spu = -1;
this.streamCam1.ForeColor = System.Drawing.Color.Black;
this.streamCam1.Location = new System.Drawing.Point(1, 416);
this.streamCam1.Margin = new System.Windows.Forms.Padding(2);
this.streamCam1.Name = "streamCam1";
string path = #"C:\Program Files\VideoLAN\VLC";
System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(path);
this.streamCam1.VlcLibDirectory = directoryInfo;
this.streamCam1.VlcMediaplayerOptions = null;
this.streamCam1.Size = new System.Drawing.Size(540, 226);
this.streamCam1.TabIndex = 2198;
streamCam1.HandleCreated += (sender, args) =>
{
if (CamControlAddInReady != null)
{
CamControlAddInReady();
}
};
return streamCam1;
}
}
}

c# How to have user select folder and then enter

I am fairly new to C# so i don't know how to attack this problem. I have this code, that generates the form so a pop up box comes up and lets you select the folder the user wants to select. The problem is that after its selected it doesn't give an option to hit enter or hit ok so that the rest of my code can use that folder as a path to execute the remainder of what i want to do.
This is the code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using System.IO;
namespace FolderBrowserDialogSampleInCSharp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void BrowseFolderButton_Click(object sender, EventArgs e)
{
FolderBrowserDialog folderDlg = new FolderBrowserDialog();
folderDlg.ShowNewFolderButton = true;
// Show the FolderBrowserDialog.
DialogResult result = folderDlg.ShowDialog();
if (result == DialogResult.OK)
{
textBox1.Text = folderDlg.SelectedPath;
Environment.SpecialFolder root = folderDlg.RootFolder;
var dir = textBox1.Text;
File.SetAttributes(dir, FileAttributes.Normal);
string[] files = Directory.GetFiles(dir, "*.pdf");
IEnumerable<IGrouping<string, string>> groups = files.GroupBy(n => n.Split('.')[0].Split('_')[0]);
foreach (var items in groups)
{
Console.WriteLine(items.Key);
PdfDocument outputPDFDocument = new PdfDocument();
foreach (var pdfFile in items)
{
Merge(outputPDFDocument, pdfFile);
}
if (!Directory.Exists(dir + #"\Merge"))
Directory.CreateDirectory(dir + #"\Merge");
outputPDFDocument.Save(Path.GetDirectoryName(items.Key) + #"\Merge\" + Path.GetFileNameWithoutExtension(items.Key) + ".pdf");
}
Console.ReadKey();
}
}
private static void Merge(PdfDocument outputPDFDocument, string pdfFile)
{
PdfDocument inputPDFDocument = PdfReader.Open(pdfFile, PdfDocumentOpenMode.Import);
outputPDFDocument.Version = inputPDFDocument.Version;
foreach (PdfPage page in inputPDFDocument.Pages)
{
outputPDFDocument.AddPage(page);
}
}
}
}
What generates the form to come is :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace FolderBrowserDialogSampleInCSharp
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
I'm assuming that i either have to add in a button in the form design as "enter" or "ok."
Could i just have this so that as soon as the user selects the folder and hits ok the program proceeds to store that as the user selected path?
The answer i was searching for:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using System.IO;
namespace FolderBrowserDialogSampleInCSharp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void BrowseFolderButton_Click(object sender, EventArgs e)
{
FolderBrowserDialog folderDlg = new FolderBrowserDialog();
folderDlg.ShowNewFolderButton = true;
// Show the FolderBrowserDialog.
DialogResult result = folderDlg.ShowDialog();
if (result == DialogResult.OK)
{
textBox1.Text = folderDlg.SelectedPath;
Environment.SpecialFolder root = folderDlg.RootFolder;
var dir = textBox1.Text;
File.SetAttributes(dir, FileAttributes.Normal);
string[] files = Directory.GetFiles(dir, "*.pdf");
IEnumerable<IGrouping<string, string>> groups = files.GroupBy(n => n.Split('.')[0].Split('_')[0]);
foreach (var items in groups)
{
Console.WriteLine(items.Key);
PdfDocument outputPDFDocument = new PdfDocument();
foreach (var pdfFile in items)
{
Merge(outputPDFDocument, pdfFile);
}
if (!Directory.Exists(dir + #"\Merge"))
Directory.CreateDirectory(dir + #"\Merge");
outputPDFDocument.Save(Path.GetDirectoryName(items.Key) + #"\Merge\" + Path.GetFileNameWithoutExtension(items.Key) + ".pdf");
}
Console.Read();
Close();
}
}
private static void Merge(PdfDocument outputPDFDocument, string pdfFile)
{
PdfDocument inputPDFDocument = PdfReader.Open(pdfFile, PdfDocumentOpenMode.Import);
outputPDFDocument.Version = inputPDFDocument.Version;
foreach (PdfPage page in inputPDFDocument.Pages)
{
outputPDFDocument.AddPage(page);
}
}
}
}

c# importing excel to datagridview doesn't work

I am using ExcelDataReader here.
I don't know why below code doesn't work.
It doesn't generate any error but it still doesn't show excel data.
It simply doesn't do anything after loading excel file.
I am new to C# and after 5 hours of digging I feel frustrated since I don't know why this doesn't work.
using Excel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class ExcelForm : Form
{
public ExcelForm()
{
InitializeComponent();
}
private void ExcelForm_Load(object sender, EventArgs e)
{
}
DataSet result;
private void btnOpen_Click(object sender, EventArgs e)
{
using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "Excel(.xls)|*.xls|Excel(.xlsx)|*.xlsx", ValidateNames = true })
{
if(ofd.ShowDialog() == DialogResult.OK)
{
FileStream fs = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read);
IExcelDataReader reader;
if (ofd.FilterIndex == 1)
reader = ExcelReaderFactory.CreateBinaryReader(fs);
else
reader = ExcelReaderFactory.CreateOpenXmlReader(fs);
reader.IsFirstRowAsColumnNames = true;
result = reader.AsDataSet();
reader.Close();
dataGridView.DataSource = result;
}
}
}
}
}
dataGridView.DataSource = DtSet.Tables[0];

IMAP searchParse exception?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Web;
using ActiveUp.Net.Mail;
using ActiveUp.Net.Imap4;
namespace imapClient
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Imap4Client client = new Imap4Client();
client.ConnectSsl("imap.gmail.com", 993);
MessageBox.Show("connected!");
client.Login("soham.elf", "********");
MessageBox.Show("signed in!");
Mailbox mail = client.SelectMailbox("INBOX");
//exception thrown here
MessageCollection msgs = mail.SearchParse("ALL");
textBox1.Text = msgs.Count.ToString();
}
}
}
Expection:"Index and length must refer to a location within the string.
Parameter name: length"
I am trying to test the IMAP client; I'm just starting with it. I am using mailsystem.NET. What's wrong with my code?
Try use Phrases like that document: http://www.limilabs.com/blog/imap-search-requires-parentheses
private void SearchFromTest()
{
try
{
var _selectedMailBox = "INBOX";
var _searchWithEmailFrom = "email#domain.com";
using (var _clientImap4 = new Imap4Client())
{
_clientImap4.ConnectSsl(_imapServerAddress, _imapPort);
//_clientImap4.Connect(_mailServer.address, _mailServer.port);
_clientImap4.Login(_imapLogin, _imapPassword); // Efetua login e carrega as MailBox da conta.
//_clientImap4.LoginFast(_imapLogin, _imapPassword); // Efetua login e não carrega as MailBox da conta.
var _mailBox = _clientImap4.SelectMailbox(_selectedMailBox);
// A0001 SEARCH CHARSET utf-8 BODY "somestring" OR TO "someone#me.com" FROM "someone#me.com"
var searchPhrase = "CHARSET utf-8 FROM \"" + _searchWithEmailFrom + "\"";
foreach (var messageId in _mailBox.Search(searchPhrase).AsEnumerable())
{
var message = _mailBox.Fetch.Message(messageId);
var _imapMessage = Parser.ParseMessage(message);
}
_clientImap4.Disconnect();
}
Assert.IsTrue(true);
}
catch (Exception e)
{
Assert.Fail("Don't work.", e);
}
}

How can I use open hardware monitor source code in c# ? I tried anything doesn't work

I have this code in Form1:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OpenHardwareMonitor.Hardware.HDD;
using OpenHardwareMonitor;
namespace OpenHardwareMonitor
{
public partial class Form1 : Form
{
OpenHardwareMonitor.Hardware.SensorValue sv;
OpenHardwareMonitor.Hardware.ISensor ii;
public Form1()
{
InitializeComponent();
string y = ii.Name;
sv = new Hardware.SensorValue();
DateTime dt = sv.Time;
float t = sv.Value;
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
ii variable is null I don't know how to make an instance for it.
The other two variables in the constructor return 0 nothing. If I'm not using the ii variable the other two don't throw an error but don't return any values.
I'm using the openhardwaremonitor dll from http://code.google.com/p/open-hardware-monitor/downloads/detail?name=openhardwaremonitor-v0.4.0-beta.zip&can=2&q=
The c# dll is coming with the program it self.
So I added as reference the dll but I don't know how to make the code.
Could someone build for me just an example of the code according to my code here ?
I tried to look in the openhwardwaremonitor site and source code there and didn't understand how to use it.
What else can I do ?
Thanks.
I've tested this code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OpenHardwareMonitor;
using OpenHardwareMonitor.Hardware;
namespace CPUTemperatureMonitor
{
public partial class Form1 : Form
{
Computer thisComputer;
public Form1()
{
InitializeComponent();
thisComputer = new Computer() { CPUEnabled = true };
thisComputer.Open();
}
private void timer1_Tick(object sender, EventArgs e)
{
String temp = "";
foreach (var hardwareItem in thisComputer.Hardware)
{
if (hardwareItem.HardwareType == HardwareType.CPU)
{
hardwareItem.Update();
foreach (IHardware subHardware in hardwareItem.SubHardware)
subHardware.Update();
foreach (var sensor in hardwareItem.Sensors)
{
if (sensor.SensorType == SensorType.Temperature)
{
temp += String.Format("{0} Temperature = {1}\r\n", sensor.Name, sensor.Value.HasValue ? sensor.Value.Value.ToString() : "no value");
}
}
}
}
textBox1.Text = temp;
}
}
}
The form has a multiline text control and a timer. Add a reference to OpenHardwareMonitorLib.dll.
You also need to request a higher execution level in the application, i.e. right click on the project, add a new manifest file item and declare
requestedExecutionLevel level="highestAvailable" uiAccess="false"

Categories

Resources