private void BTN_edit_Click(object sender, EventArgs e) { ConnectionClass con = new ConnectionClass(); con.OpenCon(); bool status; if (CBX_ProductStatus.SelectedIndex == 0) { status = true; } else { status = false; } if (FRM_Products.IfProductExists(con.Connection, TXT_ProductCode.Text)) { string sqlQuery = @"UPDATE [dbo].[Products] SET [Product_Name] = '" + TXT_ProductName.Text + "',[Product_Status] = '" + status + "' " + "WHERE [Product_ID] = '" + TXT_ProductCode.Text + "'"; FRM_Products.Show_MSG(LBL_AddMSG, "Porduct updated", Color.Green); SqlCommand cmd = new(sqlQuery, con.Connection); cmd.ExecuteNonQuery(); con.CloseCon(); } else { FRM_Products.Show_MSG(LBL_AddMSG, "Error", Color.Red); } }
private void BTN_Add_Click(object sender, EventArgs e) { string ProductCode = TXT_ProductCode.Text; string ProductName = TXT_ProductName.Text; int ProductStatus = CBX_ProductStatus.SelectedIndex; if (FRM_Products.Validation(ERP_ProductAdd, ProductCode, ProductName, ProductStatus, TXT_ProductCode, TXT_ProductName, CBX_ProductStatus)) { ConnectionClass con = new ConnectionClass(); con.OpenCon(); bool status; if (CBX_ProductStatus.SelectedIndex == 0) { status = true; } else { status = false; } if (FRM_Products.IfProductExists(con.Connection, TXT_ProductCode.Text)) { FRM_Products.Show_MSG(LBL_AddMSG, "Product with this code already exists", Color.OrangeRed); } else { string sqlQuery = @"INSERT INTO [dbo].[Products] ([Product_ID], [Product_Name], [Product_Status]) VALUES ('" + TXT_ProductCode.Text + "','" + TXT_ProductName.Text + "','" + status + "')"; SqlCommand cmd = new(sqlQuery, con.Connection); cmd.ExecuteNonQuery(); con.CloseCon(); FRM_Products.Show_MSG(LBL_AddMSG, "Product added to list", Color.LightGreen); } } }