public bool Update(itemForecastBLL u) { bool isSuccess = false; Tool tool = new Tool(); Text text = new Text(); SqlConnection conn = new SqlConnection(myconnstrng); try { String sql = @"UPDATE tbl_item_forecast SET " + ForecastQty + "=@forecast_qty," + UpdatedDate + "=@updated_date," + UpdatedBy + "=@updated_by" + " WHERE item_code=@item_code AND cust_id =@cust_id AND forecast_year = @forecast_year AND forecast_month = @forecast_month"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@cust_id", u.cust_id); cmd.Parameters.AddWithValue("@item_code", u.item_code); cmd.Parameters.AddWithValue("@forecast_year", u.forecast_year); cmd.Parameters.AddWithValue("@forecast_month", u.forecast_month); cmd.Parameters.AddWithValue("@forecast_qty", u.forecast_qty); cmd.Parameters.AddWithValue("@updated_date", u.updated_date); cmd.Parameters.AddWithValue("@updated_by", u.updated_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; tool.historyRecord(text.ForecastEdit, text.getForecastEditString(u), u.updated_date, u.updated_by); } else { //Query failed isSuccess = false; tool.historyRecord(text.System, "Failed to updated forecast(frmItemForecastDAL) " + u.item_code, u.updated_date, u.updated_by); } } catch (Exception ex) { tool.saveToText(ex); } finally { conn.Close(); } return(isSuccess); }
public string getForecastEditString(itemForecastBLL u) { string customer = "null"; if (int.TryParse(u.cust_id.ToString(), out int i)) { customer = tool.getCustName(Convert.ToInt32(u.cust_id)); } string detail = "[" + customer + "_" + u.forecast_month + u.forecast_year + "] " + tool.getItemName(u.item_code) + " (" + u.item_code + "):" + u.forecast_old_qty + " -> " + u.forecast_qty; return(detail); }
public bool Insert(itemForecastBLL u) { bool isSuccess = false; Tool tool = new Tool(); Text text = new Text(); SqlConnection conn = new SqlConnection(myconnstrng); try { String sql = @"INSERT INTO tbl_item_forecast (" + CustID + "," + ItemCode + "," + ForecastYear + "," + ForecastMonth + "," + ForecastQty + "," + UpdatedDate + "," + UpdatedBy + ") VALUES" + "(@cust_id," + "@item_code," + "@forecast_year," + "@forecast_month," + "@forecast_qty," + "@updated_date," + "@updated_by)"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@cust_id", u.cust_id); cmd.Parameters.AddWithValue("@item_code", u.item_code); cmd.Parameters.AddWithValue("@forecast_year", u.forecast_year); cmd.Parameters.AddWithValue("@forecast_month", u.forecast_month); cmd.Parameters.AddWithValue("@forecast_qty", u.forecast_qty); cmd.Parameters.AddWithValue("@updated_date", u.updated_date); cmd.Parameters.AddWithValue("@updated_by", u.updated_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; tool.historyRecord(text.ForecastInsert, text.getForecastInsertString(u), u.updated_date, u.updated_by); } else { //Query failed isSuccess = false; tool.historyRecord(text.System, "Failed to insert forecast(frmItemForecastDAL) " + u.item_code, u.updated_date, u.updated_by); } } catch (Exception ex) { tool.saveToTextAndMessageToUser(ex); } finally { conn.Close(); } return(isSuccess); }