Example #1
0
        private void frmOption_Load(object sender, EventArgs e)
        {
            this.FormBorderStyle = FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;

            initData();

            this.printControl = new DevExpress.XtraPrinting.Control.PrintControl();
            this.gcPreview.Controls.Add(printControl);
            this.printControl.Dock = DockStyle.Fill;

            bc = new ProductBarcode(null);
            GetBarcodeOption();
            DevExpress.XtraReports.UI.XtraReport xr = bc.GetReportStamp(this.tenDonVi.Text.Trim());
            printControl.PrintingSystem = xr.PrintingSystem;
            xr.PrintingSystem.ClearContent();
            xr.CreateDocument();

            printControl.ExecCommand(DevExpress.XtraPrinting.PrintingSystemCommand.ViewWholePage);
            //if (symbc == -1)
            //{
            //    EAN13Chk.Focus();
            //}
            //else
            //{
            //    OtherChk.Focus();
            //}
        }
        ////*************Khoi tao BarCodeOption
        private ProductBarcode InitBarCodeOption()
        {
            DOBarcodeOption configOption = DOBarcodeOption.load();

            //DataTable tab = InitDataTable();
            //TrialPLBarCodeProduct bc = new TrialPLBarCodeProduct(InitDataFromTable(tab),"ID", "NAME", "UNIT", "PRICE", "QUANTITY");

            ProductBarcode bc = new ProductBarcode(InitDataFromTable(data), "ID", "NAME", "UNIT", "PRICE", "QUANTITY");

            int symbc = HelpNumber.ParseInt32(configOption.SYM_BARCODE);
            if (symbc == -1)
                bc.symBC = BarCodeType.EAN13;
            else
                bc.symBC = ProductBarcode.getBarCodeType(symbc);

            bc.pos = new StyleLabelBarcode[4];
            bc.alight = new DevExpress.XtraPrinting.TextAlignment[4];

            bc.pos[0] = StyleLabelBarcode.None;
            bc.pos[1] = StyleLabelBarcode.None;
            bc.pos[2] = StyleLabelBarcode.None;
            bc.pos[3] = StyleLabelBarcode.None;

            bc.alight[0] = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
            bc.alight[1] = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
            bc.alight[2] = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
            bc.alight[3] = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;

            if (configOption.UNIT_USING == "Y")
            {
                bc.barcode_param = configOption.BARCODE_PARAM;

                bc.pos[HelpNumber.ParseInt32(configOption.UNIT_POS) - 1] = StyleLabelBarcode.Unit;

                if (configOption.UNIT_ALIGHT == 0)
                    bc.alight[HelpNumber.ParseInt32(configOption.UNIT_POS) - 1] = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
                else if (configOption.UNIT_ALIGHT == 1)
                    bc.alight[HelpNumber.ParseInt32(configOption.UNIT_POS) - 1] = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
                else if (configOption.UNIT_ALIGHT == 2)
                    bc.alight[HelpNumber.ParseInt32(configOption.UNIT_POS) - 1] = DevExpress.XtraPrinting.TextAlignment.MiddleRight;
            }

            if (configOption.NAME_USING == "Y")
            {
                bc.pos[HelpNumber.ParseInt32(configOption.NAME_POS) - 1] = StyleLabelBarcode.Name;

                if (configOption.NAME_ALIGHT == 0)
                    bc.alight[HelpNumber.ParseInt32(configOption.NAME_POS) - 1] = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
                else if (configOption.NAME_ALIGHT == 1)
                    bc.alight[HelpNumber.ParseInt32(configOption.NAME_POS) - 1] = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
                else if (configOption.NAME_ALIGHT == 2)
                    bc.alight[HelpNumber.ParseInt32(configOption.NAME_POS) - 1] = DevExpress.XtraPrinting.TextAlignment.MiddleRight;
            }

            if (configOption.BARCODE_USING == "Y")
            {
                bc.pos[HelpNumber.ParseInt32(configOption.BARCODE_POS) - 1] = StyleLabelBarcode.Barcode;

                if (configOption.BARCODE_ALIGHT == 0)
                    bc.alight[HelpNumber.ParseInt32(configOption.BARCODE_POS) - 1] = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
                else if (configOption.BARCODE_ALIGHT == 1)
                    bc.alight[HelpNumber.ParseInt32(configOption.BARCODE_POS) - 1] = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
                else if (configOption.BARCODE_ALIGHT == 2)
                    bc.alight[HelpNumber.ParseInt32(configOption.BARCODE_POS) - 1] = DevExpress.XtraPrinting.TextAlignment.MiddleRight;
            }

            if (configOption.PRICE_USING == "Y")
            {
                bc.pos[HelpNumber.ParseInt32(configOption.PRICE_POS) - 1] = StyleLabelBarcode.Price;

                if (configOption.PRICE_ALIGHT == 0)
                    bc.alight[HelpNumber.ParseInt32(configOption.PRICE_POS) - 1] = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
                else if (configOption.PRICE_ALIGHT == 1)
                    bc.alight[HelpNumber.ParseInt32(configOption.PRICE_POS) - 1] = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
                else if (configOption.PRICE_ALIGHT == 2)
                    bc.alight[HelpNumber.ParseInt32(configOption.PRICE_POS) - 1] = DevExpress.XtraPrinting.TextAlignment.MiddleRight;
            }

            bc.heightBarcode = HelpNumber.ParseInt32(configOption.BARCODE_HEIGHT);
            bc.widthBarcode = HelpNumber.ParseInt32(configOption.BARCODE_WIDTH);

            bc.idCountry = configOption.COUNTRY;
            bc.idProvider = configOption.PROVIDER;

            bc.widthStamp = HelpNumber.ParseInt32(configOption.STAMP_WIDTH);
            bc.heightStamp = HelpNumber.ParseInt32(configOption.STAMP_HEIGHT);

            //Thiet lap kho giay
            bc.paperKind = GetPaperSize().Kind;

            //Thiet lap canh le
            //bc.marginBottom = GetMarginBottom();
            //bc.marginTop = GetMarginTop();
            //bc.marginLeft = GetMarginLeft();
            //bc.marginRight = GetMarginRight();

            bc.marginBottom = 0;
            bc.marginTop = 0;
            bc.marginLeft = 0;
            bc.marginRight = 0;

            bc.widthPage = GetPaperSize().Width;
            bc.heightPage = GetPaperSize().Height;

            bc.char_number = configOption.CHAR_NUMBER;
            bc.barcode_param = configOption.BARCODE_PARAM;

            return bc;
        }
