|
Who write this code ask to him...
|
|
|
|
|
Finds an item in the tab control with a matching ID value, and sets it as the selected tab item.
It relies on you having set the appropriate ID value into the Tag property of each TabItem when you created it, however.
And in future, please ask WPF queries in the WPF forum: http://www.codeproject.com/Forums/1004257/Silverlight-WPF.aspx[^]
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Please do not cross post.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I created the ff: code to insert a new record in database but the problem is it didn't add a new record in my database...
ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\memberInfo.mdf;Integrated Security=True;User Instance=True";
SqlConnection conn = new SqlConnection(ConnectionString);
String insertCommand = @"INSERT INTO members
(m_id, fname, mname, lname, pres_add, p_add_con, h_add, h_add_con, office_add, off_add_con, proff_occ,
spez, d_birth, p_birth, age, sex, c_status, d_marriage, citizenship, h_educ_att,
h_educ_school, stud_school, stud_year, stud_course, spec_skills, bld_type, w_ser_att,
mem_status, church_org_mem, comm_sugg)
VALUES(
@m_id, @fname, @mname, @lname, @pres_add, @p_add_con, @h_add, @h_add_con, @office_add, @off_add_con, @proff_occ,
@spez, @d_birth, @p_birth, @age, @sex, @c_status, @d_marriage, @citizenship, @h_educ_att,
@h_educ_school, @stud_school, @stud_year, @stud_course, @spec_skills, @bld_type, @w_ser_att,
@mem_status, @church_org_mem, @comm_sugg
)";
conn.Open();
SqlCommand cmd = new SqlCommand(insertCommand, conn);
cmd.Parameters.AddWithValue("@m_id", txtMem_id.Text);
cmd.Parameters.AddWithValue("@fname", txtFname.Text);
cmd.Parameters.AddWithValue("@mname", txtMiddlename.Text);
cmd.Parameters.AddWithValue("@lname", txtLastname.Text);
cmd.Parameters.AddWithValue("@pres_add", txtPresAdd.Text);
cmd.Parameters.AddWithValue("@p_add_con", txtPressAddCon.Text);
cmd.Parameters.AddWithValue("@h_add", txtHomeAdd.Text);
cmd.Parameters.AddWithValue("@h_add_con", txtHomeAddCon.Text);
cmd.Parameters.AddWithValue("@office_add", txtOffAdd.Text);
cmd.Parameters.AddWithValue("@off_add_con", txtOffAddCon.Text);
cmd.Parameters.AddWithValue("@proff_occ", txtOffOcc.Text);
cmd.Parameters.AddWithValue("@spez", txtSpez.Text);
cmd.Parameters.AddWithValue("@d_birth", dtpBirthdate.Text);
cmd.Parameters.AddWithValue("@p_birth", txtBirthPlace.Text);
cmd.Parameters.AddWithValue("@age", txtAge.Text);
cmd.Parameters.AddWithValue("@sex", cmb_sex.SelectedIndex);
cmd.Parameters.AddWithValue("@c_status", cmb_CivilStatus.SelectedIndex);
cmd.Parameters.AddWithValue("@d_marriage", txtDateMarr.Text);
cmd.Parameters.AddWithValue("@citizenship", txtCitizenship.Text);
cmd.Parameters.AddWithValue("@h_educ_att", txtHighEducAtt.Text);
cmd.Parameters.AddWithValue("@h_educ_school", txtHighEducAttSchool.Text);
cmd.Parameters.AddWithValue("@stud_school", txtStudSchool.Text);
cmd.Parameters.AddWithValue("@stud_year", txtStudYear.Text);
cmd.Parameters.AddWithValue("@stud_course", txtStudCourse.Text);
cmd.Parameters.AddWithValue("@spec_skills", txtSpecSkill.Text);
cmd.Parameters.AddWithValue("@bld_type", txtBldtype.Text);
cmd.Parameters.AddWithValue("@w_ser_att", cmb_worSerAtt.SelectedIndex);
cmd.Parameters.AddWithValue("@mem_status", cmb_MemStatus.SelectedIndex);
cmd.Parameters.AddWithValue("@church_org_mem", cmb_memChurchOrg.SelectedIndex);
cmd.Parameters.AddWithValue("@comm_sugg", txtCommSugg.Text);
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("Data Saved");
|
|
|
|
|
...and the error message would be ...... ?? (Hint: REALLY helpful!)
A couple of glaring things stand out in your code. The first is that you're using textbox values directly in your SQL parameters without any validation or normalization. This is just going to lead to your database containing a ton of junk data.
The second is that you may be trying to insert a value into an autonumbered field, m_id. If the field is autonumbered in your database, you can't put a value in that column yourself, so you should delete that field from your INSERT statement.
|
|
|
|
|
Probably inserting strings into date fields. You need to do some parsing of the text fields and ToString().
|
|
|
|
|
hi,
I wrote a chat program with private and public chat,but i have a problem,for example when one user want to have a private chat with other,his first message send to server not to specific user and other messages send for all users that ON now,
Now I want to close the public chat server connection with this user,because the program i wrote in private form can be server and client.
In client program I have one form that has 2 buttons and one datagridview, one button is for "private chat" and other is for "public",the datagridview shows friends.when i click "public chat" button i go to Public form that has one "send button" and 2 text boxes one is "txtMessage" and other is"textbox2".Now my "send button" code is :
try
{
if (connectionstatus)
{
string TimeOfConnect = " Connected at :" + ConectTime;
string firstmessage = label2.Text.Trim();
byte[] buffer = PadMessage(string.Format("{0} {1}", firstmessage, TimeOfConnect));
server.Send(buffer, 0, MessageLength, SocketFlags.None);
connectionstatus = false;
}
else
{
byte[] buffer = PadMessage(string.Format("{0} : {1}", label2.Text.Trim(), txtMessage.Text));
server.Send(buffer, 0, MessageLength, SocketFlags.None);
textBox2.Text += string.Format("Me : {0}\r\n", txtMessage.Text);
txtMessage.Text = "";
txtMessage.Focus();
}
}
catch (Exception)
{
if (!tfconnect)
return;
server.Close();
tRecive.Abort();
server.Close();
if (tfconnect)
RoomForm_Load(sender, e);
txtMessage.Text = "";
}
}
private byte[] PadMessage(string message)
{
while (message.Length < MessageLength)
message += " ";
byte[] buffer = Encoding.ASCII.GetBytes(message);
return buffer;
}
and my form load code is
if (tfconnect)
{
txtMessage.Enabled = false;
Send_btn.Enabled = false;
tfconnect = false;
connectionstatus = false;
try
{
tRecive.Abort();
server.Close();
}
catch { }
}
else
{
DTime = DateTime.Now;
ConectTime = " " + DTime;
string show = label2.Text + "join at" + ConectTime;
// listView1.Items.Add(show);
txtMessage.Enabled = true;
Send_btn.Enabled = true;
txtMessage.Focus();
tfconnect = true;
connectionstatus =true ;
ConectToServer();
button1_Click_1(sender, e);
connectionstatus = false;
}
}
private void ConectToServer()
{
try
{
server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try
{
IPAddress ipAddress = IPAddress.Parse(ServerIPAddress);
server.Connect(ipAddress, ServerPortNo);
}
catch
{
MessageBox.Show("ip can't identified");
}
tRecive = new Thread(new ParameterizedThreadStart(Startclient));
tRecive.Start(server);
}
catch (SocketException)
{
txtMessage.Enabled = false;
Send_btn.Enabled = false;
MessageBox.Show("can't connect to server");
tfconnect = true;
RoomForm_Load(null, null);
return;
}
}
public bool beclose = true;
public void Startclient(object client1)
{
while (beclose)
{
byte[] ReceivedBuffer = new byte[1024];
int a = 0;
try
{
a = ((Socket)client1).Receive(ReceivedBuffer);
if (a == 0)
throw new Exception();
}
catch
{
Thread.CurrentThread.Abort();
((Socket)client1).Close();
RoomForm_Load(null, null);
return;
}
string Data = Encoding.UTF8.GetString(ReceivedBuffer).Replace("\0", "").Trim();
System.Threading.ThreadStart todo = delegate
{
if (Data.Substring(0, 3) != "***")
{
textBox2.Text += string.Format("{0}\r\n", Data);
}
else
{
Form_Load(null, null);
}
};
textBox2.Invoke(todo);
}
}
My server has one button "btnListen"
also My server code is
private void SetButtonEnable(Button btn, bool SetEnabled)
{
System.Threading.ThreadStart todo = delegate
{
btn.Enabled = SetEnabled;
};
btn.Invoke(todo);
}
private void clientListRefresh()
{
try
{
System.Threading.ThreadStart todo = delegate
{
txt_showclients.Text = "";
};
txt_showclients.Invoke(todo);
foreach (var client in clients)
{
System.Threading.ThreadStart todo1 = delegate
{
txt_showclients.Text += client.Value + "\r\n";
};
txt_showclients.Invoke(todo1);
}
}
catch { }
}
private void startServer()
{
while (serverStart)
{
try
{
var client = server.Accept();
// server wait
// get name that client send
byte[] recivedBuffer = new byte[1024];
int testconnection = 0;
try
{
testconnection = client.Receive(recivedBuffer);
if (testconnection == 0)
throw new Exception();
else
{
string data = Encoding.UTF8.GetString(recivedBuffer).Replace("\0", "").Trim();
clients.Add(client, data);
clientListRefresh();
Thread clientThread = new Thread(new ParameterizedThreadStart(clientconnection));
clientThread.Start(client);
}
}
catch (Exception ex)
{
MessageBox.Show("client close");
client.Close();
}
}
catch
{
}
}
}
private void clientconnection(object object1)
{
var client = ((Socket)object1);
while (serverStart)
{
byte[] recivedBuffer = new byte[1024];
int testconnection = 0;
try
{
testconnection = client.Receive(recivedBuffer);
if (testconnection == 0)
throw new Exception();
}
catch (Exception)
{
clients.Remove(client);
client.Close();
if (refreshListIfServerIsStart)
clientListRefresh();
return;
}
string data = Encoding.UTF8.GetString(recivedBuffer).Replace("\0", "").Trim();
Thread broadcastThread = new Thread(new ParameterizedThreadStart(broadCast));
broadcastThread.Start(new object[] { client, data });
}
}
private void broadCast(object object1)
{
var Senderclient = ((Socket)((object[])object1)[0]);
var data = ((string)((object[])object1)[1]);
byte[] broadCastBuffer = padMessage(data);
foreach (var client in clients)
{
if (client.Key.Equals(Senderclient))
continue;
System.Threading.ParameterizedThreadStart breadCastSend = delegate(object clientX)
{
((Socket)clientX).Send(broadCastBuffer, 0, messageLength, SocketFlags.None);
};
new Thread(breadCastSend).Start(client.Key);
}
}
private byte[] padMessage(string message)
{
while (message.Length < messageLength)
message += " ";
byte[] buffer = Encoding.UTF8.GetBytes(message);
return buffer;
}
private void clientsLogout()
{
try
{
string data = "***";
byte[] broadCastBuffer = padMessage(data);
foreach (var client in clients)
{
System.Threading.ParameterizedThreadStart breadCastSend = delegate(object clientX)
{
((Socket)clientX).Send(broadCastBuffer, 0, messageLength, SocketFlags.None);
};
new Thread(breadCastSend).Start(client.Key);
}
}
catch { }
}
private void btnListen_Click(object sender, EventArgs e)
{
refreshListIfServerIsStart = true;
try
{
server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
EndPoint ipendpoint = new IPEndPoint(IPAddress.Parse(serverIP), serverPort);
server.Bind(ipendpoint);
server.Listen(maxConnection);
serverStart = true;
Thread startServerThread = new Thread(new ThreadStart(startServer));
startServerThread.Start();
}
catch { }
SetButtonEnable(btnListen, false);
// SetButtonEnable(btn, true);
txtIp.Enabled = false;
}
Now I want to write Private Chat that use this server,for exp when user want has private chat with one of friends click his name in datagridview and open private chat form,so he can has private chat with that friend,
Now what should i do?
modified 11-Jul-14 5:48am.
|
|
|
|
|
Considering this is an invention of your own and you haven't told us ANYTHING at all about your code, how it works, what you've done to implement this "private chat", or even compared it to how you're doing "public chat", it's pretty much impossible to tell you anything useful.
|
|
|
|
|
What exactly is your question? You dumped a bunch of code that none of us will likely take the time to review and understand and then did not ask a specific question.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Good afternoon,
in my project I have a button inside a gridvew that clicking opens a form.
This form is what I fill in two columns of the grid.
wanted to know how I program the button to open the form.
My code:
//Preenche template registos
templateRegistar.AllowAddNewRow = false;
templateRegistar.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
templateRegistar.Caption = "Registo de Lavagem de Fardamento";
templateRegistar.Columns.Add(new GridViewTextBoxColumn { HeaderText = "Nº Ticket", FieldName = "SYS_Registo_Entrega.SYS_Ticket.Ticket_ID", IsVisible = true });
templateRegistar.Columns.Add(new GridViewTextBoxColumn { HeaderText = "Fardamento", FieldName = "Fardamento_Funcionario.Fardamento.Descricao", IsVisible = true });
templateRegistar.Columns.Add(new GridViewTextBoxColumn { HeaderText = "Quantidade", FieldName = "Quantidade", IsVisible = true });
templateRegistar.Columns.Add(new GridViewTextBoxColumn { HeaderText = "Utilizador", FieldName = "SYS_Utilizador.Funcionario.Nome_Funcionario", IsVisible = true });
templateRegistar.Columns.Add(new GridViewTextBoxColumn { HeaderText = "Data Entrega", FieldName = "DtEntrega", IsVisible = true });
templateRegistar.Columns.Add(new GridViewComboBoxColumn { HeaderText = "Utilizador", FieldName = "Utilizador_IDLevantamento", IsVisible = true });
templateRegistar.Columns.Add(new GridViewComboBoxColumn { HeaderText = "Data Levantamento", FieldName = "DtLevantamento", IsVisible = true });
templateRegistar.Columns.Add(new GridViewCommandColumn { HeaderText = "", DefaultText = "Registar Levantamento", UseDefaultText = true, MaxWidth = 150, Name = "Levantamento" });
templateRegistar.Columns.Add(new GridViewTextBoxColumn { HeaderText = "Num_Mecanografico_Funcionario", FieldName = "Num_Mecanografico_Funcionario", IsVisible = false });
GridViewRelation relationRegistar = new GridViewRelation(radGridViewFuncionarios.MasterTemplate);
relationRegistar.ChildTemplate = templateRegistar;
relationRegistar.RelationName = "FuncionarioLavagem";
relationRegistar.ParentColumnNames.Add("Num_Mecanografico_Funcionario");
relationRegistar.ChildColumnNames.Add("Num_Mecanografico_Funcionario");
radGridViewFuncionarios.Relations.Add(relationRegistar);
radGridViewFuncionarios.CommandCellClick += radGridViewFuncionarios_CommandCellClick;
//Botao registar Levantamento
void radGridViewFuncionarios_CommandCellClick1(object sender, EventArgs e)
{
GridCommandCellElement click = (GridCommandCellElement)sender;
SYS_Registo_Entrega row = click.RowInfo.DataBoundItem as SYS_Registo_Entrega;
RegistarLevantamento reg = new RegistarLevantamento(row);
if (reg.ShowDialog() == DialogResult.OK)
{
PreencheFuncionarios(); // se foi adicionado novo funcionario a BD, entao atualiza a lista
}
}
|
|
|
|
|
First I suggest you have a good rat through Teleriks demos, they are usually pretty comprehensive. That should show you how to wire up the buttons and identify the content of the row that was clicked.
From that information you can get the data from the underlying collection to be passed to the second form.
Once you have that do some research on passing data between forms - there are plenty of examples.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
i'am trouble to execute base encode 64
this is the error message:
The name 'EncodePasswordToBase64' does not exist in the current context
|
|
|
|
|
Base64 is not an encryption function: it is a translation function. As a result, it is about as secure as having your password tattooed on your forehead backwards so nobody can read it except you with a mirror.
Stop trying to encrypt passwords at all - it is a very poor idea: Password Storage: How to do it.[^]
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
thanks but
what is lacking for the program, please solution. thanks
|
|
|
|
|
How are we supposed to know?
All you've said is that some symbol is not found in your code, which means you haven't defined it anywhere. Chances are really good you copied and pasted some code from somewhere and you have no idea what it does or how it works, correct? Well, we don't know what that symbol is supposed to be either.
Griff is correct. It looks like you're trying to encrypt a password. DO NOT DO THIS! He already gave a link to show you how to hash and store passwords correctly. Use it.
|
|
|
|
|
this is the code, the problem still to same like above ??
public static string EncodePasswordToBase64(string password)
{
try
{
byte[] encData_byte = new byte[password.Length];
encData_byte = System.Text.Encoding.UTF8.GetBytes(password);
string encodedData = Convert.ToBase64String(encData_byte);
return encodedData;
}
catch (Exception ex)
{
throw new Exception("Error in base64Encode" + ex.Message);
}
}
public string DecodeFrom64(string encodedData)
{
System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
System.Text.Decoder utf8Decode = encoder.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(encodedData);
int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decoded_char = new char[charCount];
utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
string result = new String(decoded_char);
return result;
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text=EncodePasswordToBase64(TextBox1.Text);
}
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Text = DecodeFrom64(Label1.Text);}
|
|
|
|
|
Are all of these functions in the same class?
|
|
|
|
|
I hope your not uSing this code to "encrypt" anything because this is not encryption.
Get rid of the "static" keyword on the EncodePasswordToBase64 method definition line.
|
|
|
|
|
thanks for the solution
|
|
|
|
|
hi every one ,
if i have any combobox filled with column in any table (MemeberValue, DataSource, DisplayName)
and i need to change the text of this combo if i know the MemeberValue(ID).
how can i do that ??
|
|
|
|
|
That will depend on what UI you are using, winforms/wpf/silverlight/asp and that is just the common ones.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
When you want to change the text? When _SelectedIndexChanged event fired?
|
|
|
|
|
hello i am writing an that application that can read a pdf file, get values from a pdf file and display in the application. . sofar i cannot retrive it on the pdf controler. please help
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();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "PDF document (*.pdf)|*.pdf";
DialogResult result = dialog.ShowDialog();
if (result == DialogResult.OK)
{
try
{
string pdfFile = dialog.FileName;
//this.axFoxitReaderOCX1.LoadFromFile(javascript.pdf);
}
catch (Exception exe)
{
MessageBox.Show(exe.Message, "Spire.PdfViewer Demo", MessageBoxButtons.OK, MessageBoxIcon.Error);
string path = @"C:\users\library\livhuwani\Documents\books.pdf";
System.Diagnostics.Process.Start("", path);
}
}
}
}
}
|
|
|
|
|
So, basically, you haven't done anything?
Start here: Extract Text from PDF in C# (100% .NET)[^] and come back when you have a specific problem - we aren't going to do it all for you!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|