-C# Label & Literal not displaying value - c#

I have a profile that allows users to display, edit, save.
The save and edit works ok.
However, the display is not working properly.
I tried changing labels to literals but they don't either.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.BindGenderDropDownList();
//this.BindTimeZonesDropDownList();
//this.BindCulturesDropDownList();
if (!string.IsNullOrEmpty(Membership.GetUser().UserName))
{
Profile = MyProfile.GetProfile(Membership.GetUser().UserName);
this.DisplayProfile();
}
}
}
protected void btnGo_Click(object sender, EventArgs e)
{
this.DisplayProfile();
}
protected void btnEdit_Click(object sender, EventArgs e)
{
this.EditProfile();
}
protected void btnCancelDisplay_Click(object sender, EventArgs e)
{
this.ResetElements();
}
protected void btnSave_Click(object sender, EventArgs e)
{
this.SaveProfile();
}
protected void btnCancelEdit_Click(object sender, EventArgs e)
{
this.ResetElements();
}
private void DisplayProfile()
{
this.SetElementsForDisplaying();
litfullname.Text = this.Profile.ProfileDetail.FullName;
}
private void EditProfile()
{
this.SetElementsForEditing();
if (Profile.ProfileDetail == null)
{
txtfname.Text = this.Profile.ProfileDetail.FullName;
txtcardno.Text = this.Profile.ProfileDetail.IdentityCardNo;
ddlcardcolor.SelectedValue = this.Profile.ProfileDetail.IdentityCardColour;
txtcardexp.Text = this.Profile.ProfileDetail.IdentityCardExpiryDate.ToString("dd MMMM yyyy");
ddlrace.Text = this.Profile.ProfileDetail.Race;
ddlreligion.SelectedValue = this.Profile.ProfileDetail.Religion;
txtaddress1.Text = this.Profile.ProfileDetail.ContactInformation.Address1;
txtaddress2.Text = this.Profile.ProfileDetail.ContactInformation.Address2;
txtaddress3.Text = this.Profile.ProfileDetail.ContactInformation.Address3;
txtpostcode.Text = this.Profile.ProfileDetail.ContactInformation.Postcode;
ddldistrict.SelectedValue = this.Profile.ProfileDetail.ContactInformation.District;
txtphoneoffice.Text = this.Profile.ProfileDetail.ContactInformation.OfficePhone;
txtphonehome.Text = this.Profile.ProfileDetail.ContactInformation.HomePhone;
txtphonecell.Text = this.Profile.ProfileDetail.ContactInformation.MobilePhone;
txtemail.Text = this.Profile.ProfileDetail.ContactInformation.Email;
}
}
Save profile. This is working properly.
private void SaveProfile()
{
if (Profile.ProfileDetail == null)
{
this.Profile.ProfileDetail.FullName = txtfname.Text;
this.Profile.ProfileDetail.IdentityCardNo = txtcardno.Text;
this.Profile.ProfileDetail.IdentityCardColour = ddlcardcolor.SelectedValue;
this.Profile.ProfileDetail.IdentityCardExpiryDate = DateTime.ParseExact(txtcardexp.Text, "dd MMMM yyyy", null);
this.Profile.ProfileDetail.Race = ddlrace.SelectedValue;
this.Profile.ProfileDetail.Religion = ddlreligion.SelectedValue;
this.Profile.ProfileDetail.ContactInformation.Address1 = txtaddress1.Text;
this.Profile.ProfileDetail.ContactInformation.Address2 = txtaddress2.Text;
this.Profile.ProfileDetail.ContactInformation.Address3 = txtaddress3.Text;
this.Profile.ProfileDetail.ContactInformation.Postcode = txtpostcode.Text;
this.Profile.ProfileDetail.ContactInformation.District = ddldistrict.SelectedValue;
this.Profile.ProfileDetail.ContactInformation.OfficePhone = txtphoneoffice.Text;
this.Profile.ProfileDetail.ContactInformation.HomePhone = txtphonehome.Text;
this.Profile.ProfileDetail.ContactInformation.MobilePhone = txtphonecell.Text;
this.Profile.ProfileDetail.ContactInformation.Email = txtemail.Text;
}
this.Profile.Save();
this.ResetElements();
}
To display, which doesn't work properly
private void SetElementsForDisplaying()
{
pnlDisplayValues.Visible = true;
pnlSetValues.Visible = false;
litUserTitle.Visible = false;
litUserTitle.Text = string.Format("Display profile for {0}", this.Profile.UserName);
}
Edit profile. Working properly
private void SetElementsForEditing()
{
pnlDisplayValues.Visible = false;
pnlSetValues.Visible = true;
litUserTitle.Visible = true;
litUserTitle.Text = string.Format("Edit profile for {0}", this.Profile.UserName);
}
private void ResetElements()
{
pnlSetValues.Visible = false;
pnlDisplayValues.Visible = true;
litUserTitle.Visible = true;
}

