Пример #1
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     using (var context = new ManagementDbEntities())
     {
         if (selectedID > 0)
         {
             var selectCustomer = context.Customers.Where(c => c.Id == selectedID).FirstOrDefault();
             selectCustomer.Name          = txtName.Text;
             selectCustomer.ContactPerson = txtContactPerson.Text;
             selectCustomer.Contact       = txtContact.Text;
             selectCustomer.Address       = txtAddress.Text;
             context.SaveChanges();
             this.Close();
         }
         else
         {
             var newCustomer = new Customers
             {
                 Name          = txtName.Text,
                 ContactPerson = txtContactPerson.Text,
                 Contact       = txtContact.Text,
                 Address       = txtAddress.Text,
             };
             context.Customers.Add(newCustomer);
             context.SaveChanges();
             this.Close();
         }
     }
 }
Пример #2
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (txtStockInQuantity.Text == string.Empty)
     {
         labWarning.Visible = true;
     }
     if (!labWarning.Visible)
     {
         using (var context = new ManagementDbEntities())
         {
             context.Products.Where(c => c.Id == selectedProduct.Id).FirstOrDefault().Quantity = double.Parse(txtTotalQuantity.Text);
             var newRecord = new StockInRecords
             {
                 ProductName  = comboProducts.Text,
                 ProductNotes = txtNotes.Text,
                 ProductSpec  = txtSpec.Text,
                 ProductUnit  = txtUnit.Text,
                 Quantity     = double.Parse(txtStockInQuantity.Text),
                 Date         = dtPicker.Value,
             };
             context.StockInRecords.Add(newRecord);
             context.SaveChanges();
             this.Close();
         }
     }
 }
Пример #3
0
 private void btnSubmit_Click(object sender, EventArgs e)
 {
     using (var context = new ManagementDbEntities())
     {
         string password    = textBoxPassword.Text;
         string newPassword = txtNewPassword.Text;
         var    user        = context.Users.FirstOrDefault();
         if (user != null)
         {
             labelWarning.Visible = false;
             var hashedPassword = con.HashPassword(password);
             if (user.Password.SequenceEqual(hashedPassword))
             {
                 var hashedNewPassWord = con.HashPassword(newPassword);
                 user.Password = hashedNewPassWord;
                 context.SaveChanges();
                 this.Close();
             }
             else
             {
                 labelWarning.Visible = true;
             }
         }
     }
 }
Пример #4
0
        private string GetInvoiceNumber()
        {
            string invoiceNumber;

            using (var context = new ManagementDbEntities())
            {
                var counter = context.Counters.Where(c => c.Name == "invoice").FirstOrDefault();
                if (counter == null)
                {
                    var newCounter = new Counters
                    {
                        Name   = "invoice",
                        Format = "<YYYYMM>0000",
                        Value  = "<YYYYMM>0000",
                    };
                    context.Counters.Add(newCounter);
                    context.SaveChanges();
                }
                counter = context.Counters.Where(c => c.Name == "invoice").FirstOrDefault();
                if (counter.Value == "<YYYYMM>0000")
                {
                    counter.Value = DateTime.Today.Year.ToString() + string.Format("{0:00}", DateTime.Today.Month) + "0000";
                }
                else
                {
                    string counterValue;
                    int    number;
                    if (counter.Value.Substring(0, 4) == DateTime.Today.Year.ToString() && counter.Value.Substring(4, 2) == string.Format("{0:00}", DateTime.Today.Month))
                    {
                        counterValue = counter.Value.Substring(6, 4);
                        int.TryParse(counterValue, out number);
                        number      += 1;
                        counterValue = string.Format("{0:0000}", number);
                    }
                    else
                    {
                        counterValue = "0000";
                    }
                    counter.Value = DateTime.Today.Year.ToString() + string.Format("{0:00}", DateTime.Today.Month) + counterValue;
                }

                invoiceNumber = counter.Value;
                context.SaveChanges();
            }
            return(invoiceNumber);
        }
Пример #5
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (txtPrice.Text == string.Empty)
     {
         labWarning.Visible = true;
     }
     if (!labWarning.Visible)
     {
         using (var context = new ManagementDbEntities())
         {
             if (selectedID > 0)
             {
                 var selectProduct = context.Products.Where(c => c.Id == selectedID).FirstOrDefault();
                 selectProduct.Name  = txtName.Text;
                 selectProduct.Spec  = txtSpec.Text;
                 selectProduct.Unit  = comUnit.Text;
                 selectProduct.Price = double.Parse(txtPrice.Text);
                 selectProduct.Notes = txtNotes.Text;
                 context.SaveChanges();
                 this.Close();
             }
             else
             {
                 var newProduct = new Products
                 {
                     Name     = txtName.Text,
                     Spec     = txtSpec.Text,
                     Unit     = comUnit.Text,
                     Price    = double.Parse(txtPrice.Text),
                     Notes    = txtNotes.Text,
                     Quantity = 0,
                 };
                 context.Products.Add(newProduct);
                 context.SaveChanges();
                 this.Close();
             }
         }
     }
 }
