I am trying to "learn" C# and building my 1st database driven data entry application. I am coming from Oracle development, hence wondering whether am doing few things right, as most of the examples I could find are dealing with datasets derived using SQL
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;
namespace lSystem
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void l_PEOPLEBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
if ((string.IsNullOrWhiteSpace(fIRST_NAMETextBox.Text) || (string.IsNullOrWhiteSpace(cIVIL_IDTextBox.Text) ||
(string.IsNullOrWhiteSpace(tELEPHONE_NUMBERTextbox.Text)))))
{
MessageBox.Show("Error, one of the mandatory columns are not filled up");
return;
}
try
{
this.Validate();
this.pERSON_IDTextBox.Text = this.l_PEOPLETableAdapter.ScalarQuery().ToString();
this.l_PEOPLEBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.uNUDataSet);
}
catch (Exception ex)
{
MessageBox.Show("Exception happened, original message: " + ex.Message);
}
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'uNUDataSet.L_PEOPLE' table. You can move, or remove it, as needed.
this.l_PEOPLETableAdapter.Fill(this.uNUDataSet.L_PEOPLE);
// this.fIRST_NAMETextBox.Focus();
this.ActiveControl = this.fIRST_NAMETextBox;
}
private void sByName_Click(object sender, EventArgs e)
{
this.l_PEOPLETableAdapter.FillByNAME(this.uNUDataSet.L_PEOPLE, this.sByNameText.Text);
}
private void fIRST_NAMETextBox_Validated(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(fIRST_NAMETextBox.Text))
{
eNROLL_errorprovider.SetError(fIRST_NAMETextBox, "Name required");
fIRST_NAMETextBox.Focus();
}
}
private void cIVIL_IDTextBox_Validated(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(cIVIL_IDTextBox.Text))
{
eNROLL_errorprovider.SetError(cIVIL_IDTextBox, "Civil ID Number required");
cIVIL_IDTextBox.Focus();
}
}
private void tELEPHONE_NUMBERTextbox_Validated(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(tELEPHONE_NUMBERTextbox.Text))
{
eNROLL_errorprovider.SetError(tELEPHONE_NUMBERTextbox, "Telephone Number required");
tELEPHONE_NUMBERTextbox.Focus();
}
else
{
eNROLL_errorprovider.Clear();
}
}
}
}
What I am trying to do with the above piece of code is, unless the user enters first name, civil id number and supply the telephone number, the form shouldn't submit the data. For the person id, I am using a sequence, called through a scalar query attached to the table adaptor.
While I click the binding navigator save button, what should execute in order to fire the validation events attached with the text columns so that the error provider will get activated?
You need to register the event like the code below
public Form1()
{
InitializeComponent();
tELEPHONE_NUMBERTextbox.Validated += new EventHandler(tELEPHONE_NUMBERTextbox_Validated);
}
private void tELEPHONE_NUMBERTextbox_Validated(object sender, EventArgs e)
{
}
Related
I'm trying to grab a list of all of my Skype friends who are online and put it into my listbox named lst1.
I'm also trying to make my tool answer to some commands like if some one sends !news to me it messages them a text that I've set in the code.
This is what I've tried so far, I'm just playing around with the code to learn how to use skype4comlib.
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 MetroFramework;
using MetroFramework.Forms;
using MetroFramework.Components;
using SKYPE4COMLib;
using System.Threading;
namespace betaskypetool
{
public partial class Form1 : MetroForm
{
#region Definitions
Skype Merk = new Skype();
private int count = 1;
#endregion
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void metroButton1_Click(object sender, EventArgs e)
{
try
{
this.Merk.Attach(5, true);
MessageBox.Show("You are now connected enjoy!", "Tutorial Skype Tool!");
}
catch (Exception)
{
MessageBox.Show("Failed To Connect?\n Be Sure Skype Is Open!", "Tutorial Skype Tool!");
}
}
private void metroButton2_Click(object sender, EventArgs e)
{
this.Merk.CurrentUserStatus = TUserStatus.cusOnline;
}
private void metroButton3_Click(object sender, EventArgs e)
{
this.Merk.CurrentUserStatus = TUserStatus.cusDoNotDisturb;
}
private void metroButton4_Click(object sender, EventArgs e)
{
this.Merk.CurrentUserStatus = TUserStatus.cusAway;
}
private void metroButton5_Click(object sender, EventArgs e)
{
this.Merk.CurrentUserStatus = TUserStatus.cusInvisible;
}
private void metroButton6_Click(object sender, EventArgs e)
{
this.Merk.CurrentUserStatus = TUserStatus.cusOffline;
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if(checkBox1.Checked == true)
{
timer1.Start();
}
else
{
timer1.Stop();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
this.Merk.CurrentUserStatus = TUserStatus.cusOnline;
Thread.Sleep(20);
this.Merk.CurrentUserStatus = TUserStatus.cusAway;
Thread.Sleep(20);
this.Merk.CurrentUserStatus = TUserStatus.cusDoNotDisturb;
Thread.Sleep(20);
this.Merk.CurrentUserStatus = TUserStatus.cusInvisible;
Thread.Sleep(20);
}
private void metroButton7_Click(object sender, EventArgs e)
{
foreach(User spamall in Merk.Friends)
{
Merk.SendMessage(spamall.Handle, "Haiiiii" + spamall.FullName + ",\n" + richTextBox1.Text + "\n\n(cash) Sent From Merk's Tutorial Tool! (cash)");
}
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
I hope you understand my question and can help me out with what I need to do to add those 2 features to my project
You can get a collection of your online friends like this:
var onlineFriends = Merk.Friends.Cast<User>().Where(u => u.OnlineStatus == TOnlineStatus.olsOnline);
After this it's easy to put them in a ListBox.
WPF example:
foreach (var friend in onlineFriends)
{
MyListBox.Items.Add(friend.FullName);
}
That said, I'm not sure if it's worth to spend a lot of time learning it, because according to this blog post, Microsoft doesn't really support skype4comlib anymore.
https://support.skype.com/en/faq/FA12384/how-does-my-3rd-party-application-work-with-skype-and-how-will-changes-to-skype-impact-my-3rd-party-application
As communicated in this blog post, due to technology improvements we are making to the Skype experience, some features of the API will stop working with Skype for desktop. For example, delivery of chat messages using the API will cease to work.
For example, I'm not able to send a message using the library anymore.
PS.: I'm using Skype 7.17.0.106
hey i wrote below code to send my datagridview value seleted row to another form but i got this error my event is double content click and i dont know why this happened
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
using System.Windows.Forms;
namespace WindowsFormsApplication12
{
public partial class Form5 : Form
{
public Form5()
{
InitializeComponent();
}
private void Form5_Load(object sender, EventArgs e)
{
tblClassTableAdapter.Fill(dataSet1.tblClass);
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
this.tblClassTableAdapter.FillBy1(this.dataSet1.tblClass, textBox1.Text);
}
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
new Form6(int.Parse(dataGridView1.SelectedRows[0].Cells[0].Value.ToString())).Show();
}
}
and my form 6
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;
namespace WindowsFormsApplication12
{
public partial class Form6 : Form
{
int classid;
private string p;
public Form6(int myid)
{
classid = myid;
InitializeComponent();
}
public Form6(string p)
{
// TODO: Complete member initialization
this.p = p;
}
public void Form6_Load(object sender, EventArgs e)
{
textBox1.Text = classid.ToString();
}
public DataGridViewRow dataGridViewRow { get; set; }
}
}
thank you guys for helping
DataGridViewCellEventArgs has two important args for you:
e.rowIndex, e.columnIndex which specifying in which cell you pressed.
By the way, you are trying to parse Int from cell, surround it with try/catch for case the parse fails.
try this code instead:
try {
if (e.ColumnIndex > -1 && e.RowIndex > -1)
new Form6(int.Parse(dataGridView1[e.ColumnIndex,e.RowIndex].Value.ToString())).Show();
}
catch (Exception ex) {
MessageBox.Show("Error: " + ex.Message);
}
I think it should help you, mark as answered if yes.
So, I've got a simple application that needs to view, insert, update, and delete data from an access db file by using the DataGrid tool in Visual Studio 2012. Upon initial load, my database loaded fine, and to my knowledge it is a bound data source:
I used an Access DB table called lawyers and created a binding data source called lawyerBindingSource attached to my lawyerGridView inside of my LawyerForm.
The problem is that when I relaunch my application, the newly inserted data does not refresh within my GridView. I've read similar stackoverflow questions on this topic, but have yet to find a solution. Please help! Here is my form code:
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;
namespace NewcomerAndAssociatesSystem
{
public partial class Lawyers : Form
{
public Lawyers()
{
InitializeComponent();
}
private void Lawyers_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'seniorProjectDb1DataSet.LawOffice' table. You can move, or remove it, as needed.
this.lawOfficeTableAdapter.Fill(this.seniorProjectDb1DataSet.LawOffice);
// TODO: This line of code loads data into the 'seniorProjectDb1DataSet.Lawyer' table. You can move, or remove it, as needed.
this.lawyerTableAdapter.Fill(this.seniorProjectDb1DataSet.Lawyer);
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void lawyerReturnMain_Click(object sender, EventArgs e)
{
new MainForm().Show();
this.Hide();
}
private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void fillByToolStripButton_Click(object sender, EventArgs e)
{
try
{
this.lawyerTableAdapter.FillBy(this.seniorProjectDb1DataSet.Lawyer);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
private void fillByToolStripButton1_Click(object sender, EventArgs e)
{
try
{
this.lawOfficeTableAdapter.FillBy(this.seniorProjectDb1DataSet.LawOffice);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
private void lawyersQueryToolStripButton_Click(object sender, EventArgs e)
{
try
{
this.lawyerTableAdapter.lawyersQuery(this.seniorProjectDb1DataSet.Lawyer);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
private void lawyerBindingSource_CurrentChanged(object sender, EventArgs e)
{
}
}
}
When the application is running, then the newly insterted/updated data is displayed correctly?
It's when you shutdown the application the changes are lost?
If so, that's probably because the database is overwritten again.
Check this thread for more info:
Why does "Copy if newer" not copy a file when the file is updated?
You need to use Update TableAdapter Method to save data in Db other than in your grid:
this.lawOfficeTableAdapter.Update(this.seniorProjectDb1DataSet.LawOffice);
this.lawyerTableAdapter.Update(this.seniorProjectDb1DataSet.Lawyer);
I'm creating a custom internet browser in c# using the webbrowser control.
And it works i can load sites and browse around and all that.
But with some sites (with alot of pictures and such) he wont put everything in the right spot so i will get text blocks inside images and vice versa.
How do i solve this ?
My 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;
namespace WindowsFormsApplication13
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
WB1.Navigate("http://nos.nl");
}
private void GoBtn_Click(object sender, EventArgs e)
{
if (AddRsBsr.Text.StartsWith("http://"))
{
WB1.Navigate(AddRsBsr.Text);
}
else if (AddRsBsr.Text.StartsWith("https://"))
{
WB1.Navigate(AddRsBsr.Text);
}
else
{
WB1.Navigate("http://www.googl.com/search?q=" + AddRsBsr.Text);
}
}
private void AddRsBsr_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Return)
{
if (AddRsBsr.Text.StartsWith("http://"))
{
WB1.Navigate(AddRsBsr.Text);
}
else if (AddRsBsr.Text.StartsWith("https://"))
{
WB1.Navigate(AddRsBsr.Text);
}
else
{
WB1.Navigate("http://www.googl.com/search?q=" + AddRsBsr.Text);
}
}
}
private void BackBtn_Click(object sender, EventArgs e)
{
WB1.GoBack();
}
private void StopBtn_Click(object sender, EventArgs e)
{
WB1.Stop();
}
private void HomeBtn_Click(object sender, EventArgs e)
{
WB1.Navigate("http://google.nl");
}
}
}
Now i know my code isn't clean and all but im doing that right now while waiting and hoping for an answer.
Thanks !
The WebBrowser component defaults to rendering in ... IE7 mode.
To have it behave as IE10/11 you need to make the registry changed described here (FEATURE_BROWSER_EMULATION): http://msdn.microsoft.com/en-us/library/ie/ee330730(v=vs.85).aspx
I have created a database in microsoft office access. In form1.cs i added a DataGridView with the source from the database created. In tableDataSet.xsd/tabelAdapter i created a new query with 3 parameters which i use to insert the data in the database ( Name, Password, Age) . how can i use this query with that 3 parameters from 3 different textbox?
PS: i use only Windows Form Application, no asp.net or etc.
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;
namespace lucian
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'jucatoriDataSet.jucator' table. You can move, or remove it, as needed.
this.jucatorTableAdapter.Fill(this.jucatoriDataSet.jucator);
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void adaugareToolStripButton_Click(object sender, EventArgs e)
{
try
{
this.jucatorTableAdapter.Fill(this.jucatoriDataSet.jucator);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
Take a look at that article http://msdn.microsoft.com/en-us/magazine/cc163709.aspx
Basically you need to learn about ADO.NET :)