private void SetElementsForDisplaying()
{
pnlDisplayValues.Visible = true;
pnlSetValues.Visible = false;
litUserTitle.Visible = true; // set this as visible
litUserTitle.Text = string.Format("Display profile for {0}", this.Profile.UserName);
}
And in your pnlDisplayValues panel add the literals you want and set the values in the DisplayProfile() method

Related

Updating/Deleting a row in listview that includes a countdown timer

Currently i am having trouble updating a row in my listview that contains both text and a timer that counts down. So far I've tried updating the entire row as well as trying to update just the text and i get an error in each instance.
System.ArgumentOutOfRangeException: InvalidArgument=Value of '0' is not valid for 'index
I am also having a slight problem with the delete button. It deletes the row as planned but it appears the information is still running in the background and haven't come across any info on how to delete the session. I pray for your guidance.
private void Confirm_Click(object sender, EventArgs e)
{
CSession newSession = new CSession();
if(PasswordText.Text == "")
{
MessageBox.Show("Password not entered");
return;
}
newSession.password = PasswordText.Text;
newSession.purchased_time = workingTimeSpan;
newSession.remaining_time = workingTimeSpan;
newSession.status = "Online";
sessionlist.Add(newSession);
PasswordText.Text = "";
TimerLabel.Text = "";
workingTimeSpan = new TimeSpan();
}
private void DisplayAllSessions()
{
listView1.Items.Clear();
foreach(CSession c in sessionlist)
{
string[] row = { c.password, c.purchased_time.ToString(), c.remaining_time.ToString(), c.status };
ListViewItem i = new ListViewItem(row);
listView1.Items.Add(i);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
foreach(CSession c in sessionlist)
{
if (c.remaining_time.TotalMinutes == 5 && !c.MessageDisplayed)
{
c.MessageDisplayed = true;
MessageBox.Show("Time almost up for client.");
}
if (c.remaining_time.TotalSeconds < 1)
{
c.status = "Offline";
}
if(c.status == "Online")
{
c.remaining_time -= oneSecond;
}
}
DisplayAllSessions();
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Close();
}
private void Reset_Click(object sender, EventArgs e)
{
}
private void updatebutton()
{
listView1.SelectedItems[0].SubItems[0].Text = PasswordText.Text;
PasswordText.Text = "";
}
private void Update_Click(object sender, EventArgs e)
{
updatebutton();
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
PasswordText.Text = listView1.SelectedItems[0].Text;
TimerLabel.Text = listView1.SelectedItems[0].SubItems[1].Text;
}
private void Delete_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Do you wish to delete.", "Removing User", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
{
listView1.Items.Clear();
timer1.Stop();
}
}
This is what i used for the update function and delete row function.
private void updatebutton()
{
CSession updatedsession = new CSession();
int updateindex = 0;
int index = 0;
foreach (CSession lookup in sessionlist)
{
if(lookup.password == PasswordText.Text)
{
if (MessageBox.Show("Do you wish to add time.", "Adding Time",
MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
{
updatedsession = lookup;
updateindex = index;
}
break;
}
index++;
}
updatedsession.purchased_time = workingTimeSpan +
updatedsession.purchased_time;
updatedsession.remaining_time = workingTimeSpan +
updatedsession.remaining_time;
sessionlist[updateindex] = updatedsession;
//sortedSessionList[PasswordText.Text] = updatedsession;
PasswordText.Text = "";
TimerLabel.Text = "";
workingTimeSpan = new TimeSpan();
}
private void Update_Click(object sender, EventArgs e)
{
updatebutton();
}
private void Delete_Click(object sender, EventArgs e)
{
CSession cSession = new CSession();
if (MessageBox.Show("Do you wish to delete.", "Removing User",
MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
{
int index = 0;
foreach (CSession c in sessionlist)
{
if(c.password == PasswordText.Text)
{
break;
}
index++;
}
sessionlist.RemoveAt(index);
}
}

How to hide and show a panel by clicking a button in C#

I have three panels and three buttons. Upon clicking button1 I want to show Panel1 and hide Panel2 and Panel3.
The same process with the other buttons and panels. How can I do this?
I'm using a Window Forms application written in C#/.NET. This code is not working very well, because only two panels are showing.
private void frmMain_Load(object sender, EventArgs e)
{
pnlItems.Visible = true;
pnlCustomer.Visible = false;
pnlPOS.Visible = false;
}
private void btnItems_Click(object sender, EventArgs e)
{
pnlItems.Visible = true;
pnlCustomer.Visible = false;
pnlPOS.Visible = false;
}
private void btnCustomers_Click(object sender, EventArgs e)
{
pnlCustomer.Visible = true;
pnlItems.Visible = false;
pnlPOS.Visible = false;
}
private void btnPOS_Click(object sender, EventArgs e)
{
pnlPOS.Visible = true;
pnlCustomer.Visible = false;
pnlItems.Visible = false;
}
private void frmMain_Load(object sender, EventArgs e)
{
pnlItems.Visible = true;
pnlCustomer.Visible = false;
pnlPOS.Visible = false;
}
private void btnItems_Click(object sender, EventArgs e)
{
if(pnlItems.Visible != true)
{
pnlItems.Visible = true;
pnlCustomer.Visible = false;
pnlPOS.Visible = false;
}
}
private void btnCustomers_Click(object sender, EventArgs e)
{
if(pnlCustomer.Visible != true)
{
pnlCustomer.Visible = true;
pnlItems.Visible = false;
pnlPOS.Visible = false;
}
}
private void btnPOS_Click(object sender, EventArgs e)
{
if(pnlPOS.Visible != true)
{
pnlPOS.Visible = true;
pnlCustomer.Visible = false;
pnlItems.Visible = false;
}
}
Here I have updated the conditional statement for if your panel is not visible then act. I hope this will work.

How to Decode QRCode from WebCamera using Aforge.NET and ZXing.NET in C#

I am trying to develop a WindowsForm Application which will use webcamera to detect QRCode and decode the message. For this I am using AForge.NET and ZXing.NET.
So far, I have been able to figure out how to decode the QRCode from an URI, but I want to detect the QRCode from webcamera, and decode it.
Below is the sample to my code.
public String Decode(Uri uri)
{
Bitmap image;
try
{
image = (Bitmap)Bitmap.FromFile(uri.LocalPath);
}
catch (Exception ex)
{
throw new FileNotFoundException("Resource not found: " + uri);
}
using (image)
{
String text = "";
LuminanceSource source = new BitmapLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Result result = new MultiFormatReader().decode(bitmap);
if (result != null)
{
text = result.Text;
return text;
}
text = "Provided QR couldn't be read.";
return text;
}
}
private FilterInfoCollection videoDevices;
private VideoCaptureDevice videoSource;
private Bitmap capturedImage;
private String message = "";
public FormQRCodeScanner()
{
InitializeComponent();
}
private void FormQRCodeScanner_Load(object sender, EventArgs e)
{
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo device in videoDevices)
{
comboBoxCameraSource.Items.Add(device.Name);
}
comboBoxCameraSource.SelectedIndex = 0;
videoSource = new VideoCaptureDevice();
buttonStartStop.Text = "Start";
buttonCapture.Enabled = false;
buttonDecode.Enabled = false;
}
private void FormQRCodeScanner_FormClosing(object sender, FormClosingEventArgs e)
{
if (videoSource.IsRunning)
{
videoSource.Stop();
}
}
void videoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap image = (Bitmap) eventArgs.Frame.Clone();
pictureBoxSource.Image = image;
}
private void buttonStartStop_Click(object sender, EventArgs e)
{
if (videoSource.IsRunning)
{
videoSource.Stop();
pictureBoxSource.Image = null;
pictureBoxCaptured.Image = null;
pictureBoxSource.Invalidate();
pictureBoxCaptured.Invalidate();
buttonStartStop.Text = "Start";
buttonCapture.Enabled = false;
buttonDecode.Enabled = false;
}
else
{
videoSource = new VideoCaptureDevice(videoDevices[comboBoxCameraSource.SelectedIndex].MonikerString);
videoSource.NewFrame += new NewFrameEventHandler(videoSource_NewFrame);
videoSource.Start();
buttonStartStop.Text = "Stop";
buttonCapture.Enabled = true;
buttonDecode.Enabled = true;
}
}
private void buttonCapture_Click(object sender, EventArgs e)
{
if (videoSource.IsRunning)
{
pictureBoxCaptured.Image = (Bitmap)pictureBoxSource.Image.Clone();
capturedImage = (Bitmap)pictureBoxCaptured.Image;
}
}
private void buttonDecode_Click(object sender, EventArgs e)
{
if (capturedImage != null)
{
ExtractQRCodeMessageFromImage(capturedImage);
richTextBoxMessage.Text = message;
richTextBoxMessage.ReadOnly = true;
}
}
private string ExtractQRCodeMessageFromImage(Bitmap bitmap)
{
try
{
BarcodeReader reader = new BarcodeReader
(null, newbitmap => new BitmapLuminanceSource(bitmap), luminance => new GlobalHistogramBinarizer(luminance));
reader.AutoRotate = true;
reader.TryInverted = true;
reader.Options = new DecodingOptions { TryHarder = true };
var result = reader.Decode(bitmap);
if (result != null)
{
message = result.Text;
return message;
}
else
{
message = "QRCode couldn't be decoded.";
return message;
}
}
catch (Exception ex)
{
message = "QRCode couldn't be detected.";
return message;
}
}
**For this you should install these packages
Install-Package AForge
Install-Package AForge.Video
Install-Package AForge.Video.DirectShow
Install-Package ZXing.Net
you can watch this video for more help
https://www.youtube.com/watch?v=wcoy0Gwxr50**
using System.IO;
using AForge;
using AForge.Video;
using AForge.Video.DirectShow;
using ZXing;
using ZXing.Aztec;
private void Form1_Load(object sender, EventArgs e)
{
CaptureDevice = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo Device in CaptureDevice)
{
comboBox1.Items.Add(Device.Name);
}
comboBox1.SelectedIndex = 0;
FinalFrame = new VideoCaptureDevice();
}
private void button1_Click(object sender, EventArgs e)
{
FinalFrame = new VideoCaptureDevice(CaptureDevice[comboBox1.SelectedIndex].MonikerString);
FinalFrame.NewFrame += new NewFrameEventHandler(FinalFrame_NewFrame);
FinalFrame.Start();
}
private void FinalFrame_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone();
}
private void timer1_Tick(object sender, EventArgs e)
{
BarcodeReader Reader = new BarcodeReader();
Result result = Reader.Decode((Bitmap)pictureBox1.Image);
try
{
string decoded = result.ToString().Trim();
if (decoded != "")
{
timer1.Stop();
MessageBox.Show(decoded);
Form2 form = new Form2();
form.Show();
this.Hide();
}
}
catch(Exception ex){
}
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
timer1.Start();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (FinalFrame.IsRunning == true)
{
FinalFrame.Stop();
}
}

