示例#1
0
 public void refreshProducts()
 {
     GridProducts.Rows.Clear();
     using (var context = new ManagementDbEntities())
     {
         var products = context.Products.ToList();
         if (products.Count > 0)
         {
             btnEdit.Enabled   = true;
             btnDelete.Enabled = true;
             foreach (Products product in products)
             {
                 var index = GridProducts.Rows.Add();
                 GridProducts.Rows[index].Cells["colName"].Value     = product.Name;
                 GridProducts.Rows[index].Cells["colID"].Value       = product.Id;
                 GridProducts.Rows[index].Cells["colSpec"].Value     = product.Spec;
                 GridProducts.Rows[index].Cells["colUnit"].Value     = product.Unit;
                 GridProducts.Rows[index].Cells["colNotes"].Value    = product.Notes;
                 GridProducts.Rows[index].Cells["colPrice"].Value    = string.Format("{0:0.00}", product.Price);
                 GridProducts.Rows[index].Cells["colQuantity"].Value = string.Format("{0:0}", product.Quantity);
             }
             GridProducts_CellClick(GridProducts, new DataGridViewCellEventArgs(0, 0));
         }
         else
         {
             btnEdit.Enabled   = false;
             btnDelete.Enabled = false;
         }
     }
 }
示例#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 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();
         }
     }
 }
示例#4
0
 public void refreshProducts()
 {
     GridStockInDetails.Rows.Clear();
     using (var context = new ManagementDbEntities())
     {
         var stockInRecords = context.StockInRecords.ToList();
         if (dtStart.Checked)
         {
             stockInRecords = stockInRecords.Where(r => r.Date >= dtStart.Value).ToList();
         }
         if (dtEnd.Checked)
         {
             stockInRecords = stockInRecords.Where(r => r.Date <= dtEnd.Value).ToList();
         }
         foreach (StockInRecords stockInRecord in stockInRecords)
         {
             var index = GridStockInDetails.Rows.Add();
             GridStockInDetails.Rows[index].Cells["colName"].Value     = stockInRecord.ProductName;
             GridStockInDetails.Rows[index].Cells["colID"].Value       = stockInRecord.Id;
             GridStockInDetails.Rows[index].Cells["colSpec"].Value     = stockInRecord.ProductSpec;
             GridStockInDetails.Rows[index].Cells["colUnit"].Value     = stockInRecord.ProductUnit;
             GridStockInDetails.Rows[index].Cells["colNotes"].Value    = stockInRecord.ProductNotes;
             GridStockInDetails.Rows[index].Cells["colDate"].Value     = stockInRecord.Date.GetValueOrDefault().ToString("yyyy/MM/dd");
             GridStockInDetails.Rows[index].Cells["colQuantity"].Value = string.Format("{0:0}", stockInRecord.Quantity);
         }
     }
 }
示例#5
0
        public StockOutProduct()
        {
            InitializeComponent();
            CenterToScreen();
            using (var context = new ManagementDbEntities())
            {
                comboCustomerName.Items.Clear();
                customers = context.Customers.ToList();
                products  = context.Products.ToList();
                comboCustomerName.DisplayMember = "Text";
                comboCustomerName.ValueMember   = "Value";
                foreach (var customer in customers)
                {
                    ComboboxItem item = new ComboboxItem {
                        Text = customer.Name, Value = customer.Id
                    };
                    comboCustomerName.Items.Add(item);
                }

                DataGridViewComboBoxColumn theColumn = (DataGridViewComboBoxColumn)this.GridProducts.Columns["ColName"];
                foreach (var product in products)
                {
                    ComboboxItem item = new ComboboxItem {
                        Text = product.Name, Value = product.Id
                    };
                    theColumn.Items.Add(item);
                }
                theColumn.ValueMember   = "Value";
                theColumn.DisplayMember = "Text";
                this.GridProducts.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(GridProducts_EditingControlShowing);
            }
        }
