private void ReloadCustomers() { using (igortransDBcontext db = new igortransDBcontext()) { CustomerList = db.customers.ToList(); } }
private void ReloadUsers() { using (igortransDBcontext db = new igortransDBcontext()) { UserList = db.users.ToList(); } }
private void buttonAdv5_Click(object sender, EventArgs e) // SAVE { if (materialSingleLineTextField6.Text == "") { materialSingleLineTextField6.Focus(); return; } using (igortransDBcontext db = new igortransDBcontext()) { customer csr = db.customers.Where(c => c.account == materialSingleLineTextField6.Text).FirstOrDefault(); if (csr != null) { csr = SavedRecord(csr); db.Entry(csr).State = System.Data.Entity.EntityState.Modified; } else { csr = SavedRecord(csr, true); db.Entry(csr).State = System.Data.Entity.EntityState.Added; } db.SaveChanges(); } ReloadCustomers(); ReloadList(); FormHelper.ViewModeButtons(BtnList, FormHelper.ViewMode.View, this.Name); LockFields(true); }
private void ValidateCustomer() { if (materialSingleLineTextField7.Text != "") { customer selectedCustomer = new customer(); using (igortransDBcontext db = new igortransDBcontext()) { selectedCustomer = db.customers.Where(x => x.account == materialSingleLineTextField7.Text).FirstOrDefault(); if (selectedCustomer != null) { ShowCustomer(selectedCustomer); SaveInvoice(true); } else { custSearch.Open(null, materialSingleLineTextField7.Text); if (custSearch.SelectedCustomer == null) { materialSingleLineTextField7.Focus(); ClearScreen(); } } } } else { ClearScreen(); } }
private void buttonAdv1_Click(object sender, EventArgs e) // DELETE { if (listView1.Items.Count > 1) { DialogResult res = MessageBox.Show(null, "Are you sure you want to delete this customer ?", "Delete Customer", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (res == DialogResult.Yes) { using (igortransDBcontext db = new igortransDBcontext()) { db.customers.Remove(db.customers.Where(u => u.customerid == Convert.ToInt32(listView1.SelectedItems[0].Tag)).FirstOrDefault()); db.SaveChanges(); } FormHelper.ViewModeButtons(BtnList, FormHelper.ViewMode.View, this.Name); ReloadCustomers(); ReloadList(); } } }
private void buttonAdv1_Click(object sender, EventArgs e) // DELETE { if (listView1.SelectedItems.Count == 1) { DialogResult res = MessageBox.Show(null, "Are you sure you want to delete this invoice ?", "Delete Invoice", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (res == DialogResult.Yes) { using (igortransDBcontext db = new igortransDBcontext()) { int id = Convert.ToInt32(listView1.SelectedItems[0].Tag); db.invoices.Remove(db.invoices.Where(inv => inv.invoiceid == id).FirstOrDefault()); db.invdets.RemoveRange(db.invdets.Where(invdet => invdet.invoiceid == id)); db.SaveChanges(); } FormHelper.ViewModeButtons(BtnList, FormHelper.ViewMode.View, this.Name); ReloadInvoices(); ReloadInvoicesList(); } } Vmode = FormHelper.ViewMode.View; }
private void Form_Load(object sender, EventArgs e) { LockControls(true); company Company = new company(); using (igortransDBcontext db = new igortransDBcontext()) { Company = db.companies.FirstOrDefault(); } if (Company.companyid != 0) { LoadRecord(Company); if ((Enums.AccessLevel)ApplicationSettings.LoggedUser.access_level == Enums.AccessLevel.Admin) { FormHelper.BtnEnabled(buttonAdv2, true); } else { FormHelper.BtnEnabled(buttonAdv2, false); } FormHelper.BtnEnabled(buttonAdv5, false); FormHelper.BtnEnabled(buttonAdv3, false); } }
private void DeleteToolStripMenuItem_Click(object sender, EventArgs e) { if (listView2.SelectedItems != null && (int)listView1.SelectedItems[0].Tag != 0) { using (igortransDBcontext db = new igortransDBcontext()) { int it = (int)listView1.SelectedItems[0].Tag; invoice selectedInvoice = db.invoices.Where(x => x.invoiceid == it).FirstOrDefault(); } if (SelectedInvoice.status != 2) { DialogResult res = MessageBox.Show(this, "Are you sure yoo want to delete this line ?", "Delete Invoice line", MessageBoxButtons.OK, MessageBoxIcon.Question); if (res == DialogResult.OK) { DeleteDetailsLine(); } } else { MessageBox.Show(this, "Unable to delete paid invoice", "Operation not allowed", MessageBoxButtons.OK, MessageBoxIcon.Stop); } } }
private void buttonAdv5_Click(object sender, EventArgs e) //SAVE { if (materialSingleLineTextField1.Text == "") { materialSingleLineTextField1.Focus(); return; } using (igortransDBcontext db = new igortransDBcontext()) { user usr = db.users.Where(u => u.login == materialSingleLineTextField1.Text).FirstOrDefault(); if (usr != null) { usr = SavedRecord(usr); db.Entry(usr).State = System.Data.Entity.EntityState.Modified; } else { usr = SavedRecord(usr, true); db.Entry(usr).State = System.Data.Entity.EntityState.Added; } db.SaveChanges(); } ReloadUsers(); ReloadList(); FormHelper.ViewModeButtons(BtnList, FormHelper.ViewMode.View, this.Name); LockFields(true); panel1.BackColor = Color.Gainsboro; }
private void OK_Click(Object sender, EventArgs e) { if (materialSingleLineTextField2.Text == "") { materialSingleLineTextField2.Focus(); return; } if (materialSingleLineTextField1.Text == "") { materialSingleLineTextField1.Focus(); return; } using (igortransDBcontext db = new igortransDBcontext()) { string pass = Security.Encrypt(materialSingleLineTextField1.Text, true); user loggedUser = db.users.Where(u => u.password == pass && u.login == materialSingleLineTextField2.Text).FirstOrDefault(); if (loggedUser != null) { ApplicationSettings.LoggedUser = loggedUser; IgorTransExpress x = new IgorTransExpress(); this.Hide(); x.Show(); } else { materialSingleLineTextField1.Text = ""; materialSingleLineTextField2.Text = ""; } } }
private void ShowInvoiceDetails(invoice invoice) { listView2.Items.Clear(); using (igortransDBcontext db = new igortransDBcontext()) { selectedInvoiceDetails = db.invdets.Where(x => x.invoiceid == invoice.invoiceid).ToList(); } if (selectedInvoiceDetails.Count != 0) { foreach (invdet invdet in selectedInvoiceDetails) { ListViewItem itm = new ListViewItem(); itm.Text = invdet.line.ToString(); itm.Tag = invdet.invdetid; itm.SubItems.Add(invdet.delivery_date.ToShortDateString()); itm.SubItems.Add(invdet.line_ref); itm.SubItems.Add(invdet.delivery_from); itm.SubItems.Add(invdet.delivery_to); itm.SubItems.Add(invdet.comments); itm.SubItems.Add(string.Format("{0:0,0.00}", invdet.line_total)); itm.SubItems.Add(invdet.@ref); listView2.Items.Add(itm); } } RecalcAsyncSingle(); }
private void ReloadInvoices() { using (igortransDBcontext db = new igortransDBcontext()) { InvoiceList = db.invoices.ToList(); RecalcAsyncTotalCaller(); } }
private void ReloadInvoicesList() { listView1.Items.Clear(); listView1.ForeColor = Color.Red; foreach (invoice inv in InvoiceList) { customer cust = null; using (igortransDBcontext db = new igortransDBcontext()) { cust = db.customers.Where(x => x.customerid == inv.customerid).First(); } ListViewItem itm = new ListViewItem() { Text = cust.name + " - " + inv.invoice_number, Tag = inv.invoiceid, UseItemStyleForSubItems = false, ForeColor = Color.Red }; switch (inv.status) { case 0: itm.ForeColor = Color.Red; ; break; case 1: itm.ForeColor = Color.Orange; break; case 2: itm.ForeColor = Color.Green; break; } listView1.Items.Add(itm); } listView1.Refresh(); if (InvoiceList.Count == 0) { FormHelper.AreRaisedButtonsVisible(BtnList, false); FormHelper.BtnEnabled(buttonAdv4, true); panel1.Visible = false; panel2.Visible = false; } }
private void SaveInvoice(bool isNew) { if (isNew != true) { SelectedInvoice.customerid = selectedCustomer.customerid; SelectedInvoice.date_created = dateTimePickerAdv1.Value; SelectedInvoice.date_paid = dateTimePickerAdv2.Value; SelectedInvoice.total_paid = currencyTextBox2.DecimalValue; SelectedInvoice.status = CalcInvoiceStatus(); SelectedInvoice.vat = CalcVat(); SelectedInvoice.pdf = null; SelectedInvoice.invoice_number = materialSingleLineTextField1.Text; SelectedInvoice.total = CalcTotal(); SelectedInvoice.@ref = txtInvoiceRef.Text; using (igortransDBcontext db = new igortransDBcontext()) { db.Entry(SelectedInvoice).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); SelectedInvoice = db.invoices.Where(x => x.invoiceid == SelectedInvoice.invoiceid).FirstOrDefault(); } } else { invoice newInvoice = new invoice { customerid = selectedCustomer.customerid, date_created = dateTimePickerAdv1.Value, date_paid = dateTimePickerAdv2.Value, status = 0, total = 0.00M, vat = 0.00M, pdf = null, invoice_number = GetNextInvoiceNumber().ToString(), total_paid = 0.00M, }; newInvoice.@ref = txtInvoiceRef.Text; materialSingleLineTextField1.Text = newInvoice.invoice_number; using (igortransDBcontext db = new igortransDBcontext()) { db.Entry(newInvoice).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); SelectedInvoice = db.invoices.Where(x => x.invoiceid == db.invoices.Max(xx => xx.invoiceid)).FirstOrDefault(); } } }
private void SaveDetailsRecord(bool?isNew = false) { using (igortransDBcontext db = new igortransDBcontext()) { if (isNew == true) { int ln = 1; if (db.invdets.Count(x => x.invoiceid == SelectedInvoice.invoiceid) > 0) { ln = db.invdets.Where(x => x.invoiceid == SelectedInvoice.invoiceid).Max(x => x.line) + 1; } invdet selectedInvdet = new invdet { line = ln, invoiceid = db.invoices.Max(x => x.invoiceid), delivery_date = dateTimePickerAdv3.Value, line_ref = textBoxExt1.Text, comments = textBoxExt4.Text, delivery_from = textBoxExt2.Text, delivery_to = textBoxExt3.Text, @ref = richTextBox1.Text, line_total = currencyTextBox1.DecimalValue }; db.Entry(selectedInvdet).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); } else { int currentInvdetid = Convert.ToInt32(listView2.SelectedItems[0].Tag); invdet selectedInvdet = db.invdets.Where(x => x.invdetid == currentInvdetid ).FirstOrDefault(); selectedInvdet.invoiceid = SelectedInvoice.invoiceid; selectedInvdet.delivery_date = dateTimePickerAdv3.Value; selectedInvdet.line_ref = textBoxExt1.Text; selectedInvdet.comments = textBoxExt4.Text; selectedInvdet.delivery_from = textBoxExt2.Text; selectedInvdet.delivery_to = textBoxExt3.Text; selectedInvdet.@ref = richTextBox1.Text; selectedInvdet.line_total = Convert.ToDecimal(currencyTextBox1.Text); db.Entry(selectedInvdet).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } }
private void ShowList(string searchPhrase) { listView2.Items.Clear(); using (igortransDBcontext db = new igortransDBcontext()) { CustomerList = db.customers.Where(x => x.account.Contains(searchPhrase) || x.name.Contains(searchPhrase)).ToList(); foreach (customer c in CustomerList) { ListViewItem itm = new ListViewItem(); itm.Tag = c; itm.Text = c.account; itm.SubItems.Add(c.name); listView2.Items.Add(itm); } } }
private void button1_Click(object sender, EventArgs e) { user u = new user() { login = "******", password = Security.Encrypt("test", true), access_level = 1, name = "Lukasz", surname = "Sikorski", position = "MD", email = "*****@*****.**", phone = "07861550186" }; using (igortransDBcontext db = new igortransDBcontext()) { db.users.Add(u); db.SaveChanges(); } }
private void LoadDetailLine() { int lineId = Convert.ToInt32(listView2.SelectedItems[0].Tag); using (igortransDBcontext db = new igortransDBcontext()) { invdet selectedInvdet = db.invdets.Where(x => x.invdetid == lineId).FirstOrDefault(); if (selectedInvdet != null) { dateTimePickerAdv3.Value = selectedInvdet.delivery_date; textBoxExt1.Text = selectedInvdet.line_ref; textBoxExt2.Text = selectedInvdet.delivery_from; textBoxExt3.Text = selectedInvdet.delivery_to; textBoxExt4.Text = selectedInvdet.comments; richTextBox1.Text = selectedInvdet.@ref; currencyTextBox1.DecimalValue = selectedInvdet.line_total; } } }
private void button4_Click(object sender, EventArgs e) { using (igortransDBcontext db = new igortransDBcontext()) { invoice inv = new invoice() { invoice_number = "0000001", customerid = db.customers.FirstOrDefault().customerid, date_created = DateTime.Now, date_paid = FormHelper.EmptyDate, status = 0, total = 100.45M, vat = 100.45M * 0.8M, pdf = Sql.PDFFileToByte("C:\\Users\\Lukasz\\Documents\\IMG_20170907_0001.pdf") }; db.invoices.Add(inv); db.SaveChanges(); } }
private void editToolStripMenuItem_Click(object sender, EventArgs e) //EDIT DETAIL { if (listView2.SelectedItems.Count == 1) { using (igortransDBcontext db = new igortransDBcontext()) { int xid = (int)listView1.SelectedItems[0].Tag; invoice selectedInvoice = db.invoices.Where(x => x.invoiceid == xid).FirstOrDefault(); if (selectedInvoice.status != 2) { isItemEditPanelShown(true); LoadDetailLine(); } else { MessageBox.Show(this, "Unable to edit completed invoice", "Operation terminated.", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void DeleteDetailsLine() { int lineid = Convert.ToInt32(listView2.SelectedItems[0].Tag); using (igortransDBcontext db = new igortransDBcontext()) { invdet selectedInvdet = db.invdets.Where(x => x.invdetid == lineid).FirstOrDefault(); if (selectedInvdet != null) { db.invdets.Remove(selectedInvdet); ReloadInvoices(); ReloadInvoicesList(); LockFields(true, true); FormHelper.ViewModeButtons(BtnList, FormHelper.ViewMode.View, this.Name); panel1.BackColor = Color.Gainsboro; panel2.BackColor = Color.Gainsboro; RecalcAsyncSingleCaller(); } } }
private company SavedRecord() { using (igortransDBcontext db = new igortransDBcontext()) { company result = db.companies.Where(c => c.companyid == ((company)this.Tag).companyid).FirstOrDefault(); result.name = materialSingleLineTextField1.Text; result.add1 = materialSingleLineTextField2.Text; result.add2 = materialSingleLineTextField3.Text; result.add3 = materialSingleLineTextField4.Text; result.county = materialSingleLineTextField5.Text; result.city = materialSingleLineTextField6.Text; result.postcode = materialSingleLineTextField7.Text; result.country = materialSingleLineTextField8.Text; result.telephone = materialSingleLineTextField9.Text; result.email = materialSingleLineTextField10.Text; result.vat = materialSingleLineTextField11.Text; result.logo = Sql.ImageToByte(pictureBox1.Image); return(result); } }
private void materialRaisedButton2_Click(object sender, EventArgs e) //SAVE { using (igortransDBcontext db = new igortransDBcontext()) { company cmp = cmp = SavedRecord(); db.Entry(cmp).State = System.Data.Entity.EntityState.Modified; if (db.SaveChanges() == 1) { FormHelper.BtnEnabled(buttonAdv2, true); FormHelper.BtnEnabled(buttonAdv3, false); FormHelper.BtnEnabled(buttonAdv5, false); buttonAdv4.Visible = false; LockControls(true); } else { MessageBox.Show("No changes saved"); } } panel1.BackColor = Color.Gainsboro; }
private void ShowInvoice(invoice inv, bool?isNewInvoice = false) { Vmode = FormHelper.ViewMode.View; isItemEditPanelShown(false); selectedInvoiceDetails.Clear(); customer cust; listView2.Items.Clear(); using (igortransDBcontext db = new igortransDBcontext()) { cust = db.customers.Where(c => c.customerid == inv.customerid).FirstOrDefault(); } ShowCustomer(cust); dateTimePickerAdv1.Value = inv.date_created; dateTimePickerAdv1.ForeColor = DefaultForeColor; btnShowInvoice.Visible = true; if (inv.date_paid != null) { dateTimePickerAdv2.Value = inv.date_paid; dateTimePickerAdv2.Format = DateTimePickerFormat.Long; } else { dateTimePickerAdv2.CustomFormat = " "; dateTimePickerAdv2.Format = DateTimePickerFormat.Custom; dateTimePickerAdv2.Text = ""; } materialSingleLineTextField1.Text = inv.invoice_number; materialSingleLineTextField1.Font = new Font(materialSingleLineTextField1.Font, FontStyle.Bold | FontStyle.Italic); currencyTextBox2.ReadOnly = false; currencyTextBox2.DecimalValue = inv.total_paid; txtInvoiceRef.Text = inv.@ref; SelectedInvoice = inv; panel4.Visible = true; ShowInvoiceDetails(inv); }
private void button3_Click(object sender, EventArgs e) { customer c = new customer() { account = "TST", name = "Cus 1", add1 = "Add 1", add2 = "Add 2", add3 = "Add 3", county = "County", postcode = "Postcode", country = "Country", city = "City", telephone = "4590340-934", email = "dadads" }; using (igortransDBcontext db = new igortransDBcontext()) { db.customers.Add(c); db.SaveChanges(); } }
private void buttonAdv1_Click(object sender, EventArgs e) //DELETE { if (listView1.Items.Count > 1) { DialogResult res = MessageBox.Show(null, "Are you sure you want to delete this user ?", "Delete User", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (res == DialogResult.Yes) { using (igortransDBcontext db = new igortransDBcontext()) { db.users.Remove(db.users.Where(u => u.login == materialSingleLineTextField1.Text).FirstOrDefault()); db.SaveChanges(); } ReloadUsers(); ReloadList(); FormHelper.ViewModeButtons(BtnList, FormHelper.ViewMode.View, this.Name); ClearScreen(); ShowUser(ApplicationSettings.LoggedUser); } } }
private void button2_Click(object sender, EventArgs e) { company c = new company() { name = "Igor Trans Express", add1 = "57 Whittington Street", add2 = "", add3 = "", county = "Derbyshire", country = "United Kingdom", city = "Derby", postcode = "DE249AZ", telephone = "447592337042", email = "*****@*****.**", vat = "182459289", logo = Sql.SaveFileAsBytea("..\\..\\..\\..\\..\\image\\top.png") }; using (igortransDBcontext db = new igortransDBcontext()) { db.companies.Add(c); db.SaveChanges(); } }