private void button2_Click(object sender, EventArgs e) { try { Sale_Refund refund = new Sale_Refund(); refund.Refund_Date = DateTime.Now; db.Sale_Refund.Add(refund); db.SaveChanges(); foreach (var item in salereturnlist) { Refund_Line refundline = new Refund_Line(); refundline.Refund_Amount = Convert.ToDecimal(item.GrossPrice); refundline.Refund_Quantity = item.Quantity; refundline.Sales_Order_Line_ID = item.SaleLineID; refundline.Sale_Refund_ID = RetrieveLastSaleRefundID(); db.Refund_Line.Add(refundline); db.SaveChanges(); } MessageBox.Show("Success"); } catch (Exception err) { MessageBox.Show(err.ToString()); } }
private void button1_Click_1(object sender, EventArgs e) { tabControl1.SelectedIndex = 1; List <SOSummary> mylist = new List <SOSummary>(); DataGridViewRow row = new DataGridViewRow(); dataGridView3.Rows.Clear(); dataGridView2.Rows.Clear(); for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (Convert.ToInt32(dataGridView1.Rows[i].Cells["received"].Value) == 1) { row = (DataGridViewRow)dataGridView1.Rows[i].Clone(); int intColIndex = 0; foreach (DataGridViewCell cell in dataGridView1.Rows[i].Cells) { row.Cells[intColIndex].Value = cell.Value; intColIndex++; } dataGridView2.Rows.Add(row); dataGridView2.AllowUserToAddRows = false; dataGridView2.Refresh(); } else if (Convert.ToInt32(dataGridView1.Rows[i].Cells["received"].Value) == 0) { row = (DataGridViewRow)dataGridView1.Rows[i].Clone(); int intColIndex = 0; foreach (DataGridViewCell cell in dataGridView1.Rows[i].Cells) { row.Cells[intColIndex].Value = cell.Value; intColIndex++; } dataGridView3.Rows.Add(row); dataGridView3.AllowUserToAddRows = false; dataGridView3.Refresh(); } } foreach (DataGridViewRow r in dataGridView2.Rows) { string product = r.Cells[1].Value.ToString(); var q = db.Getpoduct().Where(x => x.Product_Description == product).First(); //int w = Convert.ToInt32(q.Available_Quantity); q.Available_Quantity += Convert.ToInt32(r.Cells[2].Value); db.Products.Where(x => x.Product_ID == q.Product_ID).First().Available_Quantity += q.Available_Quantity; db.SaveChanges(); } if (dataGridView2.RowCount == dataGridView1.RowCount) { var q1 = db.Supplier_Order.Where(x => x.SO_Number == textBox1.Text).First(); q1.Supplier_Order_Status_ID = 2; db.SaveChanges(); } }
public void DecreaseProductQuantityOnHand(int ID, int quantity) { foreach (var item in db.Products) { if (ID == item.Product_ID) { item.Available_Quantity = item.Available_Quantity - quantity; break; } } db.SaveChanges(); }
private void button2_Click(object sender, EventArgs e) { if (newSO != null) { int prid = Convert.ToInt32(comboBox2.SelectedValue); var q = db.Products.Where(p => p.Product_ID == prid).FirstOrDefault(); var q1 = db.Supplier_Order_Line.Where(sol => sol.Product_ID == prid && sol.Supplier_Order_Id == newSO.Supplier_Order_Id).FirstOrDefault(); if (newSOL == null) { newSOL = new Supplier_Order_Line() { Supplier_Order_Id = newSO.Supplier_Order_Id, Product_ID = Convert.ToInt32(comboBox2.SelectedValue), Quantity = Convert.ToInt32(numericUpDown1.Value) }; db.Supplier_Order_Line.Add(newSOL); db.SaveChanges(); var q2 = db.Supplier_Order.Where(x => x.Supplier_Order_Id == newSO.Supplier_Order_Id).First(); dataGridView1.DataSource = db.GetSOL(newSO.Supplier_Order_Id).Where(x => x.SO_Number == q2.SO_Number).ToList(); } else { var q3 = db.Supplier_Order.Where(x => x.Supplier_Order_Id == newSO.Supplier_Order_Id).First(); if (q1 == null) { newSOL = new Supplier_Order_Line() { Supplier_Order_Id = newSO.Supplier_Order_Id, Product_ID = Convert.ToInt32(comboBox2.SelectedValue), Quantity = Convert.ToInt32(numericUpDown1.Value) }; db.Supplier_Order_Line.Add(newSOL); //q.Available_Quantity -= Convert.ToInt32(numericUpDown1.Value); db.SaveChanges(); dataGridView1.DataSource = db.GetSOL(newSO.Supplier_Order_Id).Where(x => x.SO_Number == q3.SO_Number).ToList(); } else { var q4 = db.Supplier_Order_Line.Where(sol => sol.Supplier_Order_Id == newSO.Supplier_Order_Id && sol.Supplier_Order_Line_ID == q1.Supplier_Order_Line_ID). FirstOrDefault(); q4.Quantity += Convert.ToInt32(numericUpDown1.Value); //q.Available_Quantity -= Convert.ToInt32(numericUpDown1.Value); db.SaveChanges(); dataGridView1.DataSource = db.GetSOL(newSO.Supplier_Order_Id).Where(x => x.SO_Number == q3.SO_Number).ToList(); } } } }
private void btnReturn_Click(object sender, EventArgs e) { try { var q = db.Client_Purchase_Order_Line.Where(op => op.Client_Purchase_Order_Line_ID == polid).FirstOrDefault(); int prid = Convert.ToInt32(q.Product_ID.ToString()); var q1 = db.Products.Where(op => op.Product_ID == prid).FirstOrDefault(); newCRL = new Credit_Return_Line() { Client_Purchase_Order_Line_ID = polid, Quantity_Returned = Convert.ToInt32(textBox7.Text), Reason_For_Return_ID = Convert.ToInt32(comboBox1.SelectedValue), Credit_Return_ID = newCR.Credit_Return_Id, Credit_Return_Amount = Convert.ToDecimal(q1.Order_Price.ToString()) * Convert.ToInt32(textBox7.Text) }; db.Credit_Return_Line.Add(newCRL); db.SaveChanges(); dataGridView2.DataSource = db.Get_Credit_Return_Line(newCR.Credit_Return_Id); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void btnPOLRemove_Click(object sender, EventArgs e) { if (MessageBox.Show("Are you sure you want to remove this item?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { try { db.Client_Purchase_Order_Line. Remove(db.Client_Purchase_Order_Line.Where(pol => pol.Client_Purchase_Order_Line_ID == polid). FirstOrDefault() as Client_Purchase_Order_Line); db.SaveChanges(); loadPurcaseOrderLineResultBindingSource.DataSource = db.GetPOL(poid).ToList(); CalculateSubtotal(); //decimal sum = 0; //xPO = db.Client_Purchase_Order.Single(p => p.Client_Purchase_Id == poid); //foreach (DataGridViewRow ar in dgvPOL.Rows) //{ // sum += (Convert.ToInt32(ar.Cells[dgvPOL.Columns["quantity"].Index].Value) * //Convert.ToDecimal(ar.Cells[dgvPOL.Columns["order_price"].Index].Value)); //} //xPO.Gross_Amount = sum; if (r.IsNewRow == false) { decimal grossAmount = Convert.ToDecimal(db.GetPOL(newPO.Client_Purchase_Id).Sum(pol => pol.Subtotal)); } //db.Client_Purchase_Order.a(xpo); db.SaveChanges(); dgvPO.DataSource = db.Load_Purchase_Order().ToList(); //dgvPO.Refresh(); // btnPOLRemove.Enabled = false; } catch (Exception) { MessageBox.Show("Table is empty. There are no records to be removed."); } } }
private void btnAddCty_Click(object sender, EventArgs e) { try { NewCity.City_Name = txtctyName.Text; NewCity.Province_ID = Convert.ToInt32(cbProvince.SelectedValue.ToString()); db.Cities.Add(NewCity); db.SaveChanges(); MessageBox.Show("City has been added successfully"); this.Close(); } catch (Exception) { } }
private void button3_Click(object sender, EventArgs e) { // var q = db.Clients.Where(x => x.Client_Name == txtName.Text).ToList(); Client NewCllient = new Client(); Credit_Approval NewCA = new Credit_Approval(); Credit_Approval Credit_Approval_Form = new Credit_Approval(); City newCity = new City(); Credit_Status crStatus = new Credit_Status(); Client_Account_Status cAS = new Client_Account_Status(); Province NewProv = new Province(); if (txtName.Text == "" || txtVatRegNum.Text == "" || txtTelephone.Text == "" || txtFaxNumber.Text == "" || txtEmailAdd.Text == "" || txtPhysicalAdd.Text == "") { MessageBox.Show("Please enter all fields!"); } else if (db.Load_Client().Where(x => x.VAT_Registration_No_ == txtVatRegNum.Text).ToList() == null) { try { // NewCA.Credit_Approval_Form = Convert.ToString(txtFilePath.Text); // txtFilePath.Text = Convert.ToBase64String(NewCA.Credit_Approval_Form); // NewCA.Credit_Approval_Form = Encoding.ASCII.GetBytes(txtFilePath.Text); NewCA.Credit_Approval_Amount = Convert.ToInt32(txtCreditAmount.Text); NewCA.Date_Of_Commencement = txtDateTimeDateOfCommencement.Value.Date; db.Credit_Approval.Add(NewCA); NewCllient.Client_Name = txtName.Text; NewCllient.Client_VAT_Reg_Number = txtVatRegNum.Text; NewCllient.Client_Telephone = "+27" + txtTelephone.Text; NewCllient.Client_Fax_Number = txtFaxNumber.Text; NewCllient.Client_Email_Address = txtEmailAdd.Text; NewCllient.Physical_Address = txtPhysicalAdd.Text; NewCllient.Province_Id = Convert.ToInt32(cbxProvince.SelectedValue.ToString()); NewCllient.City_Id = Convert.ToInt32(cbxCity.SelectedValue); NewCllient.Account_Status_ID = Convert.ToInt32(cbxAccountStatus.SelectedValue); NewCllient.Credit_Approval_ID = NewCA.Credit_Approval_ID; db.Clients.Add(NewCllient); db.SaveChanges(); MessageBox.Show("Client Has been Added succesfully"); //Audit Log int Client_Id = NewCllient.Client_ID; string client_Value = Convert.ToString(NewCllient); Audit_Log Current_Audit3 = new Audit_Log(); Current_Audit3.Table_Name = "Client"; // Current_Audit3.Users_Id = Globals.Users_Id; Current_Audit3.Date_Time = DateTime.Now; db.Audit_Log.Add(Current_Audit3); db.SaveChanges(); int Log_ID3 = Current_Audit3.Audit_Log_Id; Audit_Create_Delete Current_Create3 = new Audit_Create_Delete(); Current_Create3.Audit_Log_Id = Log_ID3; Current_Create3.Created = true; Current_Create3.PK_Row_Effected = Client_Id; Current_Create3.Value = client_Value; db.Audit_Create_Delete.Add(Current_Create3); db.SaveChanges(); this.Close(); this.Hide(); //MessageBox.Show("Are you sure you want to add this client ?", "confirmation", MessageBoxButtons.YesNo); //MessageBox.Show("Client details have been added successfully"); //MessageBox.Show("Client already exists on the system"); //MessageBox.Show("Please fill in all required fields"); //MessageBox.Show("Please select a client"); } catch (Exception) { } } else { MessageBox.Show("The Client with the VAT Registration Number: " + txtVatRegNum.Text + " already exists in the database"); } }
//public int RetrieveLastImageID() //{ // int ID = 0; // List<Product> MyList = new List<Product>(); // List<Product> ReturnList = new List<Product>(); // foreach (var item in db.Products) // { // MyList.Add(item); // } // ReturnList.Add(MyList.Last()); // foreach (var item in ReturnList) // { // ID = item.; // break; // } // return ID; //} private void btnAdd_Click(object sender, EventArgs e) { try { //{ // if (ValidateIfProductExists(txtDescription.Text) == true) // { // MessageBox.Show("Product exists"); // } correct = true; Product prod = new Product(); //Sales_Unit_Price Price = new Sales_Unit_Price(); Product Image = new Product(); if (txtDescription.Text == "" || txtQuantity.Text == "0" || cbxprodT.Items == null || cbxbrand.Items == null || txtPrice.Text == null || cbxPly.Items == null || cbxPackSize.Items == null || cbxSheet.Items == null || cbxLength.Items == null || cbxWidth.Items == null) { MessageBox.Show("Please Enter all fields on the product Form"); correct = false; } if (txtDescription.Text == "") { //lblProdWarning.ForeColor = Color.Red; lblProdDescr.Visible = true; correct = false; } if (txtQuantity.Text == "0") { lblavailQuan.ForeColor = Color.Red; lblavailQuan.Text = "Invalid Quantity"; correct = false; } if (correct == true) { if (PictureAdded == true) { // Image.Image_Name = txtImageName.Text; prod.Product_Brand_ID = Convert.ToInt32(cbxbrand.SelectedValue); prod.Length_ID = Convert.ToInt32(cbxLength.SelectedValue); prod.Pack_Size_ID = Convert.ToInt32(cbxPackSize.SelectedValue); prod.Sheet_ID = Convert.ToInt32(cbxSheet.SelectedValue); prod.Ply_ID = Convert.ToInt32(cbxPly.SelectedValue); prod.Product_Type_ID = Convert.ToInt32(cbxprodT.SelectedValue); prod.Available_Quantity = Convert.ToInt32(txtQuantity.Text); prod.Product_Description = txtDescription.Text; prod.Width_ID = Convert.ToInt32(cbxWidth.SelectedValue); prod.Sales_Price = Convert.ToDecimal(txtPrice.Text); string fileName = Path.GetFileName(txtImage.Text); prod.Image = "../Image/Lopac/" + fileName; db.Products.Add(prod); db.SaveChanges(); } else { prod.Product_Brand_ID = Convert.ToInt32(cbxbrand.SelectedValue); prod.Length_ID = Convert.ToInt32(cbxLength.SelectedValue); prod.Pack_Size_ID = Convert.ToInt32(cbxPackSize.SelectedValue); prod.Sheet_ID = Convert.ToInt32(cbxSheet.SelectedValue); prod.Ply_ID = Convert.ToInt32(cbxPly.SelectedValue); prod.Product_Type_ID = Convert.ToInt32(cbxprodT.SelectedValue); prod.Available_Quantity = Convert.ToInt32(txtQuantity.Text); prod.Product_Description = txtDescription.Text; prod.Width_ID = Convert.ToInt32(cbxWidth.SelectedValue); prod.Sales_Price = Convert.ToDecimal(txtPrice.Text); db.Products.Add(prod); db.SaveChanges(); } MessageBox.Show("Product Successfully added"); } } catch (NullReferenceException) { MessageBox.Show("Product Added"); } }
private void button2_Click(object sender, EventArgs e) { correct = true; if (txtName.Text == "" || txtVatRegNum.Text == "" || txtTelephone.Text == "" || txtFaxNumber.Text == "" || txtEmailAdd.Text == "" || txtPhysicalAdd.Text == "") { MessageBox.Show("Please enter all fields!"); correct = false; } DialogResult dialogResult = MessageBox.Show("Would you like to update the client Information ?", "Update Template", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { if (correct == true) { try { if (correct == true) { var query = db.Clients.Where(co => co.Client_ID == ClientID).FirstOrDefault(); var query1 = db.Provinces.Where(co => co.Province_Id == query.Province_Id).FirstOrDefault(); var query2 = db.Cities.Where(co => co.City_Id == query.City_Id).FirstOrDefault(); var query3 = db.Credit_Approval.Where(co => co.Credit_Approval_ID == query.Credit_Approval_ID).FirstOrDefault(); var query4 = db.Credit_Status.Where(co => co.Credit_Status_ID == query3.Credit_Approval_ID).FirstOrDefault(); var query5 = db.Client_Account_Status.Where(co => co.Account_Status_ID == query3.Credit_Approval_ID).FirstOrDefault(); Client NewCllient = new Client(); Credit_Approval NewCA = new Credit_Approval(); City newCity = new City(); Credit_Status crStatus = new Credit_Status(); Client_Account_Status cAS = new Client_Account_Status(); Province NewProv = new Province(); NewCllient = db.Clients.Where(co => co.Client_ID == ClientID).FirstOrDefault(); NewCA = db.Credit_Approval.Where(co => co.Credit_Approval_ID == query3.Credit_Approval_ID).FirstOrDefault(); newCity = db.Cities.Where(co => co.City_Id == query.City_Id).FirstOrDefault(); crStatus = db.Credit_Status.Where(co => co.Credit_Status_ID == query.Credit_Approval_ID).FirstOrDefault(); cAS = db.Client_Account_Status.Where(co => co.Account_Status_ID == query.Credit_Approval_ID).FirstOrDefault(); query.Client_Name = txtName.Text; query.Client_VAT_Reg_Number = txtVatRegNum.Text; query.Client_Telephone = "+27" + txtTelephone.Text; query.Client_Fax_Number = txtFaxNumber.Text; query.Physical_Address = txtPhysicalAdd.Text; query.Client_Email_Address = txtEmailAdd.Text; query1.Province_Name = cbxProvince.Text; query2.City_Name = cbxCity.Text; query3.Credit_Approval_Amount = Convert.ToDecimal(txtCreditAmount.Text); if (query3.Credit_Status_ID == null) { cbxCreditStatus.SelectedIndex = -1; } else { query4.Credit_Status_Description = cbxCreditStatus.Text; } NewCA.Credit_Approval_ID = crStatus.Credit_Status_ID; query5.Account_Status_Description = comboBox5.Text; query3.Credit_Approval_Form = FileData; //query3.Credit_Approval_Form = Encoding.ASCII.GetBytes(txtFilePath.Text); db.SaveChanges(); MessageBox.Show("Client Has been updated succesfully"); this.Close(); } } catch (Exception ex) { MessageBox.Show("Error has occured, and template was not updated successfully" + ex); } } } }