public ProblemReport getOneReportByID(int problemID, MySqlConnection conn) { conn.Open(); MySqlCommand cmd = new MySqlCommand("SELECT `problem_report`.`Problem_ID`, `problem_report`.`Photo`, `problem_report`.`Reason`, `problem_report`.`Order_ID`, `customer`.`Customer_Surname`, `customer`.`Customer_GivenName`, `customer`.`Regeion_Code`, `customer`.`Mobile_Phone_No`, " + "`problem_report`.`Report_date`, `problem_report`.`Return_date` FROM `problem_report`, `customer`, `order` " + "WHERE `problem_report`.`Order_ID`=`order`.`Order_ID` AND `order`.`Customer_ID`=`customer`.`Customer_ID` AND `problem_report`.`Date_Deleted` IS NULL AND `problem_report`.`Problem_ID`=@problemID", conn); cmd.Parameters.AddWithValue("@problemID", problemID); cmd.Prepare(); MySqlDataAdapter adapter = new MySqlDataAdapter(cmd); DataTable dt = new DataTable(); adapter.Fill(dt); ProblemReport problemReport = new ProblemReport(); foreach (DataRow item in dt.Rows) { problemReport.setProblemID(int.Parse(item["Problem_ID"].ToString())); problemReport.setPhoto(ImageConverter.byteArrayToImage((byte[])item["Photo"])); problemReport.setReason(item["Reason"].ToString()); problemReport.setOrderID(((uint)item["Order_ID"]).ToString("0000000000")); problemReport.setCustSurname(item["Customer_Surname"].ToString()); problemReport.setCustGivenName(item["Customer_GivenName"].ToString()); problemReport.setCustRegeionCode((int)item["Regeion_Code"]); problemReport.setCustMobilePhoneNo((int)item["Mobile_Phone_No"]); problemReport.setReportDate(Convert.ToDateTime(item["Report_date"])); if (!Convert.IsDBNull(item["Return_date"])) { problemReport.setReturnDate(Convert.ToDateTime(item["Return_date"])); } } conn.Close(); return(problemReport); }
private void addButton_Click(object sender, EventArgs e) { bool error = false; if (string.IsNullOrWhiteSpace(reasonComboBox.Text)) { reasonHintLabel.ForeColor = Color.Red; error = true; } else { reasonHintLabel.ForeColor = SystemColors.ControlText; } if (photoBox.Image == null) { photoHintLabel.ForeColor = Color.Red; error = true; } else { photoHintLabel.ForeColor = SystemColors.ControlText; } if (!error) { if (MessageBox.Show((!naReturnDateCheckBox.Checked) ? rs.GetString("askAddReportDialogbox") : rs.GetString("askAddReportExceptReturnDateDialogbox"), "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { ProblemReport pr = new ProblemReport(); pr.setOrderID(orderDetail.getOrderID()); pr.setReportDate(DateTime.Now); showReportDateLabel.Enabled = false; pr.setReason(reasonComboBox.SelectedValue.ToString()); reasonComboBox.Enabled = false; reasonHintLabel.Enabled = false; pr.setPhoto(photoBox.Image); photoBox.Enabled = false; browsePhotoButton.Enabled = false; photoHintLabel.Enabled = false; if (!naReturnDateCheckBox.Checked) { pr.setReturnDate(returnDateTime.Value); naReturnDateCheckBox.Checked = false; naReturnDateCheckBox.Enabled = false; returnDateTime.Enabled = false; recordReturnDateButton.Enabled = false; } addButton.Enabled = false; int i = prda.insert(pr, conn); MessageBox.Show(rs.GetString("addNewReportSuccessMsg")); reportDataGridView.Rows.Add(pr.getProblemID(), pr.getReportDate().ToLongDateString() + ", " + pr.getReportDate().ToLongTimeString()); reportDataGridView.ClearSelection(); foreach (DataGridViewRow row in reportDataGridView.Rows) { if ((pr.getProblemID().ToString()).Equals(row.Cells["problemIdColumn"].Value.ToString())) { row.Selected = true; reportDataGridView.FirstDisplayedScrollingRowIndex = row.Index; } } } } }