Esempio n. 1
0
        public int update(ProblemReport problemReport, MySqlConnection conn)
        {
            conn.Open();
            MySqlCommand cmd = new MySqlCommand("UPDATE `problem_report` SET `Photo`=@photo,`Reason`=@reason,`Order_ID`=@orderID,`Report_date`=@reportDate,`Return_date`=@returnDate WHERE `Problem_ID`=@problemID", conn);

            cmd.Parameters.AddWithValue("@problemID", problemReport.getProblemID());
            cmd.Parameters.AddWithValue("@photo", ImageConverter.imageToByteArray(problemReport.getPhoto()));
            cmd.Parameters.AddWithValue("@reason", problemReport.getReason());
            cmd.Parameters.AddWithValue("@orderID", problemReport.getOrderID());
            cmd.Parameters.AddWithValue("@reportDate", problemReport.getReportDate().ToString("yyyy-MM-dd HH:mm:ss"));
            cmd.Parameters.AddWithValue("@returnDate", (problemReport.getReturnDate() != null) ? problemReport.getReturnDate().Value.ToString("yyyy-MM-dd HH:mm:ss") : null);
            cmd.Prepare();
            int i = cmd.ExecuteNonQuery();

            conn.Close();
            return(i);
        }
Esempio n. 2
0
        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;
                        }
                    }
                }
            }
        }