Ejemplo n.º 1
0
        private void btn_Calculate_Net_Weight_Click(object sender, EventArgs e)
        {
            var grossWeight = 0.0;
            var tare1       = 0.0;
            var tare2       = 0.0;
            var tareWeight  = 0.0;
            var netWeight   = 0.0;



            //get gross weight
            AddExpression expression = new AddExpression();

            try
            {
                //grossWeight = getWeight(txt_Gross_Weight_Value.Text);
                grossWeight = expression.getListSum(txt_Gross_Weight_Value.Text);
            }
            catch (Exception exc)
            {
                txt_Gross_Weight_Value.Text = "";
                txt_Gross_Weight_Value.Focus();
                MessageBox.Show(exc.Message);
                return;
            }

            //-----------------------Calculate Net weight when using container list tare-----------------------

            if (pnl_Containers.Enabled)
            {
                //local copy of container list
                var containerList = container.getContainerList();

                //use linq query to get tare weight from container selected from the combo box
                var tare =
                    from containers in containerList
                    where containers.ContainerName == cbo_Container_List_Value.Text
                    select containers;

                foreach (var item in tare)
                {
                    tare1 = item.TareWeight;
                }

                tare =
                    from containers in containerList
                    where containers.ContainerName == cbo_Container_List_2_Value.Text
                    select containers;

                foreach (var item in tare)
                {
                    tare2 = item.TareWeight;
                }

                tareWeight = tare1 + tare2;



                netWeight = grossWeight - tareWeight;

                txt_Net_Weight_Value.Text = $"{netWeight:0.00}";
            }

            //-------------------------Calculate Net weight when using Custom tare--------------------------------
            if (pnl_Custom_Tare.Enabled)
            {
                //get tare weight
                try
                {
                    tareWeight = getWeight(txt_Custom_Tare_Value.Text);
                }
                catch (FormatException Not_A_Number)
                {
                    MessageBox.Show(Not_A_Number.Message);
                    return;
                }

                //adjust tare weight if user indicates that the value is in pounds
                if (rad_Pounds.Checked)
                {
                    tareWeight = tareWeight / 2.204;
                }

                netWeight = grossWeight - tareWeight;

                txt_Net_Weight_Value.Text = $"{netWeight:0.00}";
            }
        }