/// <summary> /// 保存 /// </summary> private void btnSave_Click_1(object sender, EventArgs e) { if (CheckInput()) { if (_currentSafetyStockTable == null) { _currentSafetyStockTable = new BaseSafetyStockTable(); } _currentSafetyStockTable.WAREHOUSE_CODE = txtWarehouseCode.Text; _currentSafetyStockTable.PRODUCT_CODE = txtProductCode.Text; _currentSafetyStockTable.UNIT_CODE = txtUnitCode.Text; _currentSafetyStockTable.SAFETY_STOCK = Convert.ToDecimal(txtSafetyStock.Text); _currentSafetyStockTable.MAX_QUANTITY = Convert.ToDecimal(txtMaxQuantity.Text); _currentSafetyStockTable.MIN_PURCHASE_QUANTITY = Convert.ToDecimal(txtMinPurcahseQuantity.Text); _currentSafetyStockTable.LAST_UPDATE_USER = _userInfo.CODE; try { if (bSafetyStock.Exists(txtWarehouseCode.Text.Trim(), txtProductCode.Text.Trim())) { bSafetyStock.Update(_currentSafetyStockTable); } else { _currentSafetyStockTable.CREATE_USER = _userInfo.CODE; bSafetyStock.Add(_currentSafetyStockTable); } } catch (Exception ex) { //log.error MessageBox.Show(""); return; } result = DialogResult.OK; this.Close(); } }
public override string[] doUpdateDB() { BaseSafetyStockTable StockTable = null; BSafetyStock bSafetyStock = new BSafetyStock(); StringBuilder strError = new StringBuilder(); int successData = 0; int failureData = 0; string errorFilePath = ""; string backupFilePath = ""; //数据导入处理 foreach (DataRow dr in _csvDataTable.Rows) { StringBuilder str = new StringBuilder(); //仓库编号 str.Append(CheckWarehouse(CConvert.ToString(GetValue(dr, "WAREHOUSE_CODE")), "仓库编号")); //商品编号 if (CConvert.ToString(GetValue(dr, "PRODUCT_CODE")).Length > 40) { string product = GetValue(dr, "PRODUCT_CODE").ToString().Substring(0, 40); str.Append(CheckProduct(product, "商品编号")); } else { str.Append(CheckProduct(CConvert.ToString(GetValue(dr, "PRODUCT_CODE")), "商品编号")); } //单位 if (!string.IsNullOrEmpty(CConvert.ToString(GetValue(dr, "UNIT_CODE")))) { str.Append(CheckUnit(CConvert.ToString(GetValue(dr, "UNIT_CODE")), "单位")); } //安全在库数 str.Append(CheckDecimal(GetValue(dr, "SAFETY_STOCK", 0), 12, 2, "安全在库数")); //最大在库数 str.Append(CheckDecimal(GetValue(dr, "MAX_QUANTITY", 0), 12, 2, "最大在库数")); //最小采购数 str.Append(CheckDecimal(GetValue(dr, "MIN_PURCHASE_QUANTITY", 0), 12, 2, "最小采购数")); //状态 str.Append(CheckInt(GetValue(dr, "STATUS_FLAG", CConstant.NORMAL_STATUS), 9, "状态")); //str.Append(CheckUnit(dr[6], "单位")); //单位 if (str.ToString().Trim().Length > 0) { strError.Append(GetStringBuilder(dr, str.ToString().Trim())); failureData++; continue; } try { int ret = 0; StockTable = new BaseSafetyStockTable(); StockTable.WAREHOUSE_CODE = CConvert.ToString(GetValue(dr, "WAREHOUSE_CODE")); if (GetValue(dr, "PRODUCT_CODE").ToString().Length > 20) { StockTable.PRODUCT_CODE = CConvert.ToString(GetValue(dr, "PRODUCT_CODE")).Substring(0, 20); } else { StockTable.PRODUCT_CODE = CConvert.ToString(GetValue(dr, "PRODUCT_CODE")); } StockTable.UNIT_CODE = CConvert.ToString(GetValue(dr, "UNIT_CODE", "01")); StockTable.SAFETY_STOCK = CConvert.ToDecimal(GetValue(dr, "SAFETY_STOCK", 0)); StockTable.MAX_QUANTITY = CConvert.ToDecimal(GetValue(dr, "MAX_QUANTITY", 0)); StockTable.MIN_PURCHASE_QUANTITY = CConvert.ToDecimal(GetValue(dr, "MIN_PURCHASE_QUANTITY", 0)); StockTable.STATUS_FLAG = CConvert.ToInt32(GetValue(dr, "STATUS_FLAG", CConstant.NORMAL_STATUS)); StockTable.CREATE_USER = _userInfo.CODE; StockTable.LAST_UPDATE_USER = _userInfo.CODE; if (!bSafetyStock.Exists(StockTable.WAREHOUSE_CODE, StockTable.PRODUCT_CODE)) { bSafetyStock.Add(StockTable); } else { bSafetyStock.Update(StockTable); } successData++; } catch { strError.Append(GetStringBuilder(dr, " 数据导入失败,请与系统管理员联系!").ToString()); failureData++; } } //错误记录处理 if (strError.Length > 0) { errorFilePath = WriteFile(strError.ToString()); } //备份处理 backupFilePath = BackupFile(); return(new string[] { successData.ToString(), failureData.ToString(), errorFilePath, backupFilePath }); }