private void EnterNewQuantity() { try { if (dgw.Rows.Count <= 0) { Interaction.MsgBox("Please select item.", MsgBoxStyle.Exclamation, "Edit Quantity"); return; } isNewQuantity = true; //=============Get the last item entered when entering quantity==================// //add isSelected variable, this will verify if the user selected item in the datagridview to put new quantity //lastItemPrice = Convert.ToDouble(dgw.Rows[dgw.Rows.Count -1].Cells[3].Value); //replace Convert.ToDouble(dgw.CurrentRow.Cells[3].Value in sending data to other form when applying this idea //=============END of Get the last item entered when entering quantity==================// oldItemQuantity = Convert.ToDouble(dgw.CurrentRow.Cells[4].Value); frmEnterQuantity ep = new frmEnterQuantity(this, Convert.ToDouble(dgw.CurrentRow.Cells[3].Value)); ep.ShowDialog(); //-----------------DECREASE BASKETINFORMATION-------------------------' //Total number of Items totalNumberOfItems -= oldItemQuantity; //Compute total Amount and Display totalAmountOfItems -= oldItemQuantity * Convert.ToDouble(dgw.CurrentRow.Cells[3].Value); //Total number of Items totalNumberOfItems += NewItemQuantity; lblTotalItems.Text = totalNumberOfItems.ToString(); //Compute total Amount and Display totalAmountOfItems += (NewItemQuantity * Convert.ToDouble(dgw.CurrentRow.Cells[3].Value)); lblTotalAmount.Text = Strings.Format(totalAmountOfItems, "#,##0.00"); //Get Vat Amount and Display lblVAT.Text = Strings.Format(totalAmountOfItems * Conversion.Val(lblVatPercent.Text), "#,##0.00"); //GET SubtotalAmount lblSubTotal.Text = Strings.Format(totalAmountOfItems - (totalAmountOfItems * Conversion.Val(lblVatPercent.Text)), "#,##0.00"); dgw.CurrentRow.Cells[4].Value = NewItemQuantity; dgw.CurrentRow.Cells[5].Value = Strings.Format(NewItemQuantity * Convert.ToDouble(dgw.CurrentRow.Cells[3].Value), "#,##0.00"); txtBarcode.Focus(); } catch (Exception ex) { Interaction.MsgBox(ex.ToString()); } }
public void GetProductInfo() { if (IsValidQuantity(noOfItems) == false) { Interaction.MsgBox("The number of quantity you have entered is greater than the number of Quantity On Hand", MsgBoxStyle.Exclamation, "Warning"); return; } double discountAmount = 0; try { SQLConn.sqL = "SELECT ProductCode, Description, UnitPrice, ProductNo FROM Product WHERE ProductNo = '" + productID + "'"; SQLConn.ConnDB(); SQLConn.cmd = new MySqlCommand(SQLConn.sqL, SQLConn.conn); SQLConn.dr = SQLConn.cmd.ExecuteReader(); if (SQLConn.dr.Read() == true) { txtItemCode.Text = SQLConn.dr["ProductCOde"].ToString(); txtItemDesc.Text = SQLConn.dr["Description"].ToString(); //Validate Discount if (isDiscount == true) { discountAmount = Conversion.Val(SQLConn.dr["UnitPrice"]) * (Conversion.Val(discountPercent) / 100); txtPrice.Text = Strings.Format(Conversion.Val(SQLConn.dr["UnitPrice"]) - discountAmount, "#,##0.00"); txtPrice.Tag = Strings.Format(Conversion.Val(SQLConn.dr["UnitPrice"]), "#,##0.00"); } else { txtPrice.Text = Strings.Format(SQLConn.dr["UnitPrice"], "#,##0.00"); txtPrice.Tag = Strings.Format(Conversion.Val(SQLConn.dr["UnitPrice"]), "#,##0.00"); discountAmount = 0; } //Validate Quantity if (isNewQuantity == true) { txtQuantity.Text = noOfItems.ToString(); } else { txtQuantity.Text = "1"; } txtTotal.Text = Strings.Format(Conversion.Val(txtPrice.Text.Replace(",", "")) * Conversion.Val(txtQuantity.Text), "#,##0.00"); isNewQuantity = false; frmEnterQuantity ep = new frmEnterQuantity(this, Convert.ToDouble(SQLConn.dr["UnitPrice"])); ep.ShowDialog(); txtQuantity.Text = itemQuantity.ToString(); txtTotal.Text = Strings.Format(Conversion.Val(txtPrice.Text.Replace(",", "")) * Conversion.Val(txtQuantity.Text), "#,##0.00"); //Adding Item to Gridview to Display dgw.Rows.Add(SQLConn.dr["ProductNo"], SQLConn.dr["ProductCode"], SQLConn.dr["Description"], txtPrice.Tag, txtQuantity.Text, txtTotal.Text, Strings.Format(discountAmount * Conversion.Val(txtQuantity.Text), "#,##0.00")); //Scroll to the last row. this.dgw.FirstDisplayedScrollingRowIndex = this.dgw.RowCount - 1; //'Select the last row. // this.dgw.Rows[this.dgw.RowCount - 1].Selected = true; // dgw.CurrentCell = dgw.Rows[this.dgw.RowCount -1].Cells[0]; //dgw.SelectedRows.Clear(); dgw.ClearSelection(); //dgw.Rows[this.dgw.RowCount - 1].Selected = true; //-Get Basket Info BasketInformation(); //Clear text fields txtBarcode.Clear(); txtItemCode.Clear(); txtItemDesc.Clear(); txtPrice.Text = "0.00"; txtTotal.Text = "0.00"; txtQuantity.Text = "1"; //Set Product ID productID = 0; //et Discount to Zero discountPercent = 0; isDiscount = false; //Set Quantity to False isNewQuantity = false; noOfItems = 1; //Set Focus back to barcode txtBarcode.Focus(); } } catch (Exception) { //Interaction.MsgBox(ex.ToString()); } finally { SQLConn.cmd.Dispose(); SQLConn.conn.Close(); } }