示例#6
0
 public void refreshCustomers()
 {
     GridCustomers.Rows.Clear();
     using (var context = new ManagementDbEntities())
     {
         var customers = context.Customers.ToList();
         if (customers.Count > 0)
         {
             btnEdit.Enabled   = true;
             btnDelete.Enabled = true;
             foreach (Customers customer in customers)
             {
                 var index = GridCustomers.Rows.Add();
                 GridCustomers.Rows[index].Cells["colName"].Value          = customer.Name;
                 GridCustomers.Rows[index].Cells["colID"].Value            = customer.Id;
                 GridCustomers.Rows[index].Cells["colContactPerson"].Value = customer.ContactPerson;
                 GridCustomers.Rows[index].Cells["colContact"].Value       = customer.Contact;
                 GridCustomers.Rows[index].Cells["colAddress"].Value       = customer.Address;
             }
             GridCustomers_CellClick(GridCustomers, new DataGridViewCellEventArgs(0, 0));
         }
         else
         {
             btnEdit.Enabled       = false;
             btnDelete.Enabled     = false;
             txtName.Text          = "";
             txtContactPerson.Text = "";
             txtContact.Text       = "";
             txtAddress.Text       = "";
         }
     }
 }
示例#7
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;
             }
         }
     }
 }
示例#8
0
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            bool   logined  = false;
            string name     = textBoxUserName.Text;
            string password = textBoxPassword.Text;

            using (var context = new ManagementDbEntities())
            {
                var user = context.Users.Where(c => c.Name == name).FirstOrDefault();
                if (user != null)
                {
                    var hashedPassword = con.HashPassword(password);
                    if (user.Password.SequenceEqual(hashedPassword))
                    {
                        logined = true;
                    }
                }
            }
            if (logined)
            {
                Form frmMain = new Main(this);
                this.Hide();
                frmMain.Closed += (s, args) => this.Close();
                frmMain.Show();
            }
            else
            {
                labelWarning.Visible = true;
            }
        }
示例#9
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();
     }
 }
示例#10
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();
     }
 }
示例#11
0
 public UserInfo()
 {
     InitializeComponent();
     CenterToScreen();
     using (var context = new ManagementDbEntities())
     {
         var user = context.Users.FirstOrDefault();
         txtName.Text           = user.Name;
         txtCompanyName.Text    = user.CompanyName;
         txtCompanyAddress.Text = user.CompanyAddress;
         txtCompanyContact.Text = user.CompanyContact;
         txtComapnyFax.Text     = user.CompanyFax;
         txtInvoiceMaker.Text   = user.InvoiceCreator;
     }
 }
示例#12
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);
        }
示例#13
0
        public Invoice(string invoiceNumber)
        {
            InitializeComponent();
            CenterToScreen();
            var adapter = new DataSet1TableAdapters.DataTable1TableAdapter();

            adapter.Connection.ConnectionString = ConfigurationManager.ConnectionStrings["SyncDB"].ToString();
            var table = new DataSet1.DataTable1DataTable();

            adapter.FillByInvoiceNumber(table, invoiceNumber);
            var newDataSource = new ReportDataSource("DataSet1", (DataTable)table);

            this.reportViewer1.LocalReport.DataSources.Clear();
            this.reportViewer1.LocalReport.DataSources.Add(newDataSource);
            ReportParameter[] parameters = new ReportParameter[13];
            using (var context = new ManagementDbEntities())
            {
                double totalAmount;
                totalAmount = 0;
                var StockOutRecords = context.StockOutRecords.Where(r => r.InvoiceNumber == invoiceNumber).ToList();
                foreach (var record in StockOutRecords)
                {
                    totalAmount += record.ProductTotalAmount.GetValueOrDefault();
                }
                var firstRecord = StockOutRecords.FirstOrDefault();
                var currentUser = context.Users.FirstOrDefault();
                parameters[0]  = new ReportParameter("CustomerName", firstRecord.CustomerName);
                parameters[1]  = new ReportParameter("CustomerContactPerson", firstRecord.CustomerContactPerson);
                parameters[2]  = new ReportParameter("CustomerContactNumber", firstRecord.CustomerContact);
                parameters[3]  = new ReportParameter("CustomerAddress", firstRecord.CustomerAddress);
                parameters[4]  = new ReportParameter("InvoiceDate", firstRecord.Date.GetValueOrDefault().ToString("yyyy-MM-dd"));
                parameters[5]  = new ReportParameter("Amount", totalAmount.ToString());
                parameters[6]  = new ReportParameter("InvoiceNumber", firstRecord.InvoiceNumber);
                parameters[7]  = new ReportParameter("CapitalAmount", GetCapitalAmount(totalAmount));
                parameters[8]  = new ReportParameter("CompanyName", currentUser.CompanyName);
                parameters[9]  = new ReportParameter("CompanyAddress", currentUser.CompanyAddress);
                parameters[10] = new ReportParameter("CompanyTel", currentUser.CompanyContact);
                parameters[11] = new ReportParameter("CompanyFax", currentUser.CompanyFax);
                parameters[12] = new ReportParameter("MadeBy", currentUser.InvoiceCreator);
            }
            this.reportViewer1.LocalReport.SetParameters(parameters);
            this.reportViewer1.LocalReport.Refresh();
            this.reportViewer1.RefreshReport();
        }