Пример #6
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     using (var context = new ManagementDbEntities())
     {
         var itemToRemove = context.Products.Where(c => c.Id == currentSelectID).FirstOrDefault();
         if (itemToRemove != null)
         {
             context.Products.Remove(itemToRemove);
             context.SaveChanges();
         }
         refreshProducts();
     }
 }
Пример #7
0
 private void btnSubmit_Click(object sender, EventArgs e)
 {
     using (var context = new ManagementDbEntities())
     {
         var user = context.Users.FirstOrDefault();
         user.Name           = txtName.Text;
         user.CompanyName    = txtCompanyName.Text;
         user.CompanyAddress = txtCompanyAddress.Text;
         user.CompanyContact = txtCompanyContact.Text;
         user.CompanyFax     = txtComapnyFax.Text;
         user.InvoiceCreator = txtInvoiceMaker.Text;
         context.SaveChanges();
         this.Close();
     }
 }
Пример #8
0
        private void btnInvoice_Click(object sender, EventArgs e)
        {
            bool   thisCanBeProceed = true;
            int    quantity;
            double price;

            labWarning.Visible = false;
            foreach (DataGridViewRow row in GridProducts.Rows)
            {
                if (row.Cells["ColQuantity"].Value == null)
                {
                    thisCanBeProceed   = false;
                    labWarning.Visible = true;
                    break;
                }
                if (row.Cells["ColQuantity"].Value.ToString() == string.Empty || !int.TryParse(row.Cells["ColQuantity"].Value.ToString(), out quantity))
                {
                    thisCanBeProceed   = false;
                    labWarning.Visible = true;
                    break;
                }
                if (row.Cells["ColPrice"].Value == null)
                {
                    thisCanBeProceed   = false;
                    labWarning.Visible = true;
                    break;
                }
                if (row.Cells["ColPrice"].Value.ToString() == string.Empty || !double.TryParse(row.Cells["ColPrice"].Value.ToString(), out price))
                {
                    thisCanBeProceed   = false;
                    labWarning.Visible = true;
                    break;
                }
                //Products selectedProduct;
                //DataGridViewComboBoxCell cb = (DataGridViewComboBoxCell)row.Cells["ColName"];
                //selectedProduct = products.Where(p => p.Id.ToString() == Convert.ToString(cb.Value)).FirstOrDefault();
                //if (selectedProduct.Quantity < quantity)
                //{
                //    thisCanBeProceed = false;
                //    MessageBox.Show(selectedProduct.Name + "库存不足", "错误", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
                //    break;
                //}
            }
            if (thisCanBeProceed)
            {
                string invoiceNumber;
                invoiceNumber = GetInvoiceNumber();
                using (var context = new ManagementDbEntities())
                {
                    foreach (DataGridViewRow row in GridProducts.Rows)
                    {
                        price    = double.Parse(row.Cells["ColPrice"].Value.ToString());
                        quantity = int.Parse(row.Cells["ColQuantity"].Value.ToString());
                        var total     = price * quantity;
                        var newRecord = new StockOutRecords
                        {
                            CustomerName          = comboCustomerName.Text,
                            CustomerContactPerson = txtContactPerson.Text,
                            CustomerContact       = txtContact.Text,
                            CustomerAddress       = txtAddress.Text,
                            Date               = DateTime.Today.Date,
                            InvoiceNumber      = invoiceNumber,
                            ProductSpec        = row.Cells["ColSpec"].Value.ToString(),
                            ProductUnit        = row.Cells["ColUnit"].Value.ToString(),
                            ProductPrice       = price,
                            ProductNotes       = row.Cells["ColNotes"].Value.ToString(),
                            ProductQuantity    = quantity,
                            ProductTotalAmount = total,
                            ProductName        = row.Cells["ColName"].EditedFormattedValue.ToString(),
                            Order              = row.Index + 1,
                        };
                        context.StockOutRecords.Add(newRecord);
                        //Products selectedProduct;
                        //DataGridViewComboBoxCell cb = (DataGridViewComboBoxCell)row.Cells["ColName"];
                        //selectedProduct = products.Where(p => p.Id.ToString() == Convert.ToString(cb.Value)).FirstOrDefault();
                        //var stockoutProduct = context.Products.Where(p => p.Id == selectedProduct.Id).FirstOrDefault();
                        //stockoutProduct.Quantity = stockoutProduct.Quantity - quantity;
                        context.SaveChanges();
                    }
                }
                Form formInvoice = new Invoice(invoiceNumber);
                formInvoice.ShowDialog();
                this.Close();
            }
        }