Exemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (CheckInput())
            {
                if (_currentLocationTable == null)
                {
                    _currentLocationTable = new BaseLocationTable();
                }

                _currentLocationTable.CODE             = txtCode.Text;
                _currentLocationTable.NAME             = txtName.Text;
                _currentLocationTable.PRODUCT_CODE     = txtProductCode.Text;
                _currentLocationTable.WAREHOUSE_CODE   = txtWarehouseCode.Text;
                _currentLocationTable.LAST_UPDATE_USER = _userInfo.CODE;

                try
                {
                    if (bLocation.Exists(txtCode.Text.Trim(), txtProductCode.Text.Trim(), txtWarehouseCode.Text.Trim()))
                    {
                        bLocation.Update(_currentLocationTable);
                    }
                    else
                    {
                        _currentLocationTable.CREATE_USER = _userInfo.CODE;
                        bLocation.Add(_currentLocationTable);
                    }
                }
                catch (Exception ex)
                {
                    //log.error
                    MessageBox.Show("");
                    return;
                }
                result = DialogResult.OK;
                this.Close();
            }
        }
Exemplo n.º 2
0
        public override string[] doUpdateDB()
        {
            BaseLocationTable LocationTable = null;
            BLocation         bLocation     = new BLocation();
            StringBuilder     strError      = new StringBuilder();
            int    successData    = 0;
            int    failureData    = 0;
            string errorFilePath  = "";
            string backupFilePath = "";

            //数据导入处理
            foreach (DataRow dr in _csvDataTable.Rows)
            {
                StringBuilder str = new StringBuilder();
                //编号
                if (!string.IsNullOrEmpty(CConvert.ToString(GetValue(dr, "CODE"))))
                {
                    str.Append(CheckString(GetValue(dr, "CODE"), 20, "编号"));
                }
                else
                {
                    str.Append("编号不能为空!");
                }
                //名称
                str.Append(CheckLenght(GetValue(dr, "NAME"), 100, "名称"));
                //状态
                str.Append(CheckInt(GetValue(dr, "STATUS_FLAG", CConstant.NORMAL_STATUS), 9, "状态"));

                if (str.ToString().Trim().Length > 0)
                {
                    strError.Append(GetStringBuilder(dr, str.ToString().Trim()));
                    failureData++;
                    continue;
                }
                try
                {
                    LocationTable                  = new BaseLocationTable();
                    LocationTable.CODE             = CConvert.ToString(GetValue(dr, "CODE"));
                    LocationTable.NAME             = CConvert.ToString(GetValue(dr, "NAME"));
                    LocationTable.STATUS_FLAG      = CConvert.ToInt32(GetValue(dr, "STATUS_FLAG", CConstant.NORMAL_STATUS));
                    LocationTable.CREATE_USER      = _userInfo.CODE;
                    LocationTable.LAST_UPDATE_USER = _userInfo.CODE;

                    if (!bLocation.Exists(LocationTable.CODE))
                    {
                        LocationTable.CREATE_DATE_TIME = DateTime.Now;
                        LocationTable.LAST_UPDATE_TIME = DateTime.Now;
                        bLocation.Add(LocationTable);
                    }
                    else
                    {
                        LocationTable.LAST_UPDATE_TIME = DateTime.Now;
                        bLocation.Update(LocationTable);
                    }
                    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 });
        }