public bool Insert(facStockBLL u) { bool isSuccess = false; SqlConnection conn = new SqlConnection(myconnstrng); try { String sql = "INSERT INTO tbl_stock (stock_item_code, stock_fac_id, stock_qty, stock_unit, stock_updtd_date, stock_updtd_by) VALUES (@stock_item_code, @stock_fac_id, @stock_qty, @stock_unit, @stock_updtd_date, @stock_updtd_by)"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@stock_item_code", u.stock_item_code); cmd.Parameters.AddWithValue("@stock_fac_id", u.stock_fac_id); cmd.Parameters.AddWithValue("@stock_qty", u.stock_qty); cmd.Parameters.AddWithValue("@stock_unit", u.stock_unit); cmd.Parameters.AddWithValue("@stock_updtd_date", u.stock_updtd_date); cmd.Parameters.AddWithValue("@stock_updtd_by", u.stock_updtd_by); conn.Open(); int rows = cmd.ExecuteNonQuery(); //if the query is executed successfully then the rows' value = 0 if (rows > 0) { //query successful isSuccess = true; dalItem.updateTotalStock(u.stock_item_code); } else { //Query falled isSuccess = false; } } catch (Exception ex) { Module.Tool tool = new Module.Tool(); tool.saveToText(ex); } finally { conn.Close(); } return(isSuccess); }
private void addNewStock(string itemCode, string factory) { int facID = Convert.ToInt32(tool.getFactoryID(factory)); uStock.stock_item_code = itemCode; uStock.stock_fac_id = facID; uStock.stock_qty = 1; uStock.stock_unit = "Set"; uStock.stock_updtd_date = DateTime.Now; uStock.stock_updtd_by = MainDashboard.USER_ID; if (dalFacStock.IfExists(itemCode, facID.ToString())) { //Updating data into database bool success = dalFacStock.Update(uStock); if (!success) { //failed to update user MessageBox.Show("Failed to updated stock"); } } else { //Inserting Data into Database bool success = dalFacStock.Insert(uStock); //If the data is successfully inserted then the value of success will be true else false if (!success) { //Failed to insert data MessageBox.Show("Failed to add new stock"); } } dalItem.updateTotalStock(itemCode); }
private void stockTransfer() { bool success = false; uStock.stock_item_code = txtItemCode.Text; uStock.stock_fac_id = Convert.ToInt32(getFactoryID(cmbTo.Text)); uStock.stock_qty = getQty(txtItemCode.Text, cmbTo.Text) + Convert.ToSingle(txtQty.Text); uStock.stock_unit = Unit; uStock.stock_updtd_date = DateTime.Now; uStock.stock_updtd_by = MainDashboard.USER_ID; if (IfExists(txtItemCode.Text, cmbTo.Text)) { success = dalStock.Update(uStock); } else { success = dalStock.Insert(uStock); } if (!success) { MessageBox.Show("Failed to transfer stock"); } else { float temp = Convert.ToSingle(txtQty.Text) - overReceivedQty; dalItem.orderSubtract(txtItemCode.Text, temp.ToString()); //subtract order qty //change pmma zero cost item qty if (cmbSubFrom.Text.Equals(tool.getCustName(1))) { //dalItem.orderSubtract(txtItemCode.Text, txtQty.Text); uItem.item_code = uStock.stock_item_code; uItem.item_last_pmma_qty = dalItem.getLastPMMAQty(uItem.item_code); uItem.item_pmma_qty = dalItem.getPMMAQty(uItem.item_code) + Convert.ToSingle(txtQty.Text); uItem.item_updtd_date = uStock.stock_updtd_date; uItem.item_updtd_by = MainDashboard.USER_ID; bool itemPMMMAQtyUpdateSuccess = dalItem.UpdatePMMAQty(uItem); if (!itemPMMMAQtyUpdateSuccess) { MessageBox.Show("Failed to updated item pmma qty(@item dal)"); } } if (actionEdit) { actionEdit = false; frmOrderActionHistory.editSuccess = true; } if (ifFullyReceived()) { uOrd.ord_id = orderID; uOrd.ord_status = "RECEIVED"; dalOrd.statusUpdate(uOrd); } frmOrder.receivedNumber = txtQty.Text; orderRecordUpdate(); string from; if (string.IsNullOrEmpty(cmbSubFrom.Text)) { from = cmbFrom.Text; } else { from = cmbSubFrom.Text; } dalOrderAction.orderReceive(orderID, transferRecord("Passed"), txtQty.Text, from, cmbTo.Text, txtLotNO.Text); } if (!dalItem.updateTotalStock(txtItemCode.Text)) { MessageBox.Show("Failed to update total stock"); } }