// inserting into item table public static void AddNewItem(string category, string vendor, string name, string description, string unitPrice, string quantity) { ErrorWindow errM = new ErrorWindow(); SuccessWindow sm = new SuccessWindow(); if (IsCategoryExist(category) || IsVendorExist(vendor)) { try { using ( SqlConnection connection = new SqlConnection( ConfigurationManager.ConnectionStrings["RentalConnection"].ConnectionString)) { if (connection.State == ConnectionState.Closed) { connection.Open(); string query = "INSERT INTO dbo.Item(Category_Id,Vendor_Id,Name,Description,Unit_Price,Quantity)VALUES(" + "(select Id from Category where Category_Name='" + category + "')," + "(select Id from Vendor where Company_Name = '" + vendor + "'), '" + name + "'," + "'" + description + "','" + unitPrice + "','" + quantity + "')"; var command = new SqlCommand(query, connection) { CommandType = CommandType.Text }; if (command.ExecuteNonQuery() > 0) { //command.ExecuteNonQuery(); sm.Message = "New Item is saved Successfully."; sm.Show(); } connection.Close(); } } } catch (Exception exception) { errM.Message = exception.Message; errM.Show(); } } else { errM.Message = "OOPS!!! Category Name or Vendor Name cannot be found."; errM.Show(); } }
// inserting into purchase order table table public static void Ordering(string customer, string itemName, string user, string quantity, string discount, string totalCost) { ErrorWindow errM = new ErrorWindow(); SuccessWindow sm = new SuccessWindow(); if (!IsItemExist(itemName)) { errM.Message = "OOPS!!! Item Name cannot be found, try again."; errM.Show(); } //if (!IsQuantityZero(itemName)) //{ // errM.Message = "OOPS!!! Some Item may have zero quantity, check available quantity and try again."; // errM.Show(); //} try { using ( SqlConnection connection = new SqlConnection( ConfigurationManager.ConnectionStrings["RentalConnection"].ConnectionString)) { if (connection.State == ConnectionState.Closed) { connection.Open(); string query = "INSERT INTO [dbo].[Order](Customer_Id,Item_Id,User_Id,Quantity,Discount,Total_Cost)VALUES((select Id from Customer where Full_Name = '" + customer + "'),(select Id from Item where Name = '" + itemName + "'), '" + user + "','" + quantity + "','" + discount + "','" + totalCost + "')"; var command = new SqlCommand(query, connection) { CommandType = CommandType.Text }; if (command.ExecuteNonQuery() > 0) { //command.ExecuteNonQuery(); } connection.Close(); } } } catch (Exception exception) { errM.Message = exception.Message; errM.Show(); } }
// inserting into item table public static void AddBrokenItem(string name, string quantity, string comment) { ErrorWindow errM = new ErrorWindow(); SuccessWindow sm = new SuccessWindow(); if (IsItemExist(name)) { try { using ( SqlConnection connection = new SqlConnection( ConfigurationManager.ConnectionStrings["RentalConnection"].ConnectionString)) { if (connection.State == ConnectionState.Closed) { connection.Open(); string query = "INSERT INTO dbo.Damage_Item(Item_Id,Quantity,Comment)VALUES(" + "(select Id from Item where Name='" + name + "'), '" + quantity + "'," + "'" + comment + "')"; var command = new SqlCommand(query, connection) { CommandType = CommandType.Text }; if (command.ExecuteNonQuery() > 0) { //command.ExecuteNonQuery(); sm.Message = "Damage item is recorded Successfully."; sm.Show(); } connection.Close(); } } } catch (Exception exception) { errM.Message = exception.Message; errM.Show(); } } else { errM.Message = "OOPS!!! Item Name cannot be found."; errM.Show(); } }
//updating the item price from references link // inserting into item table public static void UpdatePrice(string name, decimal price) { ErrorWindow errM = new ErrorWindow(); SuccessWindow sm = new SuccessWindow(); if (IsItemExist(name)) { try { using ( SqlConnection connection = new SqlConnection( ConfigurationManager.ConnectionStrings["RentalConnection"].ConnectionString)) { if (connection.State == ConnectionState.Closed) { connection.Open(); string query = "UPDATE dbo.Item SET Unit_Price='" + price + "' WHERE Name=(select Id from Item where Name='" + name + "')"; var command = new SqlCommand(query, connection) { CommandType = CommandType.Text }; if (command.ExecuteNonQuery() > 0) { //command.ExecuteNonQuery(); sm.Message = "Item price updated Successfully."; sm.Show(); } connection.Close(); } } } catch (Exception exception) { errM.Message = exception.Message; errM.Show(); } } else { errM.Message = "OOPS!!! Item Name cannot be found."; errM.Show(); } }
// update item stock..by returning rented item back to stock public static void ReturnItem(string name, string quantity, string id) { ErrorWindow errM = new ErrorWindow(); SuccessWindow sm = new SuccessWindow(); if (IsItemExist(name)) { try { using ( SqlConnection connection = new SqlConnection( ConfigurationManager.ConnectionStrings["RentalConnection"].ConnectionString)) { if (connection.State == ConnectionState.Closed) { connection.Open(); string query = "UPDATE dbo.Item SET Quantity +='" + quantity + "' where Id='" + id + "'"; var command = new SqlCommand(query, connection) { CommandType = CommandType.Text }; if (command.ExecuteNonQuery() > 0) { //command.ExecuteNonQuery(); sm.Message = "Item return is successfully added to stock."; sm.Show(); } connection.Close(); } } } catch (Exception exception) { errM.Message = exception.Message; errM.Show(); } } else { errM.Message = "OOPS!!! Item Name cannot be found."; errM.Show(); } }
private void sortButton_Click(object sender, EventArgs e) { if (0 == inPaths.Count) { DialogResult result = MessageBox.Show("No input file(s) selected.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (this.outPathDisplay.Text.CompareTo("") == 0) { DialogResult result = MessageBox.Show("No output file selected.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } ParseAndPrint myParser = new ParseAndPrint(inPaths, inPathCount, this.outPathDisplay.Text); try { myParser.printIntermediateData(); myParser.printMasterData(); SuccessWindow successWindow = new SuccessWindow(this.outPathDisplay.Text); successWindow.Show(); } catch (IOException) { DialogResult result = MessageBox.Show("A file with the same name as the output path specified is currently in use by another process. " + "Close it to continue.", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (DialogResult.OK == result) { sortButton_Click(sender, e); } else { return; } } }
// // inserting into user table public static void AddUser(string firstname, string lastname, string username, string password, string userrole) { ErrorWindow errM = new ErrorWindow(); SuccessWindow sm = new SuccessWindow(); try { using ( SqlConnection connection = new SqlConnection( ConfigurationManager.ConnectionStrings["RentalConnection"].ConnectionString)) { if (connection.State == ConnectionState.Closed) { connection.Open(); string query = "INSERT INTO [User](First_Name,Last_Name,Username,Password,Role_Id)VALUES('" + firstname + "','" + lastname + "','" + username + "','" + password + "',(select Id from Role where Name='" + userrole + "'))"; var command = new SqlCommand(query, connection) { CommandType = CommandType.Text }; if (command.ExecuteNonQuery() > 0) { //command.ExecuteNonQuery(); sm.Message = "New User is successfully added."; sm.Show(); } connection.Close(); } } } catch (Exception exception) { errM.Message = exception.Message; errM.Show(); } }
// inserting into purchase order table table public static void PurchaseOrder(string itemName, string vendor, string unitPrice, string quantity, string total) { ErrorWindow errM = new ErrorWindow(); SuccessWindow sm = new SuccessWindow(); if (!IsItemExist(itemName) || !IsVendorExist(vendor)) { errM.Message = "OOPS!!! Item Name cannot be found, try again."; errM.Show(); } if (!IsVendorExist(vendor)) { errM.Message = "OOPS!!! Vendor Name cannot be found, try again."; errM.Show(); } try { using ( SqlConnection connection = new SqlConnection( ConfigurationManager.ConnectionStrings["RentalConnection"].ConnectionString)) { if (connection.State == ConnectionState.Closed) { connection.Open(); string query = "INSERT INTO dbo.Purchase_Order(Vendor_Id,Item_Id,Unit_Price,Quantity,Total)VALUES(" + "(select Id from Vendor where Company_Name='" + vendor + "')," + "(select Id from Item where Name = '" + itemName + "'), '" + unitPrice + "','" + quantity + "','" + total + "')"; var command = new SqlCommand(query, connection) { CommandType = CommandType.Text }; if (command.ExecuteNonQuery() > 0) { //command.ExecuteNonQuery(); sm.Message = "New item order is processed successfully."; sm.Show(); } connection.Close(); } } } catch (Exception exception) { errM.Message = exception.Message; errM.Show(); } //} //else //{ // errM.Message = "OOPS!!! Item Name or Vendor Name cannot be found."; // errM.Show(); //} }