예제 #1
0
        private void Save_Click(object sender, EventArgs e)
        {
            if (ValidateChildren())
            {
                //Adding Rows
                DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[0].Clone();
                row.Cells[0].Value = NameBox.Text;
                row.Cells[1].Value = PriceBox.Text;
                row.Cells[2].Value = CategoryBox.Text;
                row.Cells[3].Value = BrandBox.Text;
                row.Cells[4].Value = ColorBox.Text;
                row.Cells[5].Value = BarcodeBox.Text;
                row.Cells[6].Value = StockBox.Text;
                row.Cells[7].Value = AdBox.Text;
                dataGridView1.Rows.Add(row);

                NameBox.Clear();
                PriceBox.Clear();
                ColorBox.Clear();
                StockBox.Clear();
                BarcodeBox.Clear();
                AdBox.Clear();
            }
            else
            {
                MessageBox.Show("Please fill form correctly,then save!");
            }
        }
 private void button2_Click_1(object sender, EventArgs e)
 {
     BarcodeBox.Clear();
     ItemDescriptionBox.Clear();
     UnitBox.Clear();
     QuantityBox.Clear();
     UnitPriceBox.Clear();
     RetailPriceBox.Clear();
 }
예제 #3
0
        ////////////////////////////////////////////////////////////////////
        // Draw Cell Initialization
        ////////////////////////////////////////////////////////////////////
        internal void DrawCellInitialization()
        {
            // calculate left and right client space
            ClientLeft  = FrameLeft + Style.Margin.Left;
            ClientRight = FrameLeft + FrameWidth - Style.Margin.Right;

            // initialize cell height to top and bottom margins
            CellHeight = Style.Margin.Top + Style.Margin.Bottom;

            // we have something to draw
            if (Value != null)
            {
                // assume cell type to be text
                Type = CellType.Text;

                // get object type
                Type ValueType = Value.GetType();

                // value is string
                if (ValueType == typeof(string))
                {
                    // multi line text
                    if (Style.MultiLineText)
                    {
                        // convert string to TextBox
                        TextBox = new TextBox(ClientRight - ClientLeft, Style.TextBoxFirstLineIndent, Style.TextBoxLineBreakFactor);
                        TextBox.AddText(Style.Font, Style.FontSize, Style.ForegroundColor, (string)Value);

                        // textbox initialization
                        TextBoxInitialization();
                    }

                    // single line text
                    else
                    {
                        // save value as string
                        FormattedText = (string)Value;

                        // add line spacing
                        CellHeight += Style.FontLineSpacing;
                    }
                }

                // value is text box
                else if (ValueType == typeof(TextBox))
                {
                    // set TextBox
                    TextBox = (TextBox)Value;

                    // test width
                    if (TextBox.BoxWidth - (ClientRight - ClientLeft) > Parent.Epsilon)
                    {
                        throw new ApplicationException("PdfTableCell: TextBox width is greater than column width");
                    }

                    // textbox initialization
                    TextBoxInitialization();
                }

                // value is PdfImage
                else if (ValueType == typeof(PdfImage))
                {
                    // set image
                    Image = (PdfImage)Value;

                    // calculate client width
                    double Width = ClientWidth;

                    // calculate image width and height
                    if (ImageWidth == 0.0)
                    {
                        if (ImageHeight == 0.0)
                        {
                            ImageWidth  = Width;
                            ImageHeight = ImageWidth * (double)Image.HeightPix / (double)Image.WidthPix;
                        }
                        else
                        {
                            ImageWidth = ImageHeight * (double)Image.WidthPix / (double)Image.HeightPix;
                        }
                    }
                    else if (ImageHeight == 0.0)
                    {
                        ImageHeight = ImageWidth * (double)Image.HeightPix / (double)Image.WidthPix;
                    }

                    // image width is too wide
                    if (ImageWidth > Width)
                    {
                        ImageHeight = Width * ImageHeight / ImageWidth;
                        ImageWidth  = Width;
                    }

                    // adjust cell's height
                    CellHeight += ImageHeight;

                    // set type to image
                    Type = CellType.Image;
                }

                // value is a derived class of barcode
                else if (ValueType.BaseType == typeof(Barcode))
                {
                    // set barcode
                    Barcode = (Barcode)Value;

                    // test barcode height
                    if (Style.BarcodeHeight <= 0.0)
                    {
                        throw new ApplicationException("PdfTableStyle: BarcodeHeight must be defined.");
                    }

                    // calculate total barcode height
                    BarcodeBox = Barcode.GetBarcodeBox(Style.BarcodeBarWidth, Style.BarcodeHeight, Style.Font, Style.FontSize);

                    // adjust cell's height
                    CellHeight += BarcodeBox.TotalHeight;

                    // set type to barcode
                    Type = CellType.Barcode;
                }

                // value is basic mostly numeric object
                else
                {
                    string           Format       = Style.Format;
                    NumberFormatInfo NumberFormat = Style.NumberFormatInfo;
                    if (ValueType == typeof(int))
                    {
                        FormattedText = ((int)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(float))
                    {
                        FormattedText = ((float)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(double))
                    {
                        FormattedText = ((double)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(bool))
                    {
                        FormattedText = ((bool)Value).ToString();
                    }
                    else if (ValueType == typeof(char))
                    {
                        FormattedText = ((char)Value).ToString();
                    }
                    else if (ValueType == typeof(byte))
                    {
                        FormattedText = ((byte)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(sbyte))
                    {
                        FormattedText = ((sbyte)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(short))
                    {
                        FormattedText = ((short)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(ushort))
                    {
                        FormattedText = ((ushort)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(uint))
                    {
                        FormattedText = ((uint)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(long))
                    {
                        FormattedText = ((long)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(ulong))
                    {
                        FormattedText = ((ulong)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(decimal))
                    {
                        FormattedText = ((decimal)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(DBNull))
                    {
                        FormattedText = string.Empty;
                    }
                    else
                    {
                        throw new ApplicationException("PdfTableCell: Unknown object type");
                    }

                    // add line spacing
                    CellHeight += Style.FontLineSpacing;
                }
            }

            // value is null and textbox continuation is required
            else if (Type == CellType.TextBox && TextBoxLineNo != 0)
            {
                CellHeight += TextBox.BoxHeightExtra(ref TextBoxLineNo, out int LineEnd,
                                                     Parent._RowTopPosition - Parent.TableBottomLimit - (Style.Margin.Top + Style.Margin.Bottom),
                                                     Style.TextBoxLineExtraSpace, Style.TextBoxParagraphExtraSpace);
                TextBoxCellHeight = CellHeight;
            }
            else
            {
                // reset cell type
                Type = CellType.Empty;
            }

            // test for minimum height requirement
            if (CellHeight < Style.MinHeight)
            {
                CellHeight = Style.MinHeight;
            }

            // cell minimum height for all types but textbox
            if (Type != CellType.TextBox)
            {
                TextBoxCellHeight = CellHeight;
            }

            // return result
            return;
        }
예제 #4
0
        ////////////////////////////////////////////////////////////////////
        // Draw Cell Initialization
        ////////////////////////////////////////////////////////////////////
        internal Double DrawCellInitialization()
        {
            // calculate left and right client space
            ClientLeft  = FrameLeft + Style.Margin.Left;
            ClientRight = FrameLeft + FrameWidth - Style.Margin.Right;

            // initialize cell height to top and bottom margins
            Double CellHeight = Style.Margin.Top + Style.Margin.Bottom;

            // reset cell type
            Type = CellType.Empty;

            // we have something to draw
            if (Value != null)
            {
                // assume cell type to be text
                Type = CellType.Text;

                // get object type
                Type ValueType = Value.GetType();

                // value is string
                if (ValueType == typeof(String))
                {
                    // multi line text
                    if (Style.MultiLineText)
                    {
                        // convert string to TextBox
                        TextBox = new TextBox(ClientRight - ClientLeft, Style.TextBoxFirstLineIndent, Style.TextBoxLineBreakFactor);
                        TextBox.AddText(Style.Font, Style.FontSize, (String)Value);
                        TextBox.Terminate();
                        TextBoxHeight = TextBox.BoxHeightExtra(Style.TextBoxLineExtraSpace, Style.TextBoxParagraphExtraSpace);
                        CellHeight   += TextBoxHeight;
                        Type          = CellType.TextBox;
                    }

                    // single line text
                    else
                    {
                        // save value as string
                        FormattedText = (String)Value;

                        // add line spacing
                        CellHeight += Style.FontLineSpacing;
                    }
                }

                // value is text box
                else if (ValueType == typeof(TextBox))
                {
                    // set TextBox
                    TextBox = (TextBox)Value;

                    // test width
                    if (TextBox.BoxWidth - (ClientRight - ClientLeft) > Parent.Epsilon)
                    {
                        throw new ApplicationException("PdfTableCell: TextBox width is greater than column width");
                    }

                    // terminate TextBox
                    TextBox.Terminate();

                    // calculate TextBox height and add to cell height
                    TextBoxHeight = TextBox.BoxHeightExtra(Style.TextBoxLineExtraSpace, Style.TextBoxParagraphExtraSpace);
                    CellHeight   += TextBoxHeight;

                    // set type to text box
                    Type = CellType.TextBox;
                }

                // value is PdfImage
                else if (ValueType == typeof(PdfImage))
                {
                    // set image
                    Image = (PdfImage)Value;

                    // calculate client width
                    Double Width = ClientWidth;

                    // calculate image width and height
                    if (ImageWidth == 0.0)
                    {
                        if (ImageHeight == 0.0)
                        {
                            ImageWidth  = Width;
                            ImageHeight = ImageWidth * (Double)Image.HeightPix / (Double)Image.WidthPix;
                        }
                        else
                        {
                            ImageWidth = ImageHeight * (Double)Image.WidthPix / (Double)Image.HeightPix;
                        }
                    }
                    else if (ImageHeight == 0.0)
                    {
                        ImageHeight = ImageWidth * (Double)Image.HeightPix / (Double)Image.WidthPix;
                    }

                    // image width is too wide
                    if (ImageWidth > Width)
                    {
                        ImageHeight = Width * ImageHeight / ImageWidth;
                        ImageWidth  = Width;
                    }

                    // adjust cell's height
                    CellHeight += ImageHeight;

                    // set type to image
                    Type = CellType.Image;
                }

                // value is PdfQRCode
                else if (ValueType == typeof(PdfQRCode))
                {
                    // set QR Code
                    QRCode = (PdfQRCode)Value;

                    // calculate client width
                    Double Width = ClientWidth;

                    // calculate QR Code width
                    if (QRCodeWidth == 0.0 || QRCodeWidth > Width)
                    {
                        QRCodeWidth = Width;
                    }

                    // adjust cell's height
                    CellHeight += QRCodeWidth;

                    // set type to QR Code
                    Type = CellType.QRCode;
                }

                // value is a derived class of barcode
                else if (ValueType.BaseType == typeof(Barcode))
                {
                    // set barcode
                    Barcode = (Barcode)Value;

                    // test barcode height
                    if (Style.BarcodeHeight <= 0.0)
                    {
                        throw new ApplicationException("PdfTableStyle: BarcodeHeight must be defined.");
                    }

                    // calculate total barcode height
                    BarcodeBox = Barcode.GetBarcodeBox(Style.BarcodeBarWidth, Style.BarcodeHeight, Style.Font, Style.FontSize);

                    // adjust cell's height
                    CellHeight += BarcodeBox.TotalHeight;

                    // set type to barcode
                    Type = CellType.Barcode;
                }

                // value is basic mostly numeric object
                else
                {
                    String           Format       = Style.Format;
                    NumberFormatInfo NumberFormat = Style.NumberFormatInfo;
                    if (ValueType == typeof(Int32))
                    {
                        FormattedText = ((Int32)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(Single))
                    {
                        FormattedText = ((Single)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(Double))
                    {
                        FormattedText = ((Double)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(Boolean))
                    {
                        FormattedText = ((Boolean)Value).ToString();
                    }
                    else if (ValueType == typeof(Char))
                    {
                        FormattedText = ((Char)Value).ToString();
                    }
                    else if (ValueType == typeof(Byte))
                    {
                        FormattedText = ((Byte)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(SByte))
                    {
                        FormattedText = ((SByte)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(Int16))
                    {
                        FormattedText = ((Int16)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(UInt16))
                    {
                        FormattedText = ((UInt16)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(UInt32))
                    {
                        FormattedText = ((UInt32)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(Int64))
                    {
                        FormattedText = ((Int64)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(UInt64))
                    {
                        FormattedText = ((UInt64)Value).ToString(Format, NumberFormat);
                    }
                    else if (ValueType == typeof(Decimal))
                    {
                        FormattedText = ((Decimal)Value).ToString(Format, NumberFormat);
                    }
                    else
                    {
                        throw new ApplicationException("PdfTableCell: Unknown object type");
                    }

                    // add line spacing
                    CellHeight += Style.FontLineSpacing;
                }
            }

            // test for minimum height requirement
            if (CellHeight < Style.MinHeight)
            {
                CellHeight = Style.MinHeight;
            }

            // return result
            return(CellHeight);
        }