Example #1
0
        private void RefreshItems(object sender, EventArgs e)
        {
            var biz = new ProductLDBiz();

            dataGridView.DataSource = biz.LoadItems();
            dataGridView.Refresh();
        }
Example #2
0
        public ProductLDForm(int id, User user)
        {
            InitializeComponent();

            InitForm(user);

            textName.Focus();
            itemId = id;

            var biz = new ProductLDBiz();
            var item = biz.LoadItem(id);

            textName.Text = item.Name;
            if (item.ProductTypeId.HasValue)
            {
                drlType.SelectedValue = item.ProductTypeId.Value;
            }
            numberPrice.Text = item.Price.ToString();

            created = item.Created;
            createdBy = item.CreatedByUserId;
            modified = item.Modified;
            modifiedBy = item.ModifiedByUserId;

            this.Text = "Sửa sản phẩm";
        }
Example #3
0
        public ProductLDForm(int id, User user)
        {
            InitializeComponent();

            InitForm(user);

            textName.Focus();
            itemId = id;

            var biz  = new ProductLDBiz();
            var item = biz.LoadItem(id);

            textName.Text = item.Name;
            if (item.ProductTypeId.HasValue)
            {
                drlType.SelectedValue = item.ProductTypeId.Value;
            }
            numberPrice.Text = item.Price.ToString();

            created    = item.Created;
            createdBy  = item.CreatedByUserId;
            modified   = item.Modified;
            modifiedBy = item.ModifiedByUserId;

            this.Text = "Sửa sản phẩm";
        }
Example #4
0
        private void RefreshItems()
        {
            var biz = new ProductLDBiz();

            dataGridView.DataSource = biz.LoadItems();
            dataGridView.Refresh();
        }
Example #5
0
        public ProductLDView(User user)
        {
            InitializeComponent();

            dataGridView.AutoGenerateColumns = false;

            var biz = new ProductLDBiz();
            dataGridView.DataSource = biz.LoadItems();
            dataGridView.Refresh();

            currentUser = user;

            buttonSelectItems.Text = "Chọn";
        }
Example #6
0
        public ProductLDView(User user)
        {
            InitializeComponent();

            dataGridView.AutoGenerateColumns = false;

            var biz = new ProductLDBiz();

            dataGridView.DataSource = biz.LoadItems();
            dataGridView.Refresh();

            currentUser = user;

            buttonSelectItems.Text = "Chọn";
        }
Example #7
0
        private void DeleteItem(object sender, EventArgs e)
        {
            var items = new List<ProductLD>();

            foreach (DataGridViewRow row in dataGridView.Rows)
            {
                if (row.Cells[0].Value != null && row.Cells[0].Value == "1")
                {
                    items.Add(row.DataBoundItem as ProductLD);
                }
            }

            var biz = new ProductLDBiz();
            biz.RemoveItem(items);

            RefreshItems(sender, e);
        }
Example #8
0
        private void Search(object sender, EventArgs e)
        {
            int?typeId = null;

            var biz  = new ProductLDBiz();
            var data = biz.SearchProduct(drlProductType.Text, textName.Text, textCode.Text);

            foreach (var p in ListSelectedProduct)
            {
                var item = data.Find(i => i.Code == p.Code);
                if (item != null)
                {
                    data.Remove(item);
                }
            }

            dataGridView.DataSource = data;
        }
Example #9
0
        private void DeleteItem(object sender, EventArgs e)
        {
            var items = new List <ProductLD>();

            foreach (DataGridViewRow row in dataGridView.Rows)
            {
                if (row.Cells[0].Value != null && row.Cells[0].Value == "1")
                {
                    items.Add(row.DataBoundItem as ProductLD);
                }
            }

            var biz = new ProductLDBiz();

            biz.RemoveItem(items);

            RefreshItems(sender, e);
        }
Example #10
0
        private void Search(object sender, EventArgs e)
        {
            int? typeId = null;

            var biz = new ProductLDBiz();
            var data = biz.SearchProduct(drlProductType.Text, textName.Text, textCode.Text);

            foreach(var p in ListSelectedProduct)
            {
                var item = data.Find(i => i.Code == p.Code);
                if(item != null)
                {
                    data.Remove(item);
                }
            }

            dataGridView.DataSource = data;
        }
