/// <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); }
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); } } } } }
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); } } }
public void Execute(IJobExecutionContext context) { IStockCategoryService categoryService = new StockCategoryService(); //导入行情分类的组 IStockSync sync = new StockSync_Tencent(); data.stock_category_group categoryGroup = sync.initCategoryGroup(); categoryService.AddCategoryGroup(categoryGroup); //导入行情分类 IList <data.stockcategory> cateList = sync.GetCategorys(); foreach (data.stockcategory sc in cateList) { if (string.IsNullOrEmpty(sc.code) || string.IsNullOrEmpty(sc.name)) { continue; } if (categoryService.Find(sc.code) == null) { categoryService.Add(sc); this.Log().Info("导入行业:" + sc.name); } } //遍历类别,导入股票 IStockService stockService = new StockService(); IList <data.stockcategory> cateList2 = categoryService.GetCategoryList(categoryGroup.code); foreach (data.stockcategory cate in cateList2) { IList <data.stock> stockLIst = sync.GetStocks(cate); if (stockLIst == null || stockLIst.Count == 0) { continue; } foreach (data.stock s in stockLIst) { s.stock_category_map.Add(new stock_category_map { cate_code = cate.code, stock_code = s.code, stock_name = s.name }); if (stockService.Find(s.code) == null) { stockService.Add(s); } else { stockService.Update(s); } this.Log().Info("导入股票:" + s.name); } } this.Log().Info("导入完成"); }
public void StockServiceAdd_UnitOfWorkAddAndComplete_ReturnsUnitOfWorkAddAndComplete() { var stockDto = new StockDto(); var entity = Mapper.Map <StockDto, Stock>(stockDto); _stockService.Add(stockDto); _uow.Received().Stocks.Add(entity); _uow.Received().Complete(); }