Ejemplo n.º 1
0
        /// <summary>
        /// Save the Material and also a blank entry for the corresponding cost centre
        /// </summary>
        /// <param name="m"></param>
        /// <param name="type"></param>
        public void SaveMaterial(Accessor.MaterialProperties m, int type)
        {
            using (LinqtoNewAgeDataContext dc = new LinqtoNewAgeDataContext())
            {
                tblMaterial mat = new tblMaterial
                {
                    MaterialID  = m.MaterialID,
                    Name        = m.MaterialName,
                    Description = m.Destcription,
                    TypeID      = m.TypeID
                };

                dc.tblMaterials.InsertOnSubmit(mat);
                try
                {
                    dc.SubmitChanges();
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString(), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                switch (type)
                {
                    #region Length
                case 1:
                    tblLengthCost l = new tblLengthCost
                    {
                        TypeID          = 1,
                        MaterialID      = m.MaterialID,
                        NoPieces        = 0,
                        TotalLength     = 0,
                        LengthPerPiece  = 0,
                        TotalCostPieces = 0,
                        PricePerMeter   = 0
                    };
                    dc.tblLengthCosts.InsertOnSubmit(l);
                    try
                    {
                        dc.SubmitChanges();
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.ToString(), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }

                    break;
                    #endregion Length

                    #region Area
                case 2:
                    tblAreaCost a = new tblAreaCost
                    {
                        TypeID          = 2,
                        MaterialID      = m.MaterialID,
                        TotalLenght     = 0,
                        TotalWidth      = 0,
                        TotalCost       = 0,
                        PricePerMeterSQ = 0,
                        TotalArea       = 0
                    };
                    dc.tblAreaCosts.InsertOnSubmit(a);
                    try
                    {
                        dc.SubmitChanges();
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.ToString(), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }

                    break;
                    #endregion Area

                    #region Volume
                case 3:
                    tblVolumeCost v = new tblVolumeCost
                    {
                        TypeID        = 3,
                        MaterialID    = m.MaterialID,
                        TotalVolume   = 0,
                        TotalCost     = 0,
                        PricePerLiter = 0
                    };
                    dc.tblVolumeCosts.InsertOnSubmit(v);
                    try
                    {
                        dc.SubmitChanges();
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.ToString(), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }

                    break;
                    #endregion Volume

                    #region BussinessCost
                case 4:
                    tblBussinessCost b = new tblBussinessCost
                    {
                        TypeID      = 4,
                        MaterialID  = m.MaterialID,
                        CostName    = m.MaterialName,
                        RatePerHour = 0,
                    };
                    dc.tblBussinessCosts.InsertOnSubmit(b);
                    try
                    {
                        dc.SubmitChanges();
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.ToString(), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }

                    break;
                    #endregion BussinessCost

                //TODO FINISH INSERT
                default:
                    break;
                }
            }
        }
        /// <summary>
        /// Sets the inititial display populating all the fields with the selection
        /// </summary>
        public void SetDisplay()
        {
            int frameTyepID = 1; //Default

            switch (frameType)
            {
            case myFrameType.SquareTwoFifty:
                frameTyepID = 1;
                break;

            case myFrameType.Atwo:
                frameTyepID = 2;
                break;

            case myFrameType.SquareFourFifty:
                frameTyepID = 3;
                break;

            case myFrameType.FourFifty:
                frameTyepID = 4;
                break;

            case myFrameType.FiveFifty:
                frameTyepID = 5;
                break;

            case myFrameType.Pane:
                frameTyepID = 6;
                break;

            default:
                break;
            }

            tblAtlanticCanvasLength o      = DataEngine.GetAtlanticLength(frameTyepID, materialID);
            tblMaterial             mat    = DataEngine.GetMaterial(materialID);
            tblLengthCost           length = DataEngine.GetLengthPricePerMeter(materialID);

            //Top Frame
            lblFrame.Text      = mat.Name;
            lblMaterialID.Text = materialID;
            string pricePerMeter = string.Format("{0:C}", length.PricePerMeter);

            lblPricePerMeter.Text = pricePerMeter;

            // Details

            string frameLength = string.Format("{0:0.00}", o.FrameLenght);

            lblFrameLength.Text = frameLength;

            string frameWidth = string.Format("{0:0.00}", o.FrameWidth);

            lblFrameWidth.Text = frameWidth;

            string noFrames = string.Format("{0:0.00}", o.NoOfFrames);

            lblNoFrames.Text = noFrames;

            string TotalUsedFrmCost = string.Format("{0:C}", o.TotalUsedFrameCost);

            lblTotalUsedFrameCost.Text = TotalUsedFrmCost;

            string frameArea = string.Format("{0:0.00}", o.FrameArea);

            lblFrameArea.Text = frameArea;

            string canvasOverlap = string.Format("{0:0.00}", o.CanvasOverlap);

            lblCanvasOveralap.Text = canvasOverlap;

            string totalCanvasArea = string.Format("{0:0.00}", o.TotalCanvasArea);

            lblTotalCanvasArea.Text = totalCanvasArea;

            string frameTotalArea = string.Format("{0:0.00}", o.TotalFrameLength);

            lblTotalFrameArea.Text = o.TotalFrameLength.ToString();

            atlanticID = o.AtlanticCanvasLenID;
        }