Parent Node is also unchecked if I uncheck a single childnode in treeview, but other childnode also checked

I have a treeview in my asp.net page, when i unselect a single child node and other node are selected then parent node is always unselected. If I unselected one more child node and again select it then parent node also select. I don't no why this problem occurs ?
==================================================================================
public partial class frmTabMenuManagement : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindMenu();
}
}
public void BindMenu()
{
AdminMenuLogic al = new AdminMenuLogic();
al.Description = "";
ddlParentMenu.DataSource = al.FilterAdminMenu();
ddlParentMenu.DataTextField = "Description";
ddlParentMenu.DataValueField = "Id";
ddlParentMenu.DataBind();
ddlParentMenu.Items.Insert(0, new ListItem("As Parent", "0"));
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
AdminMenuLogic amt = new AdminMenuLogic();
if (btnSubmit.Text == "Submit")
{
if (txtMenuLink.Text == "")
{
Response.Write("<script language='javascript'>alert(' Menu Description Cannot be left Empty');</script>");
}
else if (txtDestinationLink.Text == "")
{
Response.Write("<script language='javascript'>alert(' Destination Link Cannot be left Empty');</script>");
}
else
{
amt.Description = txtMenuLink.Text;
amt.IsActive = Convert.ToString(ddlIsActive.SelectedItem);
amt.Url = txtDestinationLink.Text;
amt.Parent = Convert.ToInt32(ddlParentMenu.SelectedValue);
amt.saveAdminMenu();
Response.Write("<script language='javascript'>alert('" + amt.OutPut + "');</script>");
txtMenuLink.Text = "";
txtDestinationLink.Text = "";
BindMenu();//reflect instant changes
}
}
else if (btnSubmit.Text == "Update")
{
amt.id = Convert.ToInt32(gvSearch.SelectedRow.Cells[1].Text);
amt.Description = txtMenuLink.Text;
amt.IsActive = Convert.ToString(ddlIsActive.SelectedItem);
amt.Url = txtDestinationLink.Text;
amt.Parent = Convert.ToInt32(ddlParentMenu.SelectedValue);
amt.UpdateAdminMenu();
Response.Write("<script language='javascript'>alert('" + amt.OutPut + "');</script>");
txtMenuLink.Text = "";
txtDestinationLink.Text = "";
bindGrid();
btnSubmit.Text = "Submit";
BindMenu();//reflect instant changes
}
}
protected void btnSearch_Click(object sender, EventArgs e)
{
if (btnSubmit.Text == "Update")
{
btnSubmit.Text = "Submit";
txtMenuLink.Text = "";
txtDestinationLink.Text = "";
}
bindGrid();
}
protected void gvSearch_SelectedIndexChanged(object sender, EventArgs e)
{
TabContainer1.ActiveTabIndex = 0;
ddlParentMenu.Items.Add(gvSearch.SelectedRow.Cells[3].Text);
ddlParentMenu.SelectedValue = gvSearch.SelectedRow.Cells[3].Text;
txtMenuLink.Text = Regex.Replace(gvSearch.SelectedRow.Cells[2].Text, "amp;", "");
txtDestinationLink.Text = Regex.Replace(gvSearch.SelectedRow.Cells[4].Text, "amp;", "");
ddlIsActive.SelectedValue = gvSearch.SelectedRow.Cells[5].Text;
btnSubmit.Text = "Update";
}
protected void txtMenuLink_TextChanged(object sender, EventArgs e)
{
if (char.IsWhiteSpace(txtMenuLink.Text.First()))
{
txtMenuLink.Text = Regex.Replace(txtMenuLink.Text, " ", "");
}
}
protected void txtDestinationLink_TextChanged(object sender, EventArgs e)
{
try
{
if (char.IsWhiteSpace(txtDestinationLink.Text.First()))
{
txtDestinationLink.Text = Regex.Replace(txtDestinationLink.Text, " ", "");
}
}
catch (Exception ex)
{
}
}
protected void ddlParentMenu_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void gvSearch_RowDataBound(Object sender, GridViewRowEventArgs e)
{
GridViewRow row = e.Row;
if (row.RowType == DataControlRowType.Header)
{
e.Row.Cells[1].Visible = false;
// e.Row.Cells[3].Visible = false;
}
if (row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[1].Visible = false;
// e.Row.Cells[3].Visible = false;
}
}
protected void gvSearch_PageIndexChanging(Object sender, GridViewPageEventArgs e)
{
gvSearch.PageIndex = e.NewPageIndex;
bindGrid();
}
protected void gvSearch_PageIndexChanged(Object sender, EventArgs e)
{
}
void bindGrid()
{
AdminMenuLogic al = new AdminMenuLogic();
al.Description = txtSearch.Text;
gvSearch.DataSource = al.FilterAdminMenu();
gvSearch.DataBind();
}
protected void ddlIsActive_SelectedIndexChanged(object sender, EventArgs e)
{
}
}

