Пример #1
0
        /// <summary>
        /// Robert Forbes
        /// Created: 2017/02/07
        ///
        /// Creates a new package line in the database
        /// </summary>
        ///
        /// <remarks>
        /// Aaron Usher
        /// Created: 2017/04/21
        ///
        /// Standardized method.
        /// </remarks>
        ///
        /// <param name="packageLine">The package line to add to the database</param>
        /// <returns>Rows affected</returns>
        public static int CreatePackageLine(PackageLine packageLine)
        {
            var rows = 0;

            var conn    = DBConnection.GetConnection();
            var cmdText = @"sp_create_package_line";
            var cmd     = new SqlCommand(cmdText, conn);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@PACKAGE_ID", packageLine.PackageId);
            cmd.Parameters.AddWithValue("@PRODUCT_LOT_ID", packageLine.ProductLotId);
            cmd.Parameters.AddWithValue("@QUANTITY", packageLine.Quantity);
            cmd.Parameters.AddWithValue("@PRICE_PAID", packageLine.PricePaid);

            try
            {
                conn.Open();
                rows = cmd.ExecuteNonQuery();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }

            return(rows);
        }
        /// <summary>
        /// Robert Forbes
        /// 2017/02/07
        ///
        /// Attempts to run the data access method CreatePackageLine(PackageLine proposed) to create a new package line
        /// </summary>
        /// <param name="line">The line to be added to the database</param>
        /// <returns>bool representing if the package line was successfully added</returns>
        public bool CreatePackageLine(PackageLine line)
        {
            bool result = false;

            try
            {
                ProductLot lot = ProductLotAccessor.RetrieveProductLot(line.ProductLotId);

                int?newAvailableQuantity = lot.AvailableQuantity - line.Quantity;

                //Trying to take the quantity in the package line out of the product lot table to update stock levels
                if (ProductLotAccessor.UpdateProductLotAvailableQuantity(line.ProductLotId, lot.AvailableQuantity, newAvailableQuantity) > 0)
                {
                    //if the product lot quantity could be updated then create the package line
                    if (PackageLineAccessor.CreatePackageLine(line) > 0)
                    {
                        result = true;
                    }
                    else //Trying to add the quantity back to the product lot since the package line couldn't be created
                    {
                        ProductLotAccessor.UpdateProductLotAvailableQuantity(line.ProductLotId, newAvailableQuantity, lot.AvailableQuantity);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(result);
        }
Пример #3
0
        private void btnLabelPrint_Click(object sender, EventArgs e)
        {
            string strProcedureName =
                $"{className}.{MethodBase.GetCurrentMethod().Name}";

            long numberOfCarton = 0;

            if (cboCustomers.SelectedItem == null)
            {
                IRAPMessageBox.Instance.ShowErrorMessage("请选择客户!");
                cboCustomers.Focus();
                return;
            }
            else
            {
                PackageClient customer = cboCustomers.SelectedItem as PackageClient;
                numberOfCarton = customer.NumberOfCarton;
            }
            if (cboPackageLines.SelectedItem == null)
            {
                IRAPMessageBox.Instance.ShowErrorMessage("请选择包装线!");
                cboPackageLines.Focus();
                return;
            }
            if (edtCartonNumber.Value <= 0)
            {
                IRAPMessageBox.Instance.ShowErrorMessage("外箱数量不能小于等于零!");
                edtCartonNumber.Focus();
                return;
            }
            if (Convert.ToInt64(edtCartonNumber.Value) > numberOfCarton)
            {
                IRAPMessageBox.Instance.ShowErrorMessage(
                    $"外箱数量不能大于 [{numberOfCarton}]");
                edtCartonNumber.Value = numberOfCarton;
                edtCartonNumber.Focus();
                return;
            }
            if (cboPrinters.SelectedItem == null)
            {
                IRAPMessageBox.Instance.ShowErrorMessage(
                    "请选择一台打印机!");
                cboPrinters.Focus();
                return;
            }

            WriteLog.Instance.WriteBeginSplitter(strProcedureName);
            try
            {
                int    errCode    = 0;
                string errText    = "";
                long   transactNo = 0;

                long          numberOfBox  = Convert.ToInt64(edtBoxNumber.Value);
                long          cartonNumber = Convert.ToInt64(edtCartonNumber.Value);
                PackageClient customer     = cboCustomers.SelectedItem as PackageClient;
                PackageLine   line         = cboPackageLines.SelectedItem as PackageLine;

                AsimcoPackageClient.Instance.usp_SaveFact_PackagePrint(
                    IRAPUser.Instance.CommunityID,
                    mo.MONumber,
                    mo.MOLineNo,
                    0,
                    cartonNumber,
                    customer.T105LeafID,
                    line.T134LeafID,
                    numberOfBox,
                    IRAPUser.Instance.SysLogID,
                    ref transactNo,
                    out errCode,
                    out errText);
                WriteLog.Instance.Write(
                    $"({errCode}){errText}",
                    strProcedureName);
                if (errCode == 0)
                {
                    WriteLog.Instance.Write($"得到打印交易号 [{transactNo}]。", strProcedureName);
                    PrintLabel(transactNo);

                    btnCancel.PerformClick();
                }
                else
                {
                    IRAPMessageBox.Instance.ShowErrorMessage(errText);
                }
            }
            finally
            {
                WriteLog.Instance.WriteEndSplitter(strProcedureName);
            }
        }
Пример #4
0
        /// <summary>
        /// Robert Forbes
        /// 2017/02/07
        ///
        /// Method for handling when the add package line button is clicked
        /// Checks to make sure the data entered is valid and then attempts
        /// to run the database access method to create a package line from the data
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddPackageLine_Click(object sender, RoutedEventArgs e)
        {
            bool    valid        = true;
            int     productLotID = 0;
            int     quantity     = 0;
            decimal price        = 0.0M;

            txtPricePaid.BorderBrush  = System.Windows.Media.Brushes.Black;
            txtProductLot.BorderBrush = System.Windows.Media.Brushes.Black;
            txtQuantity.BorderBrush   = System.Windows.Media.Brushes.Black;
            try
            {
                productLotID = int.Parse(txtProductLot.Text);
            }
            catch
            {
                valid = false;
                //Seting the outline of the text box to red if its not valid
                txtProductLot.BorderBrush = System.Windows.Media.Brushes.Red;
            }

            try
            {
                quantity = int.Parse(txtQuantity.Text);
            }
            catch
            {
                valid = false;
                //Seting the outline of the text box to red if its not valid
                txtQuantity.BorderBrush = System.Windows.Media.Brushes.Red;
            }

            try
            {
                price = int.Parse(txtPricePaid.Text);
            }
            catch
            {
                valid = false;
                //Seting the outline of the text box to red if its not valid
                txtPricePaid.BorderBrush = System.Windows.Media.Brushes.Red;
            }



            if (valid == true)
            {
                //Creating a package line to pass to the manager
                PackageLine pl = new PackageLine()
                {
                    PackageId    = _package.PackageId,
                    ProductLotId = productLotID,
                    Quantity     = quantity,
                    PricePaid    = price
                };

                try
                {
                    if (_packageLineManager.CreatePackageLine(pl))
                    {
                        LoadPackageLines();
                    }
                }
                catch
                {
                    MessageBox.Show("There was a problem communicating with the database. Please ensure you entered a valid product lot ID.");
                }
            }
        }