Exemple #1
0
        public PostReportRemarks CreateReport(PostReport report)
        {
            var objReturn = new PostReportRemarks();

            var reportNo = "R" + RandomizeHelper.GenerateRandomString(7);

            var draft = GetDraftReport(report.reported_by_email);

            if (draft.report_no != null)
            {
                reportNo = draft.report_no;

                objReturn = new PostReportRemarks
                {
                    report_no = reportNo,
                    remarks   = "You have a pending report!",
                    subject   = "Report"
                };
            }

            else
            {
                using (var con = new MySqlConnection(ConnectionHelper.ServicesConnection()))
                {
                    con.Open();
                    var cmd = new MySqlCommand("INSERT INTO reportit_report (report_no, user, ip, reported_by, reported_by_email, reported_by_phone, reported_on, status) VALUES(@report_no, @user, @ip, @reported_by, @reported_by_email, @reported_by_phone, @reported_on, @status)", con);
                    cmd.Parameters.AddWithValue("@report_no", reportNo);
                    cmd.Parameters.AddWithValue("@user", report.reported_by_email);
                    cmd.Parameters.AddWithValue("@ip", "EEC Mobility");
                    cmd.Parameters.AddWithValue("@reported_by", report.reported_by);
                    cmd.Parameters.AddWithValue("@reported_by_email", report.reported_by_email);
                    cmd.Parameters.AddWithValue("@reported_by_phone", report.reported_by_phone);
                    cmd.Parameters.AddWithValue("@reported_on", DateTime.Now);
                    cmd.Parameters.AddWithValue("@status", "Draft");

                    if (cmd.ExecuteNonQuery() > 0)
                    {
                        objReturn = new PostReportRemarks
                        {
                            report_no = reportNo,
                            remarks   = "Successfully created new report!",
                            subject   = "Report"
                        };
                    }

                    else
                    {
                        objReturn = new PostReportRemarks
                        {
                            remarks = "Error on creation of new report!",
                            subject = "Error"
                        };
                    }
                }
            }


            return(objReturn);
        }
Exemple #2
0
        public PostReportRemarks SaveConcern(PostConcern concern)
        {
            var objReturn = new PostReportRemarks();

            try
            {
                var ticket_no  = "T" + RandomizeHelper.GenerateRandomString(7);
                var concern_no = "C" + RandomizeHelper.GenerateRandomString(7);

                string img1 = string.Empty, img2 = string.Empty, img3 = string.Empty;

                if (concern.image1 != null)
                {
                    img1 = "../imageReport/" + concern.report_no + "/" + concern_no + "_img1.png";
                }

                if (concern.image2 != null)
                {
                    img2 = "../imageReport/" + concern.report_no + "/" + concern_no + "_img2.png";
                }

                if (concern.image3 != null)
                {
                    img3 = "../imageReport/" + concern.report_no + "/" + concern_no + "_img3.png";
                }

                using (var con = new MySqlConnection(ConnectionHelper.ServicesConnection()))
                {
                    try
                    {
                        con.Open();
                        var cmd = new MySqlCommand("INSERT INTO reportit_concern (report_no, ticket_no, concern_no, description, floor, segment, specific_location, comment, image1, image2, image3, imagesLocation, status) VALUES(@report_no, @ticket_no, @concern_no, @description, @floor, @segment, @specific_location, @comment, @image1, @image2, @image3, @imagesLocation, @status)", con);

                        cmd.Parameters.AddWithValue("@report_no", concern.report_no);
                        cmd.Parameters.AddWithValue("@ticket_no", ticket_no);
                        cmd.Parameters.AddWithValue("@concern_no", concern_no);
                        cmd.Parameters.AddWithValue("@description", concern.description);
                        cmd.Parameters.AddWithValue("@floor", concern.floor);
                        cmd.Parameters.AddWithValue("@segment", concern.segment);
                        cmd.Parameters.AddWithValue("@specific_location", concern.specific_location);
                        cmd.Parameters.AddWithValue("@comment", concern.comment);
                        cmd.Parameters.AddWithValue("@image1", img1);
                        cmd.Parameters.AddWithValue("@image2", img2);
                        cmd.Parameters.AddWithValue("@image3", img3);
                        cmd.Parameters.AddWithValue("@imagesLocation", "imageReport/" + concern.report_no);
                        cmd.Parameters.AddWithValue("@date_created", DateTime.Now);
                        cmd.Parameters.AddWithValue("@status", "Draft");


                        if (cmd.ExecuteNonQuery() > 0)
                        {
                            var path = @"C:\xampp\htdocs\reportit\imageReport\" + concern.report_no;
                            //var path = AppDomain.CurrentDomain.BaseDirectory + concern.report_no;
                            bool exists = Directory.Exists(path);

                            if (!exists)
                            {
                                System.IO.Directory.CreateDirectory(path);
                            }

                            if (concern.image1 != null)
                            {
                                using (var ms = new MemoryStream(concern.image1))
                                {
                                    var img = Image.FromStream(ms);
                                    var bm  = new Bitmap(500, 500);
                                    var g   = Graphics.FromImage(bm);
                                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                                    g.DrawImage(img, 0, 0, 500, 500);
                                    g.Dispose();
                                    img = bm;

                                    var i2 = new Bitmap(img);
                                    i2.Save(path + @"\" + concern_no + "_img1.png", System.Drawing.Imaging.ImageFormat.Png);
                                }
                            }

                            if (concern.image2 != null)
                            {
                                using (var ms = new MemoryStream(concern.image2))
                                {
                                    var img = Image.FromStream(ms);
                                    var bm  = new Bitmap(500, 500);
                                    var g   = Graphics.FromImage(bm);
                                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                                    g.DrawImage(img, 0, 0, 500, 500);
                                    g.Dispose();
                                    img = bm;
                                    img.Save(path + @"\" + concern_no + "_img2.png", System.Drawing.Imaging.ImageFormat.Png);
                                }
                            }

                            if (concern.image3 != null)
                            {
                                using (var ms = new MemoryStream(concern.image3))
                                {
                                    var img = Image.FromStream(ms);
                                    var bm  = new Bitmap(500, 500);
                                    var g   = Graphics.FromImage(bm);
                                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                                    g.DrawImage(img, 0, 0, 500, 500);
                                    g.Dispose();
                                    img = bm;
                                    img.Save(path + @"\" + concern_no + "_img3.png", System.Drawing.Imaging.ImageFormat.Png);
                                }
                            }



                            objReturn = new PostReportRemarks
                            {
                                remarks = "Successfully added new concern!",
                                subject = "Concern"
                            };
                        }

                        else
                        {
                            objReturn = new PostReportRemarks
                            {
                                remarks = "Error on adding of new concern!",
                                subject = "Error"
                            };
                        }
                    }

                    catch (Exception e)
                    {
                        objReturn = new PostReportRemarks
                        {
                            remarks = e.InnerException.ToString(),
                            subject = "Error"
                        };
                    }
                }
            }

            catch (Exception ex)
            {
                objReturn = new PostReportRemarks
                {
                    remarks = ex.InnerException.ToString(),
                    subject = "Error"
                };
            }
            return(objReturn);
        }