/// <summary>
 /// Thêm mới hoặc Cập nhật thông tin Nhóm Hàng
 /// </summary>
 /// <param name="stockName"></param>
 private Data.Stock InsertOrUpdateStock(string stockName)
 {
     if (!string.IsNullOrEmpty(stockName))
     {
         Data.Stock stock;
         if (!_stockService.CheckStockNameExit(stockName))
         {
             stock = _stockService.GetStockByName(stockName);
         }
         else
         {
             stock = new Data.Stock()
             {
                 StockID     = _stockService.NextId(),
                 StockName   = stockName,
                 CreatedBy   = _userName,
                 CreatedDate = DateTime.Now,
                 Description = stockName,
                 IsActive    = true,
             };
             try
             {
                 _stockService.Add(stock);
             }
             catch (Exception ex)
             {
                 XtraMessageBox.Show(string.Format("Lỗi thêm Kho Hàng \n{0}", ex.Message));
             }
         }
         return(stock);
     }
     return(null);
 }
Example #2
0
        /// <summary>
        /// Tạo ID Kế tiếp
        /// </summary>
        /// <returns></returns>
        public string NextId()
        {
            var stocks = GetStocks();

            if (stocks != null)
            {
                Data.Stock stock = stocks.LastOrDefault();
                if (stock != null)
                {
                    string lastId = stock.StockID.Remove(0, 3);
                    string orderImportId;
                    if (!string.IsNullOrEmpty(lastId))
                    {
                        int nextId = int.Parse(lastId) + 1;
                        orderImportId = string.Format("K{0}", nextId.ToString(CultureInfo.InvariantCulture).PadLeft(5, '0'));
                    }
                    else
                    {
                        orderImportId = string.Format("K0000{0}", 1);
                    }
                    return(orderImportId);
                }
                return(string.Format("K0000{0}", 1));
            }
            return(string.Format("K0000{0}", 1));
        }
Example #3
0
        /// <summary>
        /// Delete
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bbiDeleteStock_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DialogResult result = XtraMessageBox.Show("Bạn có chắc muốn xóa không?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (result == DialogResult.Yes)
            {
                foreach (var rowHandle in gridView1.GetSelectedRows())
                {
                    var stockId = gridView1.GetRowCellValue(rowHandle, "StockID");
                    if (stockId != null)
                    {
                        Data.Stock stock = _stockService.GetStockById(stockId.ToString());
                        if (stock != null)
                        {
                            try
                            {
                                _stockService.Delete(stockId.ToString());
                            }
                            catch (Exception ex)
                            {
                                MessageBoxHelper.ShowMessageBoxError(ex.Message);
                            }
                        }
                    }
                }
                LoadData();
            }
            else
            {
                EnableButtonUpdateAndDelete(false);
            }
        }
Example #4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtStockID.Text))
            {
                Ultils.TextControlNotNull(txtStockID, "Mã Kho Hàng");
            }
            else if (string.IsNullOrEmpty(txtStockName.Text))
            {
                Ultils.TextControlNotNull(txtStockName, "Tên Kho Hàng");
            }
            else
            {
                if (string.IsNullOrEmpty(_stockId))
                {
                    _stock = new Data.Stock()
                    {
                        StockID     = _stockService.NextId(),
                        StockName   = txtStockName.Text,
                        Active      = checkActive.Checked,
                        CreatedDate = DateTime.Now,
                        CreatedBy   = Program.CurrentUser.Username,
                    };
                    try
                    {
                        _stockService.Add(_stock);
                        _logService.InsertLog(Program.CurrentUser.Username, "Thêm", this.Text);
                        MessageBoxHelper.ShowMessageBoxSuccess("Thêm thành công!");
                        ResetControls();
                    }
                    catch (Exception ex)
                    {
                        MessageBoxHelper.ShowMessageBoxError(ex.Message);
                    }
                }
                else
                {
                    _stock = _stockService.GetStockById(_stockId);
                    if (_stockId != null)
                    {
                        _stock.StockName   = txtStockName.Text;
                        _stock.Description = txtDescription.Text;
                        _stock.Active      = checkActive.Checked;
                        _stock.ModifyDate  = DateTime.Now;
                        _stock.ModifyBy    = Program.CurrentUser.Username;

                        try
                        {
                            _stockService.Update(_stock);
                            MessageBoxHelper.ShowMessageBoxSuccess("Sửa thành công!");
                            ResetControls();
                        }
                        catch (Exception ex)
                        {
                            MessageBoxHelper.ShowMessageBoxError(ex.Message);
                        }
                    }
                }
            }
        }
