private void button1_Click(object sender, EventArgs e) { try { if (string.IsNullOrWhiteSpace(TxtIDPro.Text.Trim()) == false) { Engine.idproduct = int.Parse(TxtIDPro.Text); Engine.SProduct(); LblDescriptionProduct.Text = Engine.ProductDescription; LblPriceProd.Text = Convert.ToString(Engine.ProductPrice); lblStock.Text = Convert.ToString(Engine.productStock); TxtQty.Focus(); } } catch (Exception error) { Engine.Qupdate = int.Parse(TxtQty.Text); if (int.Parse(TxtQty.Text) <= int.Parse(lblStock.Text)) { bool addedbefore = false; int num_row = 0; if (counter_row == 0) { dataGridView1.Rows.Add(TxtIDPro.Text, LblDescriptionProduct.Text, LblPriceProd.Text, TxtQty.Text); double totalprice = Convert.ToDouble(dataGridView1.Rows[counter_row].Cells[2].Value) * Convert.ToDouble(dataGridView1.Rows[counter_row].Cells[3].Value); dataGridView1.Rows[counter_row].Cells[4].Value = totalprice; counter_row++; Engine.Qtyupdater(); lblStock.Text = Convert.ToString(Engine.Qupdate); } else { foreach (DataGridViewRow r in dataGridView1.Rows) { if (r.Cells[0].Value.ToString() == TxtIDPro.Text) { addedbefore = true; num_row = r.Index; } } if (addedbefore == true) { dataGridView1.Rows[num_row].Cells[3].Value = (Convert.ToDouble(TxtQty.Text) + Convert.ToDouble(dataGridView1.Rows[num_row].Cells[3].Value)).ToString(); double totalprice = Convert.ToDouble(dataGridView1.Rows[num_row].Cells[2].Value) * Convert.ToDouble(dataGridView1.Rows[num_row].Cells[3].Value); dataGridView1.Rows[num_row].Cells[4].Value = totalprice; Engine.Qtyupdater(); lblStock.Text = Convert.ToString(Engine.Qupdate); } else { dataGridView1.Rows.Add(TxtIDPro.Text, LblDescriptionProduct.Text, LblPriceProd.Text, TxtQty.Text); double totalprice = Convert.ToDouble(dataGridView1.Rows[counter_row].Cells[2].Value) * Convert.ToDouble(dataGridView1.Rows[counter_row].Cells[3].Value); dataGridView1.Rows[counter_row].Cells[4].Value = totalprice; counter_row++; Engine.Qtyupdater(); lblStock.Text = Convert.ToString(Engine.Qupdate); } } TotalInvoice = 0; foreach (DataGridViewRow r in dataGridView1.Rows) { TotalInvoice += Convert.ToDouble(r.Cells[4].Value); } LblTotalInv.Text = "CZK " + TotalInvoice.ToString(); } } }
protected void gvInviceCount_ItemDataBound(object sender, GridItemEventArgs e) { //foreach (GridDataItem dataItem in gvInviceCount.MasterTableView.Items) //{ // //TextBox txtLT = (TextBox)(dataItem.FindControl("txtRequest_Qty") as TextBox); // //TextBox txtUNt = (TextBox)(dataItem.FindControl("txtUnitPrice") as TextBox); // //TextBox txtDis = (TextBox)(dataItem.FindControl("txtDiscount") as TextBox); // HiddenField lblID = (HiddenField)(dataItem.FindControl("lblID") as HiddenField); // ImageButton btnDelete = (ImageButton)(dataItem.FindControl("ImgDelete") as ImageButton); //} if (e.Item is GridDataItem) { GridDataItem dataItem = e.Item as GridDataItem; if ((dataItem["Clean"].FindControl("btnClean") as Button).Text != "") { totalClean += int.Parse((dataItem["Clean"].FindControl("btnClean") as Button).Text); } if ((dataItem["Dirty"].FindControl("btnDirty") as Button).Text != "") { TotalDirty += int.Parse((dataItem["Dirty"].FindControl("btnDirty") as Button).Text); } if ((dataItem["DIRECTINV"].FindControl("btnDIRECTINV") as Button).Text != "") { TotalDirectInv += int.Parse((dataItem["DIRECTINV"].FindControl("btnDIRECTINV") as Button).Text); } if ((dataItem["LATEPO"].FindControl("btnLATEPO") as Button).Text != "") { TotalLatePO += int.Parse((dataItem["LATEPO"].FindControl("btnLATEPO") as Button).Text); } if ((dataItem["REWORKIN"].FindControl("btnREWORKIN") as Button).Text != "") { TotalReworkIN += int.Parse((dataItem["REWORKIN"].FindControl("btnREWORKIN") as Button).Text); } if ((dataItem["REWORKOUT"].FindControl("btnREWORKOUT") as Button).Text != "") { TotalReworkOut += int.Parse((dataItem["REWORKOUT"].FindControl("btnREWORKOUT") as Button).Text); } if ((dataItem["OTHERS"].FindControl("btnOTHERS") as Button).Text != "") { TotalOthers += int.Parse((dataItem["OTHERS"].FindControl("btnOTHERS") as Button).Text); } TotalInvoice = totalClean + TotalDirty + TotalDirectInv + TotalLatePO + TotalReworkIN + TotalReworkOut + TotalOthers; } else if (e.Item is GridFooterItem) { GridFooterItem footer = (GridFooterItem)e.Item; (footer["Clean"].FindControl("lblTotal_Clean") as Label).Text = totalClean.ToString(); clientID = (footer["Clean"].FindControl("lblTotal_Clean") as Label).ClientID; (footer["Dirty"].FindControl("lblTotal_Dirty") as Label).Text = TotalDirty.ToString(); clientID = (footer["Dirty"].FindControl("lblTotal_Dirty") as Label).ClientID; (footer["DIRECTINV"].FindControl("lblTotal_Direct") as Label).Text = TotalDirectInv.ToString(); clientID = (footer["DIRECTINV"].FindControl("lblTotal_Direct") as Label).ClientID; (footer["LATEPO"].FindControl("lblTotal_LatePO") as Label).Text = TotalLatePO.ToString(); clientID = (footer["LATEPO"].FindControl("lblTotal_LatePO") as Label).ClientID; (footer["REWORKIN"].FindControl("lblTotal_ReworkIN") as Label).Text = TotalReworkIN.ToString(); clientID = (footer["REWORKIN"].FindControl("lblTotal_ReworkIN") as Label).ClientID; (footer["REWORKOUT"].FindControl("lblTotal_ReworkOUT") as Label).Text = TotalReworkOut.ToString(); clientID = (footer["REWORKOUT"].FindControl("lblTotal_ReworkOUT") as Label).ClientID; (footer["OTHERS"].FindControl("lblTotal_Others") as Label).Text = TotalOthers.ToString(); clientID = (footer["OTHERS"].FindControl("lblTotal_Others") as Label).ClientID; (footer["Report_Name"].FindControl("lblTotal_Invoice") as Label).Text = "Total" + " " + TotalInvoice.ToString() + " " + "Invoices"; clientID = (footer["OTHERS"].FindControl("lblTotal_Others") as Label).ClientID; } }