private double Calculate_Die_Price(bool silent = false)
        {
            if (Loaded)
            {
                this.Height = panel1.Visible ? 512 : 412;
                TFLP.Size   = new Size(this.Width - 2, this.Height - 2);


                if (!silent)
                {
                    Grey_Out();
                    Application.DoEvents();

                    if (secondThreadFormHandle == IntPtr.Zero)
                    {
                        Loading_Form form2 = new Loading_Form(parent, this.Location, this.Size, "CALCULATING", "PRICE")
                        {
                        };
                        form2.HandleCreated   += SecondFormHandleCreated;
                        form2.HandleDestroyed += SecondFormHandleDestroyed;
                        form2.RunInNewThread(false);
                    }
                }

                bool   Error  = false;
                bool   Rework = false;
                double price  = 0;
                double weight = 0;

                try
                {
                    price             = Ref_BaseCharge.Price;
                    current_cav_price = 0;

                    // If base price is 0, error
                    if (price == 0)
                    {
                        Error = true;
                    }

                    Console.WriteLine(Ref_BaseCharge.ToString());

                    // Get hole charge
                    if (cavities.Text != "1" && ((refHoleCharges != null && refHoleCharges.holeQty != Convert.ToInt32(cavities.Text)) || refHoleCharges == null))
                    {
                        refHoleCharges    = parent.holeCharge_List.FirstOrDefault(x => (x.holeQty == Convert.ToInt32(cavities.Text)) && x.Diameter == Ref_BaseCharge.Diameter && x.Thickness == Ref_BaseCharge.Thickness && x.Prefix == parent.Get_Die_Prefix(dt));
                        price            += refHoleCharges.Price * refHoleCharges.holeQty;
                        current_cav_price = refHoleCharges.Price * refHoleCharges.holeQty;
                    }
                    else if (cavities.Text != "1")
                    {
                        price            += refHoleCharges.Price * refHoleCharges.holeQty;
                        current_cav_price = refHoleCharges.Price * refHoleCharges.holeQty;
                    }

                    // Get special charges
                    additionalCharges.Text = "";
                    string passText = "";
                    foreach (DieCharge DC in DieCharge_List)
                    {
                        if (DC.Name.ToLower().Contains("rework") && DC.Quantity > 0)
                        {
                            Rework    = true;
                            price    += DC.GetAdditionalCost(Ref_BaseCharge.Price + current_cav_price); // Only allow one quantity of rework
                            passText += ", " + DC.Name + " (" + DC.Quantity + ")";
                        }
                        else if (DC.Quantity > 0)
                        {
                            price    += DC.GetAdditionalCost(Ref_BaseCharge.Price + current_cav_price) * DC.Quantity;
                            passText += ", " + DC.Name + " (" + DC.Quantity + ")";
                        }
                    }
                    if (passText.Length > 2)
                    {
                        additionalCharges.Text = passText.Substring(2);
                    }
                    if (passText.Length > 150)
                    {
                        additionalCharges.ScrollBars = ScrollBars.Vertical;
                    }

                    Console.WriteLine("Base Price = " + price);

                    // Get surcharge price
                    GetSurchargeWeight(0, dt, Ref_BaseCharge.Diameter, Ref_BaseCharge.Thickness, 1, out weight);
                    price += parent.surchargeRate * weight;

                    // Get Nitride cost if checked

                    if (nitride.Checked)
                    {
                        price += parent.GetFreightWeight("", dt, Convert.ToDouble(dia.Text) / MetricFactor, Convert.ToDouble(thk.Text) / MetricFactor, 0) * parent.nitrideRate;
                    }

                    // Nitride cost off actual size instead of odd size
                    //if (nitride.Checked)
                    //    price += parent.GetFreightWeight("",dt, Ref_BaseCharge.Diameter, Ref_BaseCharge.Thickness, 0) * parent.nitrideRate;

                    if (plate.Checked)
                    {
                        price += 50;
                    }

                    surchargeLabel.Text = "Steel Surcharge: $" + String.Format("{0:0.00}", parent.surchargeRate * weight) + " (" + Math.Round(weight, 2) + "lbs @ $" + String.Format("{0:0.00}", parent.surchargeRate) + "/lb)";
                    totalLabel.Text     = "Total: $" + String.Format("{0:0.00}", price);
                }
                catch
                {
                    Error = true;
                }

                if (!silent)
                {
                    Grey_In();

                    if (secondThreadFormHandle != IntPtr.Zero)
                    {
                        PostMessage(secondThreadFormHandle, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
                    }
                }

                if (Error || (!Rework && (price - parent.surchargeRate * weight) == 0) || (plate.Checked || mandrel.Checked || backer.Checked))
                {
                    surchargeLabel.Text = "";
                    totalLabel.Text     = "Please call in for quote";
                    return(0);
                }
                else
                {
                    Console.WriteLine("Price = " + price);
                    return(price);
                }
            }
            return(0);
        }
Beispiel #2
0
        private double Calculate_Die_Price(bool silent = false)
        {
            if (Loaded)
            {
                this.Height = panel1.Visible ? 512 : 412;
                TFLP.Size   = new Size(this.Width - 2, this.Height - 2);

                if (!silent)
                {
                    Grey_Out();
                    Application.DoEvents();

                    if (secondThreadFormHandle == IntPtr.Zero)
                    {
                        Loading_Form form2 = new Loading_Form(parent, this.Location, this.Size, "CALCULATING", "PRICE")
                        {
                        };
                        form2.HandleCreated   += SecondFormHandleCreated;
                        form2.HandleDestroyed += SecondFormHandleDestroyed;
                        form2.RunInNewThread(false);
                    }
                }

                bool   Error  = false;
                bool   Rework = false;
                double price  = 0;
                double weight = 0;

                try
                {
                    price             = Ref_BaseCharge.Price;
                    current_cav_price = 0;

                    // If base price is 0, error
                    if (price == 0 || Ref_BaseCharge.InnerDiameter - 1 > Ref_BaseCharge.Diameter)
                    {
                        Error = true;
                    }

                    Console.WriteLine(Ref_BaseCharge.ToString());

                    // Get special charges
                    additionalCharges.Text = "";
                    string passText = "";
                    foreach (DieCharge DC in DieCharge_List)
                    {
                        if (DC.Name.ToLower().Contains("rework") && DC.Quantity > 0)
                        {
                            Rework    = true;
                            price    += DC.GetAdditionalCost(Ref_BaseCharge.Price + current_cav_price); // Only allow one quantity of rework
                            passText += ", " + DC.Name + " (" + DC.Quantity + ")";
                        }
                        else if (DC.Quantity > 0)
                        {
                            price    += DC.GetAdditionalCost(Ref_BaseCharge.Price + current_cav_price) * DC.Quantity;
                            passText += ", " + DC.Name + " (" + DC.Quantity + ")";
                        }
                    }
                    if (passText.Length > 2)
                    {
                        additionalCharges.Text = passText.Substring(2);
                    }
                    if (passText.Length > 150)
                    {
                        additionalCharges.ScrollBars = ScrollBars.Vertical;
                    }

                    Console.WriteLine("Base Price = " + price);

                    // Get surcharge price
                    GetSurchargeWeight(0, dt, Ref_BaseCharge.Diameter, Ref_BaseCharge.Thickness, 1, out weight);
                    price += parent.surchargeRate * weight;

                    surchargeLabel.Text = "Steel Surcharge: $" + String.Format("{0:0.00}", parent.surchargeRate * weight) + " (" + Math.Round(weight, 2) + "lbs @ $" + String.Format("{0:0.00}", parent.surchargeRate) + "/lb)";
                    totalLabel.Text     = "Total: $" + String.Format("{0:0.00}", price);
                }
                catch
                {
                    Error = true;
                }

                if (!silent)
                {
                    Grey_In();

                    if (secondThreadFormHandle != IntPtr.Zero)
                    {
                        PostMessage(secondThreadFormHandle, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
                    }
                }

                if (Error || (!Rework && (price - parent.surchargeRate * weight) == 0))
                {
                    surchargeLabel.Text = "";
                    totalLabel.Text     = "Please call in for quote";
                    return(0);
                }
                else
                {
                    Console.WriteLine("Price = " + price);
                    return(price);
                }
            }
            return(0);
        }