Пример #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (CheckInput())
            {
                if (_currentProductPartsTable == null)
                {
                    _currentProductPartsTable = new BaseProductPartsTable();
                }

                _currentProductPartsTable.PRODUCT_CODE      = txtProductCode.Text;
                _currentProductPartsTable.PRODUCT_PART_CODE = txtPartsCode.Text;
                _currentProductPartsTable.QUANTITY          = Convert.ToDecimal(txtQuantity.Text);
                _currentProductPartsTable.LAST_UPDATE_USER  = _userInfo.CODE;

                try
                {
                    if (bProductParts.Exists(txtProductCode.Text.Trim(), txtPartsCode.Text.Trim()))
                    {
                        bProductParts.Update(_currentProductPartsTable);
                    }
                    else
                    {
                        _currentProductPartsTable.CREATE_USER = _userInfo.CODE;
                        bProductParts.Add(_currentProductPartsTable);
                    }
                }
                catch (Exception ex)
                {
                    //log.error
                    MessageBox.Show("");
                    return;
                }
                result = DialogResult.OK;
                this.Close();
            }
        }
Пример #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (CheckInput())
            {
                //判断编号是否已存在
                if (_mode != CConstant.MODE_MODIFY)
                {
                    if (!string.IsNullOrEmpty(this.txtProductCode.Text.Trim()) && !string.IsNullOrEmpty(this.txtPartsCode.Text.Trim()))
                    {
                        if (bProductParts.Exists(txtProductCode.Text.Trim(), txtPartsCode.Text.Trim()))
                        {
                            MessageBox.Show("规格型号和构成件的组合已存在。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            txtPartsCode.Text = "";
                            txtPartsName.Text = "";
                            txtPartsCode.Focus();
                            return;
                        }
                    }
                }

                if (_currentProductPartsTable == null)
                {
                    _currentProductPartsTable = new BaseProductPartsTable();
                }

                _currentProductPartsTable.PRODUCT_CODE       = txtProductCode.Text.Trim();
                _currentProductPartsTable.PRODUCT_PARTS_CODE = txtPartsCode.Text.Trim();
                _currentProductPartsTable.QUANTITY           = Convert.ToDecimal(txtQuantity.Text.Trim());
                _currentProductPartsTable.LAST_UPDATE_USER   = _userInfo.CODE;

                try
                {
                    bool ret = false;
                    if (bProductParts.Exists(txtProductCode.Text.Trim(), txtPartsCode.Text.Trim()))
                    {
                        ret = bProductParts.Update(_currentProductPartsTable);
                    }
                    else
                    {
                        _currentProductPartsTable.CREATE_USER = _userInfo.CODE;
                        ret = bProductParts.Add(_currentProductPartsTable);
                    }
                    if (ret)
                    {
                        result = DialogResult.OK;
                        if ("btnSaveAndNew".Equals(((Button)sender).Name))
                        {
                            ClearAll();
                        }
                        else
                        {
                            this.Close();
                        }
                    }
                    else
                    {
                        MessageBox.Show("保存失败,请重试或与系统管理员联系。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("保存失败,请重试或与系统管理员联系。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    Logger.Error("规格型号构成保存失败。", ex);
                    return;
                }
            }
        }
Пример #3
0
        public override string[] doUpdateDB()
        {
            BaseProductPartsTable ProductPartsTable = null;
            BProductParts         bProductParts     = new BProductParts();
            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 (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 (CConvert.ToString(GetValue(dr, "PRODUCT_PART_CODE")).Length > 40)
                {
                    string productpart = GetValue(dr, "PRODUCT_PART_CODE").ToString().Substring(0, 40);
                    str.Append(CheckProduct(productpart, "材料商品编号"));
                }
                else
                {
                    str.Append(CheckProduct(CConvert.ToString(GetValue(dr, "PRODUCT_PART_CODE")), "材料商品编号"));
                }
                //数量
                str.Append(CheckDecimal(GetValue(dr, "QUANTITY", 0), 12, 2, "数量"));
                //状态
                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
                {
                    ProductPartsTable = new BaseProductPartsTable();
                    if (GetValue(dr, "PRODUCT_CODE").ToString().Length > 20)
                    {
                        ProductPartsTable.PRODUCT_CODE = CConvert.ToString(GetValue(dr, "PRODUCT_CODE")).Substring(0, 20);
                    }
                    else
                    {
                        ProductPartsTable.PRODUCT_CODE = CConvert.ToString(GetValue(dr, "PRODUCT_CODE"));
                    }
                    if (GetValue(dr, "PRODUCT_PART_CODE").ToString().Length > 20)
                    {
                        ProductPartsTable.PRODUCT_CODE = CConvert.ToString(GetValue(dr, "PRODUCT_PART_CODE")).Substring(0, 20);
                    }
                    else
                    {
                        ProductPartsTable.PRODUCT_CODE = CConvert.ToString(GetValue(dr, "PRODUCT_PART_CODE"));
                    }
                    ProductPartsTable.QUANTITY         = CConvert.ToDecimal(GetValue(dr, "QUANTITY", 0));
                    ProductPartsTable.STATUS_FLAG      = CConvert.ToInt32(GetValue(dr, "STATUS_FLAG", CConstant.NORMAL_STATUS));
                    ProductPartsTable.CREATE_USER      = _userInfo.CODE;
                    ProductPartsTable.LAST_UPDATE_USER = _userInfo.CODE;

                    if (!bProductParts.Exists(ProductPartsTable.PRODUCT_CODE, ProductPartsTable.PRODUCT_PART_CODE))
                    {
                        bProductParts.Add(ProductPartsTable);
                    }
                    else
                    {
                        bProductParts.Update(ProductPartsTable);
                    }
                    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 });
        }