示例#14
0
 public StockInProduct()
 {
     InitializeComponent();
     CenterToScreen();
     dtPicker.Value = DateTime.Today;
     using (var context = new ManagementDbEntities())
     {
         comboProducts.Items.Clear();
         products = context.Products.ToList();
         comboProducts.DisplayMember = "Text";
         comboProducts.ValueMember   = "Value";
         foreach (var product in products)
         {
             ComboboxItem item = new ComboboxItem {
                 Text = product.Name, Value = product.Id
             };
             comboProducts.Items.Add(item);
         }
     }
 }
示例#15
0
 public AddCustomer(int id = -1)
 {
     InitializeComponent();
     CenterToScreen();
     selectedID = id;
     if (id > 0)
     {
         this.Text = "编辑客户";
         using (var context = new ManagementDbEntities())
         {
             var selectCustomer = context.Customers.Where(c => c.Id == selectedID).FirstOrDefault();
             txtName.Text          = selectCustomer.Name;
             txtContactPerson.Text = selectCustomer.ContactPerson;
             txtContact.Text       = selectCustomer.Contact;
             txtAddress.Text       = selectCustomer.Address;
         }
     }
     else
     {
         this.Text = "新客户";
     }
 }
示例#16
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();
             }
         }
     }
 }
示例#17
0
 public AddProduct(int id = -1)
 {
     InitializeComponent();
     CenterToScreen();
     selectedID = id;
     if (id > 0)
     {
         this.Text = "编辑产品";
         using (var context = new ManagementDbEntities())
         {
             var selectProduct = context.Products.Where(c => c.Id == selectedID).FirstOrDefault();
             txtName.Text  = selectProduct.Name;
             txtSpec.Text  = selectProduct.Spec;
             comUnit.Text  = selectProduct.Unit;
             txtPrice.Text = string.Format("{0:0.00}", selectProduct.Price);
             txtNotes.Text = selectProduct.Notes;
         }
     }
     else
     {
         this.Text = "新产品";
     }
 }
示例#18
0
 public void refreshProducts()
 {
     GridStockInDetails.Rows.Clear();
     using (var context = new ManagementDbEntities())
     {
         var stockOutRecords = context.StockOutRecords.GroupBy(r => r.InvoiceNumber).Select(group => group.FirstOrDefault()).ToList();
         if (dtStart.Checked)
         {
             stockOutRecords = stockOutRecords.Where(r => r.Date >= dtStart.Value).ToList();
         }
         if (dtEnd.Checked)
         {
             stockOutRecords = stockOutRecords.Where(r => r.Date <= dtEnd.Value).ToList();
         }
         foreach (StockOutRecords stockOutRecord in stockOutRecords)
         {
             var index = GridStockInDetails.Rows.Add();
             GridStockInDetails.Rows[index].Cells["colName"].Value          = stockOutRecord.ProductName;
             GridStockInDetails.Rows[index].Cells["colID"].Value            = stockOutRecord.Id;
             GridStockInDetails.Rows[index].Cells["colDate"].Value          = stockOutRecord.Date.GetValueOrDefault().ToString("yyyy/MM/dd");
             GridStockInDetails.Rows[index].Cells["ColInvoiceNumber"].Value = stockOutRecord.InvoiceNumber;
         }
     }
 }
示例#19
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();
            }
        }