Example #5
0
 /// <summary>
 /// Kiểm tra sự tồn tại của ID
 /// </summary>
 /// <param name="stockId"></param>
 public bool CheckStockIdExit(string stockId)
 {
     Data.Stock stock = GetStockById(stockId);
     if (stock != null)
     {
         return(false);
     }
     return(true);
 }
Example #6
0
 public bool CheckStockNameExit(string stockName)
 {
     Data.Stock stock = GetStockByName(stockName);
     if (stock != null)
     {
         return(false);
     }
     return(true);
 }
Example #7
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(txtStockID.Text))
     {
         txtStockID.Properties.Appearance.BorderColor = System.Drawing.Color.Red;
         XtraMessageBox.Show("Mã Kho Hàng không được bỏ trống!", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         txtStockID.Focus();
     }
     else if (string.IsNullOrEmpty(txtStockName.Text))
     {
         txtStockName.Properties.Appearance.BorderColor = System.Drawing.Color.Red;
         XtraMessageBox.Show("Tên Kho Hàng không được bỏ trống!", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         txtStockName.Focus();
     }
     else if (!_stockService.CheckStockNameExit(txtStockName.Text))
     {
         txtStockName.Properties.Appearance.BorderColor = System.Drawing.Color.Red;
         XtraMessageBox.Show("Tên Kho Hàng này đã tồn tại rồi!", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         txtStockName.Focus();
     }
     else
     {
         var stock = new Data.Stock()
         {
             StockID     = txtStockID.Text,
             StockName   = txtStockName.Text,
             Contact     = txtContact.Text,
             Adress      = txtAddress.Text,
             Email       = txtEmail.Text,
             Telephone   = txtPhone.Text,
             Mobile      = txtMobile.Text,
             Fax         = txtFax.Text,
             Manager     = txtManager.Text,
             Description = txtDescription.Text,
             IsActive    = checkActive.Checked,
             CreatedDate = DateTime.Now,
             CreatedBy   = null,
         };
         try
         {
             _stockService.Add(stock);
             InsertSysLog(txtStockName.Text);
             if (XtraMessageBox.Show("Thêm thành công.\n Bạn có muốn thêm mới Kho Hàng nữa không?", "HỎI", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
             {
                 ResetControls();
             }
             else
             {
                 DialogResult = DialogResult.No;
             }
         }
         catch (Exception ex)
         {
             XtraMessageBox.Show(string.Format("Lỗi {0}", ex.Message), "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Example #8
0
        private void LoadData()
        {
            if (!string.IsNullOrEmpty(_stockId))
            {
                txtStockID.Enabled = false;

                _stock              = _stockService.GetStockById(_stockId);
                txtStockID.Text     = _stock.StockID;
                txtStockName.Text   = _stock.StockName;
                txtDescription.Text = _stock.Description;
                checkActive.Checked = _stock.Active;
            }
        }
Example #9
0
        /// <summary>
        /// Trả về tên Kho theo ID
        /// </summary>
        /// <param name="stockId"></param>
        /// <returns></returns>
        public string GetStockNameById(string stockId)
        {
            if (!string.IsNullOrEmpty(stockId))
            {
                Data.Stock stock = GetStockById(stockId);
                if (stock != null)
                {
                    string stockName = stock.StockName;
                    return(stockName);
                }
            }

            return("Khác");
        }
Example #10
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(txtStockID.Text))
     {
         XtraMessageBox.Show("Mã Kho Hàng không được bỏ trống!", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         txtStockID.Focus();
     }
     else if (string.IsNullOrEmpty(txtStockName.Text))
     {
         XtraMessageBox.Show("Tên Kho Hàng không được bỏ trống!", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         txtStockName.Focus();
     }
     else
     {
         Data.Stock stock = _stockService.GetStockById(_stockId);
         if (stock != null)
         {
             stock.StockID     = txtStockID.Text;
             stock.StockName   = txtStockName.Text;
             stock.Contact     = txtContact.Text;
             stock.Adress      = txtAddress.Text;
             stock.Email       = txtEmail.Text;
             stock.Telephone   = txtPhone.Text;
             stock.Mobile      = txtMobile.Text;
             stock.Fax         = txtFax.Text;
             stock.Manager     = txtManager.Text;
             stock.Description = txtDescription.Text;
             stock.IsActive    = checkActive.Checked;
             stock.ModifyDate  = DateTime.Now;
             stock.UpdateBy    = null;
         }
         try
         {
             _stockService.Update(stock);
             InsertSysLog(txtStockName.Text);
             XtraMessageBox.Show("Sửa thành công", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Information);
             btnClose_Click(sender, e);
         }
         catch (Exception ex)
         {
             XtraMessageBox.Show(string.Format("Lỗi {0}", ex.Message), "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Example #11
0
 /// <summary>
 /// Trả về thông tin Kho Hàng theo ID
 /// </summary>
 /// <param name="stockId"></param>
 private void GetStockById(string stockId)
 {
     Data.Stock stock = _stockService.GetStockById(stockId);
     if (stock != null)
     {
         txtStockID.Text     = stock.StockID;
         txtStockName.Text   = stock.StockName;
         txtPhone.Text       = stock.Telephone;
         txtMobile.Text      = stock.Mobile;
         txtAddress.Text     = stock.Adress;
         txtEmail.Text       = stock.Email;
         txtFax.Text         = stock.Fax;
         txtManager.Text     = stock.Manager;
         txtDescription.Text = stock.Description;
         txtContact.Text     = stock.Contact;
     }
     else
     {
         XtraMessageBox.Show("Vui lòng chọn Kho Hàng cần sửa", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Example #12
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtStockID.Text))
            {
                Ultils.TextControlNotNull(txtStockID, "Mã Kho Hàng");
            }
            else if (string.IsNullOrEmpty(txtStockName.Text))
            {
                Ultils.TextControlNotNull(txtStockName, "Tên Kho Hàng");
            }
            else
            {
                if (string.IsNullOrEmpty(_stockId))
                {
                    _stock = new Data.Stock()
                    {
                        StockID = _stockService.NextId(),
                        StockName = txtStockName.Text,
                        Active = checkActive.Checked,
                        CreatedDate = DateTime.Now,
                        CreatedBy = Program.CurrentUser.Username,
                    };
                    try
                    {
                        _stockService.Add(_stock);
                        _logService.InsertLog(Program.CurrentUser.Username, "Thêm", this.Text);
                        MessageBoxHelper.ShowMessageBoxSuccess("Thêm thành công!");
                        ResetControls();
                    }
                    catch (Exception ex)
                    {
                        MessageBoxHelper.ShowMessageBoxError(ex.Message);
                    }

                }
                else
                {
                    _stock = _stockService.GetStockById(_stockId);
                    if (_stockId != null)
                    {
                        _stock.StockName = txtStockName.Text;
                        _stock.Description = txtDescription.Text;
                        _stock.Active = checkActive.Checked;
                        _stock.ModifyDate = DateTime.Now;
                        _stock.ModifyBy = Program.CurrentUser.Username;

                        try
                        {
                            _stockService.Update(_stock);
                            MessageBoxHelper.ShowMessageBoxSuccess("Sửa thành công!");
                            ResetControls();
                        }
                        catch (Exception ex)
                        {
                            MessageBoxHelper.ShowMessageBoxError(ex.Message);
                        }
                    }

                }
            }
        }
Example #13
0
 private void LoadData()
 {
     if (!string.IsNullOrEmpty(_stockId))
     {
         txtStockID.Enabled = false;
         
         _stock = _stockService.GetStockById(_stockId);
         txtStockID.Text = _stock.StockID;
         txtStockName.Text = _stock.StockName;
         txtDescription.Text = _stock.Description;
         checkActive.Checked = _stock.Active;
     }  
 }
 /// <summary>
 /// Thêm mới hoặc Cập nhật thông tin Nhóm Hàng
 /// </summary>
 /// <param name="stockName"></param>
 private Data.Stock InsertOrUpdateStock(string stockName)
 {
     if (!string.IsNullOrEmpty(stockName))
     {
         Data.Stock stock;
         if (!_stockService.CheckStockNameExit(stockName))
         {
             stock = _stockService.GetStockByName(stockName);
         }
         else
         {
             stock = new Data.Stock()
             {
                 StockID = _stockService.NextId(),
                 StockName = stockName,
                 CreatedBy = _userName,
                 CreatedDate = DateTime.Now,
                 Description = stockName,
                 IsActive = true,
             };
             try
             {
                 _stockService.Add(stock);
             }
             catch (Exception ex)
             {
                 XtraMessageBox.Show(string.Format("Lỗi thêm Kho Hàng \n{0}", ex.Message));
             }
         }
         return stock;
     }
     return null;
 }
Example #15
0
        private void barButtonItemDelete_ItemClick(object sender, ItemClickEventArgs e)
        {
            DialogResult result = XtraMessageBox.Show("Bạn có chắc muốn xóa không?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (result == DialogResult.Yes)
            {
                foreach (var rowHandle in gridView1.GetSelectedRows())
                {
                    var stockId = gridView1.GetRowCellValue(rowHandle, "StockID");
                    if (stockId != null)
                    {
                        Data.Stock stock = _stockSeries.GetStockById(stockId.ToString());
                        if (stock != null)
                        {
                            try
                            {
                                _stockSeries.Delete(stockId.ToString());
                            }
                            catch (Exception ex)
                            {
                                XtraMessageBox.Show(string.Format("Lỗi! \n {0}", ex.Message), "THÔNG BÁO",
                                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                }
                LoadStocks();
            }
            else
            {
                EnableButtonUpdateAndDelete(false);
            }

            //if (!string.IsNullOrEmpty(_stockId))
            //{
            //    Data.Stock stock = _stockSeries.GetStockById(_stockId);
            //    if (stock != null)
            //    {
            //        DialogResult result = XtraMessageBox.Show("Bạn có chắc muốn xóa thông tin Kho Hàng : " + stock.StockName + " này không?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            //        if (result == DialogResult.Yes)
            //        {
            //            try
            //            {
            //                _stockSeries.Delete(_stockId);
            //                LoadStocks();

            //                // _stockId == null
            //                EnableButtonUpdateAndDelete(false);
            //            }
            //            catch (Exception ex)
            //            {
            //                XtraMessageBox.Show(string.Format("Lỗi! \n {0}", ex.Message), "THÔNG BÁO",
            //                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            //            }

            //        }
            //    }

            //}
            //else
            //    XtraMessageBox.Show("Vui lòng chọn một Kho Hàng cần sửa!", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
Example #16
0
 /// <summary>
 /// Cập nhật thông tin
 /// </summary>
 /// <param name="stock"></param>
 public void Update(Data.Stock stock)
 {
     _context.Stocks.Attach(stock);
     _context.Entry(stock).State = EntityState.Modified;
     SaveChanges();
 }
Example #17
0
 /// <summary>
 /// Thêm mới
 /// </summary>
 /// <param name="stock"></param>
 /// <returns></returns>
 public void Add(Data.Stock stock)
 {
     _context.Stocks.Add(stock);
     SaveChanges();
 }
Example #18
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtStockID.Text))
            {
                txtStockID.Properties.Appearance.BorderColor = System.Drawing.Color.Red;
                XtraMessageBox.Show("Mã Kho Hàng không được bỏ trống!", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtStockID.Focus();
            }
            else if (string.IsNullOrEmpty(txtStockName.Text))
            {
                txtStockName.Properties.Appearance.BorderColor = System.Drawing.Color.Red;
                XtraMessageBox.Show("Tên Kho Hàng không được bỏ trống!", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtStockName.Focus();
            }
            else if (!_stockService.CheckStockNameExit(txtStockName.Text))
            {
                txtStockName.Properties.Appearance.BorderColor = System.Drawing.Color.Red;
                XtraMessageBox.Show("Tên Kho Hàng này đã tồn tại rồi!", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtStockName.Focus();
            }
            else
            {
                var stock = new Data.Stock()
                {
                    StockID = txtStockID.Text,
                    StockName = txtStockName.Text,
                    Contact = txtContact.Text,
                    Adress = txtAddress.Text,
                    Email = txtEmail.Text,
                    Telephone = txtPhone.Text,
                    Mobile = txtMobile.Text,
                    Fax = txtFax.Text,
                    Manager = txtManager.Text,
                    Description = txtDescription.Text,
                    IsActive = checkActive.Checked,
                    CreatedDate = DateTime.Now,
                    CreatedBy = null,

                };
                try
                {
                    _stockService.Add(stock);
                    InsertSysLog(txtStockName.Text);
                    if (XtraMessageBox.Show("Thêm thành công.\n Bạn có muốn thêm mới Kho Hàng nữa không?", "HỎI", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        ResetControls();
                    }
                    else
                    {
                        DialogResult = DialogResult.No;
                    }
                }
                catch (Exception ex)
                {
                    XtraMessageBox.Show(string.Format("Lỗi {0}", ex.Message), "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error);

                }
            }
        }
Example #19
0
 /// <summary>
 /// Xóa theo ID
 /// </summary>
 /// <param name="unitId"></param>
 public void Delete(string unitId)
 {
     Data.Stock stock = GetStockById(unitId);
     _context.Stocks.Remove(stock);
     SaveChanges();
 }