Esempio n. 1
0
        // Issues Action begin

        bool Issues_insert_Click(Object Src, EventArgs E)
        {
            string sSQL    = "";
            bool   bResult = Issues_Validate();

            // Issues Check Event begin
            // Issues Check Event end

            if (bResult)
            {
                string p2_issue_name = CCUtility.ToSQL(Utility.GetParam("Issues_issue_name"), CCUtility.FIELD_TYPE_Text);
                string p2_issue_desc = CCUtility.ToSQL(Utility.GetParam("Issues_issue_desc"), CCUtility.FIELD_TYPE_Text);
                string p2_issue_steps_to_recreate = CCUtility.ToSQL(Utility.GetParam("Issues_steps_to_recreate"), CCUtility.FIELD_TYPE_Text);
                string p2_issue_screen            = CCUtility.ToSQL(Utility.GetParam("Issues_screen"), CCUtility.FIELD_TYPE_Text);
                string p2_issue_dev_number        = CCUtility.ToSQL(Utility.GetParam("Issues_dev_number"), CCUtility.FIELD_TYPE_Text);
                string p2_issue_its_number        = CCUtility.ToSQL(Utility.GetParam("Issues_its_number"), CCUtility.FIELD_TYPE_Text);
                string p2_priority_id             = CCUtility.ToSQL(Utility.GetParam("Issues_priority_id"), CCUtility.FIELD_TYPE_Number);
                string p2_status_id          = CCUtility.ToSQL(Utility.GetParam("Issues_status_id"), CCUtility.FIELD_TYPE_Number);
                string p2_product_id         = CCUtility.ToSQL(Utility.GetParam("Issues_product_id"), CCUtility.FIELD_TYPE_Number);
                string p2_qastatus_id        = CCUtility.ToSQL(Utility.GetParam("Issues_qastatus_id"), CCUtility.FIELD_TYPE_Number);
                string p2_category_id        = CCUtility.ToSQL(Utility.GetParam("Issues_category_id"), CCUtility.FIELD_TYPE_Number);
                string p2_bugversion         = CCUtility.ToSQL(Utility.GetParam("Issues_bugversion"), CCUtility.FIELD_TYPE_Text);
                string p2_version            = CCUtility.ToSQL(Utility.GetParam("Issues_version"), CCUtility.FIELD_TYPE_Text);
                string p2_assigned_to        = CCUtility.ToSQL(Utility.GetParam("Issues_assigned_to"), CCUtility.FIELD_TYPE_Number);
                string p2_qaassigned_to      = CCUtility.ToSQL(Utility.GetParam("Issues_qaassigned_to"), CCUtility.FIELD_TYPE_Number);
                string p2_date_submitted     = CCUtility.ToSQL(Utility.GetParam("Issues_date_submitted"), CCUtility.FIELD_TYPE_Date);
                string p2_submitted_by       = CCUtility.ToSQL(Utility.GetParam("Issues_submitted_by"), CCUtility.FIELD_TYPE_Number);
                string p2_date_modified      = CCUtility.ToSQL(Utility.GetParam("Issues_date_modified"), CCUtility.FIELD_TYPE_Date);
                string p2_assigned_to_orig   = CCUtility.ToSQL(Utility.GetParam("Issues_assigned_to_orig"), CCUtility.FIELD_TYPE_Number);
                string p2_qaassigned_to_orig = CCUtility.ToSQL(Utility.GetParam("Issues_qaassigned_to_orig"), CCUtility.FIELD_TYPE_Number);
                // Issues Insert Event begin
                p2_assigned_to_orig   = p2_assigned_to;
                p2_qaassigned_to_orig = p2_qaassigned_to;
                {
                    HttpPostedFile myFile = Request.Files[0];
                    if (myFile.FileName.Length > 0)
                    {
                        if (int.Parse(Utility.Dlookup("users", "allow_upload", "user_id=" + Session["UserID"].ToString())) == 1)
                        {
                            int      fileIndex = myFile.FileName.LastIndexOf("\\");
                            string   rawName   = myFile.FileName.Substring(fileIndex);
                            int      extIndex  = rawName.LastIndexOf(".");
                            string   fileExt   = rawName.Substring(extIndex + 1);
                            string[] allow     = Utility.Dlookup("settings", "file_extensions", "settings_id=1").Split(new char[] { ',' });
                            bool     check     = false;
                            for (int i = 0; i < allow.Length; i++)
                            {
                                if (fileExt == allow[i])
                                {
                                    check = true;
                                    break;
                                }
                            }
                            if (!check)
                            {
                                Issues_ValidationSummary.Text   += "This file type is not allowed!You may zip the file";
                                Issues_ValidationSummary.Visible = true;
                                return(false);
                            }
                        }
                        else
                        {
                            Issues_ValidationSummary.Text   += "You are not allowed to upload files!";
                            Issues_ValidationSummary.Visible = true;
                            return(false);
                        }
                    }
                }
                // Issues Insert Event end

                sSQL = "insert into issues (" +
                       "issue_name," +
                       "issue_desc," +
                       "priority_id," +
                       "status_id," +
                       "qastatus_id," +
                       "category_id," +
                       "bugversion," +
                       "version," +
                       "assigned_to," +
                       "qaassigned_to," +
                       "date_submitted," +
                       "user_id," +
                       "date_modified," +
                       "modified_by," +
                       "assigned_to_orig," +
                       "qaassigned_to_orig," +
                       "steps_to_recreate," +
                       "screen," +
                       "dev_issue_number," +
                       "its_number," +
                       "product_id)" +
                       " values (" +
                       p2_issue_name + "," +
                       p2_issue_desc + "," +
                       p2_priority_id + "," +
                       p2_status_id + "," +
                       p2_qastatus_id + "," +
                       p2_category_id + "," +
                       p2_bugversion + "," +
                       p2_version + "," +
                       p2_assigned_to + "," +
                       p2_qaassigned_to + "," +
                       p2_date_submitted + "," +
                       p2_submitted_by + "," +
                       p2_date_modified + "," +
                       p2_submitted_by + "," +
                       p2_assigned_to_orig + "," +
                       p2_qaassigned_to_orig + "," +
                       p2_issue_steps_to_recreate + "," +
                       p2_issue_screen + "," +
                       p2_issue_dev_number + "," +
                       p2_issue_its_number + "," +
                       p2_product_id + ")";
                Issues_BeforeSQLExecute(sSQL, "Insert");
                OleDbCommand cmd = new OleDbCommand(sSQL, Utility.Connection);
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    Issues_ValidationSummary.Text   += e.Message;
                    Issues_ValidationSummary.Visible = true;
                    return(false);
                }

                // Issues AfterInsert Event begin
                string issueNumber = Utility.Dlookup("issues", "max(issue_id)", "user_id=" + Session["UserID"].ToString());

                if (Request.Files.Count > 0)
                {
                    HttpPostedFile myFile = Request.Files[0];
                    if (myFile != null && myFile.FileName.Length > 0)
                    {
                        int    fileIndex = myFile.FileName.LastIndexOf("\\");
                        string rawName   = myFile.FileName.Substring(fileIndex);
                        int    extIndex  = rawName.IndexOf(".");
                        string fileExt   = rawName.Substring(extIndex);
                        string newName   = System.Guid.NewGuid().ToString() + fileExt;
                        string fileSQL   = "INSERT INTO files (file_name,issue_id,date_uploaded,uploaded_by) VALUES(";
                        fileSQL += CCUtility.ToSQL(newName, CCUtility.FIELD_TYPE_Text) + ",";
                        fileSQL += CCUtility.ToSQL(issueNumber, CCUtility.FIELD_TYPE_Number) + ",";
                        fileSQL += CCUtility.ToSQL(System.DateTime.Now.ToString("g").Replace("T", " "), CCUtility.FIELD_TYPE_Date) + ",";
                        fileSQL += CCUtility.ToSQL(Session["UserID"].ToString(), CCUtility.FIELD_TYPE_Number) + ")";
                        OleDbCommand fileCmd = new OleDbCommand(fileSQL, Utility.Connection);
                        try
                        {
                            myFile.SaveAs(Server.MapPath(Utility.Dlookup("settings", "file_path", "settings_id=1")) + "\\" + newName);
                            fileCmd.ExecuteNonQuery();
                        }
                        catch (Exception e)
                        {
                            Issues_ValidationSummary.Text   += e.Message;
                            Issues_ValidationSummary.Visible = true;
                            return(false);
                        }
                    }
                }

                //create a new postman object
                Postman post = new Postman(ref Utility);

                //create a new issue mail notification to notify the Developer this issue is assigned to
                if (Int32.Parse(Utility.Dlookup("users", "notify_new", "user_name='" + Issues_assigned_to.SelectedItem.Text + "'")) == 1)
                {
                    EmailMessage msg = new EmailMessage(Issues_assigned_to.SelectedItem.Text,
                                                        Utility.Dlookup("settings", "notify_new_from", "settings_id=1"),
                                                        Utility.Dlookup("settings", "notify_new_body", "settings_id=1"),
                                                        Utility.Dlookup("settings", "notify_new_subject", "settings_id=1"));

                    msg.SetBodyElement("issue_receiver", Issues_assigned_to.SelectedItem.Text);
                    msg.SetBodyElement("issue_no", issueNumber);
                    msg.SetBodyElement("issue_title", Issues_issue_name.Text);
                    msg.SetBodyElement("issue_url", "<a href='http://" + Request.Url.Host + Request.ApplicationPath + "/IssueChange.aspx?issue_id=" + issueNumber + "'target=\"_blank\">here</a>");
                    msg.SetBodyElement("issue_poster", Issues_submitted_by_l.Text);
                    msg.SetSubjectElement("issue_receiver", Issues_assigned_to.SelectedItem.Text);
                    msg.SetSubjectElement("issue_no", issueNumber);
                    msg.SetSubjectElement("issue_title", Issues_issue_name.Text);
                    msg.SetSubjectElement("issue_poster", Issues_submitted_by_l.Text);

                    post.AddMessage(msg, true);
                }
                //create a new issue mail notification to notify the QA person this issue is assigned to
                if (Int32.Parse(Utility.Dlookup("users", "notify_new", "user_name='" + Issues_qaassigned_to.SelectedItem.Text + "'")) == 1)
                {
                    EmailMessage msg = new EmailMessage(Issues_qaassigned_to.SelectedItem.Text,
                                                        Utility.Dlookup("settings", "notify_new_from", "settings_id=1"),
                                                        Utility.Dlookup("settings", "notify_new_body", "settings_id=1"),
                                                        Utility.Dlookup("settings", "notify_new_subject", "settings_id=1"));

                    msg.SetBodyElement("issue_receiver", Issues_qaassigned_to.SelectedItem.Text);
                    msg.SetBodyElement("issue_no", issueNumber);
                    msg.SetBodyElement("issue_title", Issues_issue_name.Text);
                    msg.SetBodyElement("issue_url", "<a href='http://" + Request.Url.Host + Request.ApplicationPath + "/IssueChange.aspx?issue_id=" + issueNumber + "'target=\"_blank\">here</a>");
                    msg.SetBodyElement("issue_poster", Issues_submitted_by_l.Text);

                    msg.SetSubjectElement("issue_receiver", Issues_qaassigned_to.SelectedItem.Text);
                    msg.SetSubjectElement("issue_no", issueNumber);
                    msg.SetSubjectElement("issue_title", Issues_issue_name.Text);
                    msg.SetSubjectElement("issue_poster", Issues_submitted_by_l.Text);


                    post.AddMessage(msg, true);
                }
                // Issues AfterInsert Event end

                //deliver outgoing e-mails
                post.DeliverMail();
            }
            return(bResult);
        }