Example #11
0
        private void SaveItem(object sender, EventArgs e)
        {
            if (CustomValidation())
            {
                var item = new ProductLD();
                item.Name          = textName.Text;
                item.ProductTypeId = Convert.ToInt32(drlType.SelectedValue);
                item.Price         = Convert.ToDecimal(numberPrice.Text);

                if (itemId > 0)
                {
                    item.Id              = itemId;
                    item.Created         = created;
                    item.CreatedByUserId = createdBy;

                    item.Modified         = DateTime.Now;
                    item.ModifiedByUserId = currentUser;

                    var biz = new ProductLDBiz();
                    biz.UpdateItem(item);
                }
                else
                {
                    item.Created         = DateTime.Now;
                    item.CreatedByUserId = currentUser;

                    item.Modified         = DateTime.Now;
                    item.ModifiedByUserId = currentUser;

                    var biz = new ProductLDBiz();
                    biz.SaveItem(item);
                }

                this.Close();
            }
            else
            {
                this.DialogResult = System.Windows.Forms.DialogResult.None;
            }
        }
Example #12
0
        private void SaveItem(object sender, EventArgs e)
        {
            if (CustomValidation())
            {
                var item = new ProductLD();
                item.Name = textName.Text;
                item.ProductTypeId = Convert.ToInt32(drlType.SelectedValue);
                item.Price = Convert.ToDecimal(numberPrice.Text);

                if (itemId > 0)
                {
                    item.Id = itemId;
                    item.Created = created;
                    item.CreatedByUserId = createdBy;

                    item.Modified = DateTime.Now;
                    item.ModifiedByUserId = currentUser;

                    var biz = new ProductLDBiz();
                    biz.UpdateItem(item);
                }
                else
                {
                    item.Created = DateTime.Now;
                    item.CreatedByUserId = currentUser;

                    item.Modified = DateTime.Now;
                    item.ModifiedByUserId = currentUser;

                    var biz = new ProductLDBiz();
                    biz.SaveItem(item);
                }

                this.Close();
            }
            else
            {
                this.DialogResult = System.Windows.Forms.DialogResult.None;
            }
        }
Example #13
0
        private void ImportDataSet(string fileName)
        {
            var biz = new ProductLDBiz();

            using (var document = SpreadsheetDocument.Open(fileName, false))
            {
                var wbPart = document.WorkbookPart;
                var theSheet = wbPart.Workbook.Descendants<Sheet>().FirstOrDefault();

                var wsPart = (WorksheetPart)(wbPart.GetPartById(theSheet.Id));
                var count = wsPart.Worksheet.Descendants<Row>().Count();
                for (var i = 2; i <= count; i++)
                {
                    var product = new ProductLD
                    {
                        Code = IOReader.GetCellValue(document, theSheet, "A" + i),
                        Name = IOReader.GetCellValue(document, theSheet, "B" + i),
                    };

                    decimal number = 0;
                    var price = IOReader.GetCellValue(document, theSheet, "C" + i);
                    if (!string.IsNullOrEmpty(price) && decimal.TryParse(price, out number))
                    {
                        product.Price = number;
                    }

                    int number1 = 0;
                    var productTypeId = IOReader.GetCellValue(document, theSheet, "D" + i);
                    if (!string.IsNullOrEmpty(productTypeId) && int.TryParse(productTypeId, out number1))
                    {
                        product.ProductTypeId = number1;
                    }

                    var item = biz.LoadItems().FirstOrDefault(p => p.Code == product.Code);

                    if (string.IsNullOrEmpty(product.Code))
                    {
                        break;
                    }

                    if (item != null)
                    {
                        product.Id = item.Id;
                        product.Code = item.Code;
                        product.Name = item.Name;
                        product.ProductTypeId = item.ProductTypeId;
                        product.Created = item.Created;
                        product.CreatedByUserId = item.CreatedByUserId;
                        product.Modified = item.Modified;
                        product.ModifiedByUserId = item.ModifiedByUserId;

                        try
                        {
                            biz.UpdateItem(product);
                        }
                        catch (Exception ex)
                        {
                            logger.LogInfoMessage("Import Update Product");
                            string log = string.Format("ID: {0}, Code: {1}, Name: {2}, TypeId: {3}", item.Id, item.Code, item.Name, item.ProductTypeId);
                            logger.LogInfoMessage(log);
                            logger.LogException(ex);
                        }
                    }
                    else
                    {
                        product.Id = 0;
                        product.Created = DateTime.Now;
                        product.CreatedByUserId = currentUser.Id;
                        product.Modified = DateTime.Now;
                        product.ModifiedByUserId = currentUser.Id;

                        try
                        {
                            biz.SaveItem(product);
                        }
                        catch(Exception ex)
                        {
                            logger.LogInfoMessage("Import New Product");
                            string log = string.Format("ID: {0}, Code: {1}, Name: {2}, TypeId: {3}", 0, product.Code, product.Name, product.ProductTypeId);
                            logger.LogInfoMessage(log);
                            logger.LogException(ex);
                        }
                    }
                }

                MessageBox.Show("Cập nhật thành công.");
            }
        }
