Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please code in c#. please note that im a complete beginner. northwind.mdf. northwind_log.ldf OrderDetailsMaintenance.zip 1. Include the two above files in the root of your

please code in c#.

please note that im a complete beginner.

northwind.mdf.

northwind_log.ldf

OrderDetailsMaintenance.zip

1. Include the two above files in the root of your OrderDetailsMaintenance project.

2. Make sure to mark them as "Content" and "Copy Always" or "Copy if newer" in the properties window of those two files.

3. Run the Scaffold-DbContext command to create a context class as well as a class to encapsulate the Orders objects from the associated table in the mdf file. Make sure to include the parameters for -Tables Customers (only worry about the attributes associated with the text boxes, you don't need to worry about any other rows from the table)

4. Once you have ran the command, include an app.config file and add a connection string element. Make sure to copy the connection string from your Context class to your app.config. Then edit your context to grab the connection string from the app.config (ConfigurationManager.ConnectionString["Northwind"].ConnectionString)

5. Code the Find button to Find the customer id and populate the details in the below text boxes.

1. If no order is found, display a message box.

6. Code the exit button

7. Code the Save button to update its attributes and call Update and SaveChanges() on that particular entity.

1. Note: If you close the program, reopen it, and search for the entity you recently updated. You may not see the changes depending on how you setup the mdf file in your project (because it copies a new version to the bin directory each time you run the program). So, if you don't see your changes, don't be alarmed.

============

HERE IS WHAT I HAVE SO FAR frmCustomerMaintenance.cs namespace OrderDetailsMaintenance { public partial class frmCustomerMaintenance : Form { public frmCustomerMaintenance() { InitializeComponent(); } } }

frmCustomerMaintenance.resx

text/microsoft-resx 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

Program.cs

namespace OrderDetailsMaintenance { internal static class Program { ///

/// The main entry point for the application. /// [STAThread] static void Main() { // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); Application.Run(new frmCustomerMaintenance()); } } }

Validator.cs

namespace OrderDetailsMaintenance { public static class Validator { private static string title = "Entry Error"; public static string Title { get => title; set => title = value; }

public static bool IsPresent(TextBox textBox) { if (textBox.Text == "") { MessageBox.Show(textBox.Tag + " is a required field.", Title); textBox.Focus(); return false; } return true; }

public static bool IsDecimal(TextBox textBox) { decimal number = 0m; if (Decimal.TryParse(textBox.Text, out number)) { return true; } else { MessageBox.Show(textBox.Tag + " must be a decimal value.", Title); textBox.Focus(); return false; } }

public static bool IsInt32(TextBox textBox) { int number = 0; if (Int32.TryParse(textBox.Text, out number)) { return true; } else { MessageBox.Show(textBox.Tag + " must be an integer.", Title); textBox.Focus(); return false; } }

public static bool IsWithinRange(TextBox textBox, decimal min, decimal max) { decimal number = Convert.ToDecimal(textBox.Text); if (number < min || number > max) { MessageBox.Show(textBox.Tag + " must be between " + min + " and " + max + ".", Title); textBox.Focus(); return false; } return true; } } }

frmCustomerMaintenance.Designer.cs

namespace OrderDetailsMaintenance { partial class frmCustomerMaintenance { ///

/// Required designer variable. /// private System.ComponentModel.IContainer components = null;

///

/// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); }

#region Windows Form Designer generated code

///

/// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.btnFind = new System.Windows.Forms.Button(); this.btnExit = new System.Windows.Forms.Button(); this.txtCustomerId = new System.Windows.Forms.TextBox(); this.txtContact = new System.Windows.Forms.TextBox(); this.txtAddress = new System.Windows.Forms.TextBox(); this.txtCity = new System.Windows.Forms.TextBox(); this.btnSave = new System.Windows.Forms.Button(); this.label3 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.label6 = new System.Windows.Forms.Label(); this.txtCountry = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(82, 39); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(130, 15); this.label1.TabIndex = 0; this.label1.Text = "Search by Customer ID:"; // // btnFind // this.btnFind.Location = new System.Drawing.Point(509, 35); this.btnFind.Name = "btnFind"; this.btnFind.Size = new System.Drawing.Size(75, 23); this.btnFind.TabIndex = 5; this.btnFind.Text = "&Find"; this.btnFind.UseVisualStyleBackColor = true; // // btnExit // this.btnExit.Location = new System.Drawing.Point(405, 338); this.btnExit.Name = "btnExit"; this.btnExit.Size = new System.Drawing.Size(75, 23); this.btnExit.TabIndex = 6; this.btnExit.Text = "E&xit"; this.btnExit.UseVisualStyleBackColor = true; // // txtCustomerId // this.txtCustomerId.Location = new System.Drawing.Point(234, 35); this.txtCustomerId.Name = "txtCustomerId"; this.txtCustomerId.Size = new System.Drawing.Size(248, 23); this.txtCustomerId.TabIndex = 7; // // txtContact // this.txtContact.Location = new System.Drawing.Point(234, 125); this.txtContact.Name = "txtContact"; this.txtContact.Size = new System.Drawing.Size(248, 23); this.txtContact.TabIndex = 9; // // txtAddress // this.txtAddress.Location = new System.Drawing.Point(234, 181); this.txtAddress.Name = "txtAddress"; this.txtAddress.Size = new System.Drawing.Size(248, 23); this.txtAddress.TabIndex = 10; // // txtCity // this.txtCity.Location = new System.Drawing.Point(234, 228); this.txtCity.Name = "txtCity"; this.txtCity.Size = new System.Drawing.Size(248, 23); this.txtCity.TabIndex = 11; // // btnSave // this.btnSave.Location = new System.Drawing.Point(274, 338); this.btnSave.Margin = new System.Windows.Forms.Padding(2, 1, 2, 1); this.btnSave.Name = "btnSave"; this.btnSave.Size = new System.Drawing.Size(81, 22); this.btnSave.TabIndex = 12; this.btnSave.Text = "&Save"; this.btnSave.UseVisualStyleBackColor = true; // // label3 // this.label3.AutoSize = true; this.label3.Location = new System.Drawing.Point(82, 128); this.label3.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(52, 15); this.label3.TabIndex = 14; this.label3.Text = "Contact:"; // // label4 // this.label4.AutoSize = true; this.label4.Location = new System.Drawing.Point(82, 184); this.label4.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(78, 15); this.label4.TabIndex = 15; this.label4.Text = "Ship Address:"; // // label5 // this.label5.AutoSize = true; this.label5.Location = new System.Drawing.Point(82, 231); this.label5.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(57, 15); this.label5.TabIndex = 16; this.label5.Text = "Ship City:"; // // label6 // this.label6.AutoSize = true; this.label6.Location = new System.Drawing.Point(82, 284); this.label6.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(79, 15); this.label6.TabIndex = 17; this.label6.Text = "Ship Country:"; // // txtCountry // this.txtCountry.Location = new System.Drawing.Point(234, 279); this.txtCountry.Name = "txtCountry"; this.txtCountry.Size = new System.Drawing.Size(248, 23); this.txtCountry.TabIndex = 18; // // frmCustomerMaintenance // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); this.Controls.Add(this.txtCountry); this.Controls.Add(this.label6); this.Controls.Add(this.label5); this.Controls.Add(this.label4); this.Controls.Add(this.label3); this.Controls.Add(this.btnSave); this.Controls.Add(this.txtCity); this.Controls.Add(this.txtAddress); this.Controls.Add(this.txtContact); this.Controls.Add(this.txtCustomerId); this.Controls.Add(this.btnExit); this.Controls.Add(this.btnFind); this.Controls.Add(this.label1); this.Name = "frmCustomerMaintenance"; this.Text = "Customer Maintenance"; this.ResumeLayout(false); this.PerformLayout();

}

#endregion

private Label label1; private Button btnFind; private Button btnExit; private TextBox txtCustomerId; private TextBox txtContact; private TextBox txtAddress; private TextBox txtCity; private Button btnSave; private Label label3; private Label label4; private Label label5; private Label label6; private TextBox txtCountry; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxiv Special Issue On Database And Expert Systems Applications Lncs 9510

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Hendrik Decker ,Lenka Lhotska ,Sebastian Link

1st Edition

366249213X, 978-3662492130

More Books

Students also viewed these Databases questions

Question

Presentation Aids Practicing Your Speech?

Answered: 1 week ago