Example #3
0
        public BarcodeNColMRow(ProductBarcode info, int totalColPerNum, int totalRowPerPage, 
            int chieuCaoKhuonBe, int chieuRongKhuonBe, bool inKhung)
        {
            ReportUnit = ReportUnit.HundredthsOfAnInch;

            this.info = info;
            if (chieuCaoKhuonBe == -1)
            {
                info.heightContent = info.heightPage - info.marginTop - info.marginBottom;
            }
            else
            {
                info.heightContent = chieuCaoKhuonBe - info.marginTop - info.marginBottom;
            }

            if (chieuRongKhuonBe == -1)
            {
                info.widthContent = info.widthPage - info.marginLeft - info.marginRight;
            }
            else {
                info.widthContent = chieuRongKhuonBe - info.marginLeft - info.marginRight;
            }

            //Xác định số row trên 1 trang
            int rowNum = 0;
            if (this.info.dsProduct != null && this.info.dsProduct.Tables[0] != null)
            {
                rowNum = 0;
                for (int i = 0; i < this.info.dsProduct.Tables[0].Rows.Count; i++)
                {
                    rowNum += HelpNumber.ParseInt32(this.info.dsProduct.Tables[0].Rows[i][this.info.fieldQuantity]);
                }
                rowNum = ((rowNum % totalColPerNum) > 0 ? (rowNum / totalColPerNum + 1) : (rowNum / totalColPerNum));
            }
            InitializeComponent();
            ((System.ComponentModel.ISupportInitialize)(this.xrTable)).BeginInit();

            this.Detail.KeepTogether = false;
            this.Detail.Height = info.heightContent;

            //Dùng các khổ giấy của máy in
            //this.PaperKind = info.paperKind;
            //this.PageWidth = info.widthPage;
            //this.PageHeight = info.heightPage;
            //this.PageSize = new Size(info.widthPage, info.heightPage);
            //this.Margins = new System.Drawing.Printing.Margins(info.marginLeft, info.marginRight,
            //    info.marginTop - 1, info.marginBottom - 1);

            //Dùng khổ giấy do mình định nghĩa
            this.PaperKind = 0;
            this.PageWidth = info.widthContent;
            this.PageHeight = info.heightContent;
            this.PageSize = new Size(info.widthContent, info.heightContent);
            //this.Margins = new System.Drawing.Printing.Margins(info.marginLeft, info.marginRight,
            //    info.marginTop, info.marginBottom);
            this.Margins = new System.Drawing.Printing.Margins(2, 2, 2, 2);
            int cellHeight = info.heightContent / totalRowPerPage;
            int cellWidth = info.widthContent / totalColPerNum - 10;

            this.xrTable.Size = new System.Drawing.Size(totalColPerNum * cellWidth, rowNum * cellHeight);
            this.xrTable.Rows.Clear();

            for (int i = 1; i <= rowNum; i++)
            {
                XRTableRow tmpRow = new XRTableRow();
                tmpRow.Name = "Row" + i;
                tmpRow.Height = cellHeight;
                for (int j = 0; j < totalColPerNum; j++)
                {
                    XRTableCell tmpCell = new XRTableCell();
                    tmpCell.Name = "Cell" + i + j;
                    tmpRow.Cells.Add(tmpCell);
                }
                this.xrTable.Rows.Add(tmpRow);
            }
            ((System.ComponentModel.ISupportInitialize)(this.xrTable)).EndInit();

            int currentDataRow = -1;
            ((System.ComponentModel.ISupportInitialize)(this.xrTable)).BeginInit();
            int quantity = 0;
            for (int i = 0; i < rowNum; i++)
            {
                for (int j = 0; j < totalColPerNum; j++)
                {
                    XRTableCell tmpCell = xrTable.Rows[i].Cells[j];
                    if(inKhung)
                        tmpCell.BorderWidth = 1;
                    else
                        tmpCell.BorderWidth = 0;

                    if (quantity == 0)
                    {
                        currentDataRow++;
                        if (this.info.dsProduct.Tables[0].Rows.Count > currentDataRow)
                        {
                            quantity = HelpNumber.ParseInt32(this.info.dsProduct.Tables[0].Rows[currentDataRow][this.info.fieldQuantity]);
                        }
                    }
                    if (this.info.dsProduct.Tables[0].Rows.Count > currentDataRow)
                    {
                        //this.info.GetCellStamp(tmpCell, this.info.dsProduct.Tables[0].Rows[currentDataRow], tmpCell.Left, tmpCell.Top);
                        this.info.GetCellStamp(tmpCell, this.info.dsProduct.Tables[0].Rows[currentDataRow], cellWidth, cellHeight);
                        quantity--;
                    }
                }
            }
            ((System.ComponentModel.ISupportInitialize)(this.xrTable)).EndInit();
        }