Example #14
0
 private void RefreshItems()
 {
     var biz = new ProductLDBiz();
     dataGridView.DataSource = biz.LoadItems();
     dataGridView.Refresh();
 }
Example #15
0
 private void RefreshItems(object sender, EventArgs e)
 {
     var biz = new ProductLDBiz();
     dataGridView.DataSource = biz.LoadItems();
     dataGridView.Refresh();
 }
Example #16
0
        private void ImportDataSet(string fileName)
        {
            var biz = new ProductLDBiz();

            using (var document = SpreadsheetDocument.Open(fileName, false))
            {
                var wbPart   = document.WorkbookPart;
                var theSheet = wbPart.Workbook.Descendants <Sheet>().FirstOrDefault();

                var wsPart = (WorksheetPart)(wbPart.GetPartById(theSheet.Id));
                var count  = wsPart.Worksheet.Descendants <Row>().Count();
                for (var i = 2; i <= count; i++)
                {
                    var product = new ProductLD
                    {
                        Code = IOReader.GetCellValue(document, theSheet, "A" + i),
                        Name = IOReader.GetCellValue(document, theSheet, "B" + i),
                    };

                    decimal number = 0;
                    var     price  = IOReader.GetCellValue(document, theSheet, "C" + i);
                    if (!string.IsNullOrEmpty(price) && decimal.TryParse(price, out number))
                    {
                        product.Price = number;
                    }

                    int number1       = 0;
                    var productTypeId = IOReader.GetCellValue(document, theSheet, "D" + i);
                    if (!string.IsNullOrEmpty(productTypeId) && int.TryParse(productTypeId, out number1))
                    {
                        product.ProductTypeId = number1;
                    }

                    var item = biz.LoadItems().FirstOrDefault(p => p.Code == product.Code);

                    if (string.IsNullOrEmpty(product.Code))
                    {
                        break;
                    }

                    if (item != null)
                    {
                        product.Id               = item.Id;
                        product.Code             = item.Code;
                        product.Name             = item.Name;
                        product.ProductTypeId    = item.ProductTypeId;
                        product.Created          = item.Created;
                        product.CreatedByUserId  = item.CreatedByUserId;
                        product.Modified         = item.Modified;
                        product.ModifiedByUserId = item.ModifiedByUserId;

                        try
                        {
                            biz.UpdateItem(product);
                        }
                        catch (Exception ex)
                        {
                            logger.LogInfoMessage("Import Update Product");
                            string log = string.Format("ID: {0}, Code: {1}, Name: {2}, TypeId: {3}", item.Id, item.Code, item.Name, item.ProductTypeId);
                            logger.LogInfoMessage(log);
                            logger.LogException(ex);
                        }
                    }
                    else
                    {
                        product.Id               = 0;
                        product.Created          = DateTime.Now;
                        product.CreatedByUserId  = currentUser.Id;
                        product.Modified         = DateTime.Now;
                        product.ModifiedByUserId = currentUser.Id;

                        try
                        {
                            biz.SaveItem(product);
                        }
                        catch (Exception ex)
                        {
                            logger.LogInfoMessage("Import New Product");
                            string log = string.Format("ID: {0}, Code: {1}, Name: {2}, TypeId: {3}", 0, product.Code, product.Name, product.ProductTypeId);
                            logger.LogInfoMessage(log);
                            logger.LogException(ex);
                        }
                    }
                }

                MessageBox.Show("Cập nhật thành công.");
            }
        }