objects in datagridview

Im adding objects to a datagridview ( only one kind) through a list
ej.
List<Material> mater = new List<Material>();
DataGridView dgvMAterial = new DataGridView();
dgvMaterial.DataSource = null;
mater.Add((Material)cmbMaterial.SelectedValue);
dgvMaterial.DataSource = mater;
But every time I click over the datagrid I get an indexoutofrangeexeption.
Can somone tell me why?
thanks
here is my whole code for the form
public partial class inicio : Form
{
private string ConnectionString = "Data Source=localhost\\sqlexpress;Initial Catalog=data.mdf;Integrated Security=SSPI;";
//private string ConnectionString = "Server=.\\SQLExpress;AttachDbFilename=|DataDirectory|\\data\\data_data.mdf.mdf; Database=data.mdf;Trusted_Connection=Yes;";
private ISessionFactory sessionFactory;
List<Material> mater = new List<Material>();
List<Salarios> salar = new List<Salarios>();
IBindingList mind = new BindingList<Salarios>();
Productos prod;
public inicio()
{
InitializeComponent();
sessionFactory = nhn.BusinessObjects.Initialize.CreateSessionFactory(ConnectionString);
dgvMaterial.DataSource = mater;
}
private void materialToolStripMenuItem_Click(object sender, EventArgs e)
{
Catalogos.frmMaterial material = new costeos.Catalogos.frmMaterial(ConnectionString);
material.ShowDialog(this);
material.Dispose();
}
private void salariosToolStripMenuItem_Click(object sender, EventArgs e)
{
Catalogos.frmSalarios salarios = new costeos.Catalogos.frmSalarios(ConnectionString);
salarios.ShowDialog(this);
salarios.Dispose();
}
private void agregarToolStripMenuItem_Click(object sender, EventArgs e)
{
Catalogos.frmAddRemuneraciones rem = new costeos.Catalogos.frmAddRemuneraciones(ConnectionString);
rem.ShowDialog(this);
rem.Dispose();
}
private void agregarToolStripMenuItem1_Click(object sender, EventArgs e)
{
Catalogos.frmAddAdmin adm = new costeos.Catalogos.frmAddAdmin(ConnectionString);
adm.ShowDialog(this);
adm.Dispose();
}
private void agregarToolStripMenuItem2_Click(object sender, EventArgs e)
{
Catalogos.frmAddInsumosInd insumos = new costeos.Catalogos.frmAddInsumosInd(ConnectionString);
insumos.ShowDialog(this);
insumos.Dispose();
}
private void txt_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsDigit(e.KeyChar) || char.IsPunctuation(e.KeyChar) || char.IsControl(e.KeyChar))
{
e.Handled = false;
}
else
{
e.Handled = true;
}
}
private void inicio_Load(object sender, EventArgs e)
{
LlenaCampos();
}
private void LlenaCampos()
{
using (var session = sessionFactory.OpenSession())
{
using (var transaction = session.BeginTransaction())
{
var mat = session.CreateCriteria(typeof(Material))
.List<Material>();
var sal = session.CreateCriteria(typeof(Salarios))
.List<Salarios>();
transaction.Commit();
cmbMaterial.DataSource = mat;
cmbMaterial.DisplayMember = "Nombre";
cmbSalarios.DataSource = sal;
cmbSalarios.DisplayMember = "Nombre";
cmbMIndirecta.DataSource = sal;
cmbMIndirecta.DisplayMember = "Nombre";
}
}
}
private void btnAddMaterial_Click(object sender, EventArgs e)
{
materialBindingSource.DataSource = null;
//dgvMaterial.DataSource = null;
mater.Add((Material)cmbMaterial.SelectedValue);
//dgvMaterial.DataSource = mater;
dgvMaterial.DataSource = materialBindingSource;
materialBindingSource.DataSource = mater;
materialBindingSource.ResetBindings(false);
}
private void button2_Click(object sender, EventArgs e)
{
dgvSalarios.DataSource = null;
salar.Add((Salarios)cmbSalarios.SelectedValue);
dgvSalarios.DataSource = salar;
}
private void button3_Click(object sender, EventArgs e)
{
dgvMIndirecta.DataSource = null;
mind.Add((Salarios)cmbMIndirecta.SelectedValue);
dgvMIndirecta.DataSource = mind;
}
private void button1_Click(object sender, EventArgs e)
{
using (var session = sessionFactory.OpenSession())
{
using (var transaction = session.BeginTransaction())
{
if (prod == null)
{
prod = new Productos { CargasTurno = float.Parse(txtCargasTurno.Text), CavidadesMolde = int.Parse(txtCavidadesMolde.Text), Clave = txtClave.Text, Comentarios = txtComentarios.Text, MezclasTurno = float.Parse(txtMezclasTurno.Text), Moldes = int.Parse(txtMoldes.Text), Nombre = txtNombre.Text, Peso = float.Parse(txtPesoTotal.Text), TotalPza = int.Parse(txtPzasTotales.Text), Turnos = int.Parse(txtTurnos.Text) };
session.Save(prod);
transaction.Commit();
}
foreach (DataGridViewRow dr in dgvMaterial.Rows)
{
Material m = dr.DataBoundItem as Material;
m.Materiales
PMaterial mat = new PMaterial { Material = dr.DataBoundItem as Material, Cantidad = float.Parse(dr.Cells["Cantidad"].Value.ToString()), Fecha = DateTime.Now, Producto = prod };
session.Save(mat);
}
transaction.Commit();
session.Close();
}
}
}
}
}
That's probably not DGV problem, but with this combo box. Show us the code that fills combo box and sets its properties.
If you are casting to Material class you should probably use SelectedItem instead of SelectedValue. (unless you exactly know what you're doing)
I would guess that you have an event-handler that isn't happy. What exactly does the message say?
You might also be having problems if you are adding the same Material instance to the list multiple times; since IndexOf will only find the first occurrence. This line makes me very suspicious:
mater.Add((Material)cmbMaterial.SelectedValue);
since it could potentially (on consecutive clicks / etc) do exactly this.
Note: if you used BindingList<T> instead all you'd have to doo is Add(...) - no resetting required:
field:
BindingList<Material> mater = new BindingList<Material>();
init grid:
dgvMaterial.DataSource = mater;
add item:
mater.Add(newInstance);
If you assign data source to the DGV you should check element count - if zero then assign null. I don't know why this is the way it is, but I'm doing it in all my forms.
//I'm still analysing the rest of the code

Categories

Resources