예제 #1
0
        /// <summary>
        /// Populates new <see cref="MaintenanceRequest"/> object with user values entered into <see cref="RequestView"/> form.
        /// Finally, returns whether validation has been successful or not.
        /// </summary>
        /// <param name="m">New instance of MaintenanceRequest to be populated with user entered values</param>
        /// <returns>Returns true if user value validation is successful, else false</returns>
        private bool CreateMaintenanceRequest(MaintenanceRequest m)
        {
            if (string.IsNullOrWhiteSpace(this.addRequestView.ItemIdTextBox.Text))
            {
                Console.WriteLine("item id is null");
                return(false);
            }
            else
            {
                m.ItemId = this.addRequestView.ItemIdTextBox.Text;
            }

            if (string.IsNullOrWhiteSpace(this.addRequestView.ItemTypeTextBox.Text))
            {
                Console.WriteLine("item type is null");
                return(false);
            }
            else
            {
                m.ItemType = this.addRequestView.ItemTypeTextBox.Text;
            }

            if (string.IsNullOrWhiteSpace(this.addRequestView.MaintenanceTypeTextBox.Text))
            {
                return(false);
            }
            else
            {
                m.MaintenanceType = this.addRequestView.MaintenanceTypeTextBox.Text;
            }

            if (string.IsNullOrWhiteSpace(this.addRequestView.DescriptionText))
            {
                Console.WriteLine("description empty");
                return(false);
            }
            else
            {
                m.Description = this.addRequestView.DescriptionText;
            }

            m.Status        = this.addRequestView.StatusComboBox.SelectedItem.ToString();
            m.DateRequested = Convert.ToDateTime(DateTime.Now.ToShortDateString());

            if (this.addRequestView.DateRequiredDtp.Checked)
            {
                m.DateRequired = Convert.ToDateTime(this.addRequestView.DateRequiredDtp.Value.ToShortDateString());
            }
            else
            {
                m.DateRequired = null;
            }

            m.EnteredBy    = Environment.UserName.ToString();
            m.LastModified = DateTime.Now;
            m.ModifiedBy   = Environment.UserName.ToString();
            m.Comments     = this.addRequestView.CommentsText;
            return(true);
        }
예제 #2
0
        /// <summary>
        ///
        /// s valid <see cref="MaintenanceRequest"/> into MaintenanceRequest table
        /// </summary>
        /// <param name="m"><see cref="MaintenanceRequest"/> with valid values</param>
        private void InsertMaintenanceRequest(MaintenanceRequest m)
        {
            string commandText = "INSERT INTO MaintenanceRequest " +
                                 "(item_type, item_id, maintenance_type, status, description," +
                                 "date_requested, date_required, entered_by, last_modified, modified_by, comments)" +
                                 "VALUES (@item_type, @item_id, @maintenance_type, @status, @description," +
                                 "@date_requested, @date_required, @entered_by, @last_modified, @modified_by, @comments)";

            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MaintenanceRequest"].ConnectionString))
            {
                try
                {
                    SqlCommand command = new SqlCommand(commandText, conn);
                    //command.Parameters.AddWithValue("@request_id", m.RequestId);
                    command.Parameters.AddWithValue("@item_type", m.ItemType);
                    command.Parameters.AddWithValue("@item_id", m.ItemId);
                    command.Parameters.AddWithValue("@maintenance_type", m.MaintenanceType);
                    command.Parameters.AddWithValue("@status", m.Status);
                    command.Parameters.AddWithValue("@description", m.Description);
                    command.Parameters.AddWithValue("@date_requested", m.DateRequested);
                    if (m.DateRequired != null)
                    {
                        command.Parameters.AddWithValue("@date_required", m.DateRequired);
                    }
                    else
                    {
                        command.Parameters.AddWithValue("@date_required", DBNull.Value);
                    }
                    command.Parameters.AddWithValue("@entered_by", m.EnteredBy);
                    command.Parameters.AddWithValue("@last_modified", m.LastModified);
                    command.Parameters.AddWithValue("@modified_by", m.ModifiedBy);
                    command.Parameters.AddWithValue("@comments", m.Comments);

                    conn.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    this.addRequestView.RequestForm.Close();
                }
                catch (SqlException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
예제 #3
0
        private void AddRequestView_AcceptButtonClicked(object sender, EventArgs e)
        {
            // create new maintenance request
            MaintenanceRequest m = new MaintenanceRequest();

            Console.WriteLine("created new MR");


            // attempt to set up new MRt with form values
            if (this.CreateMaintenanceRequest(m))
            {
                // insert new MR to MaintenanceRequest
                this.InsertMaintenanceRequest(m);
                Console.WriteLine("inserted");
            }
            else
            {
                // error
                Console.WriteLine("MR create error");
            }
        }
예제 #4
0
 private bool Validate(MaintenanceRequest m)
 {
     // do some validation of fields
     return(true);
 }