Beispiel #1
0
 /// <summary>
 /// Function to insert values to BarcodeSettings table
 /// </summary>
 /// <param name="barcodesettingsinfo"></param>
 public void BarcodeSettingsAdd(BarcodeSettingsInfo barcodesettingsinfo)
 {
     try
     {
         if (sqlcon.State == ConnectionState.Closed)
         {
             sqlcon.Open();
         }
         SqlCommand sccmd = new SqlCommand("BarcodeSettingsAddorEdit", sqlcon);
         sccmd.CommandType = CommandType.StoredProcedure;
         SqlParameter sprmparam = new SqlParameter();
         sprmparam       = sccmd.Parameters.Add("@showProductCode", SqlDbType.Bit);
         sprmparam.Value = barcodesettingsinfo.ShowProductCode;
         sprmparam       = sccmd.Parameters.Add("@showCompanyName", SqlDbType.Bit);
         sprmparam.Value = barcodesettingsinfo.ShowCompanyName;
         sprmparam       = sccmd.Parameters.Add("@companyName", SqlDbType.VarChar);
         sprmparam.Value = barcodesettingsinfo.CompanyName;
         sprmparam       = sccmd.Parameters.Add("@showPurchaseRate", SqlDbType.Bit);
         sprmparam.Value = barcodesettingsinfo.ShowPurchaseRate;
         sprmparam       = sccmd.Parameters.Add("@showMRP", SqlDbType.Bit);
         sprmparam.Value = barcodesettingsinfo.ShowMRP;
         sprmparam       = sccmd.Parameters.Add("@point", SqlDbType.VarChar);
         sprmparam.Value = barcodesettingsinfo.Point;
         sprmparam       = sccmd.Parameters.Add("@zero", SqlDbType.VarChar);
         sprmparam.Value = barcodesettingsinfo.Zero;
         sprmparam       = sccmd.Parameters.Add("@one", SqlDbType.VarChar);
         sprmparam.Value = barcodesettingsinfo.One;
         sprmparam       = sccmd.Parameters.Add("@two", SqlDbType.VarChar);
         sprmparam.Value = barcodesettingsinfo.Two;
         sprmparam       = sccmd.Parameters.Add("@three", SqlDbType.VarChar);
         sprmparam.Value = barcodesettingsinfo.Three;
         sprmparam       = sccmd.Parameters.Add("@four", SqlDbType.VarChar);
         sprmparam.Value = barcodesettingsinfo.Four;
         sprmparam       = sccmd.Parameters.Add("@five", SqlDbType.VarChar);
         sprmparam.Value = barcodesettingsinfo.Five;
         sprmparam       = sccmd.Parameters.Add("@six", SqlDbType.VarChar);
         sprmparam.Value = barcodesettingsinfo.Six;
         sprmparam       = sccmd.Parameters.Add("@seven", SqlDbType.VarChar);
         sprmparam.Value = barcodesettingsinfo.Seven;
         sprmparam       = sccmd.Parameters.Add("@eight", SqlDbType.VarChar);
         sprmparam.Value = barcodesettingsinfo.Eight;
         sprmparam       = sccmd.Parameters.Add("@nine", SqlDbType.VarChar);
         sprmparam.Value = barcodesettingsinfo.Nine;
         sprmparam       = sccmd.Parameters.Add("@extra1", SqlDbType.VarChar);
         sprmparam.Value = barcodesettingsinfo.Extra1;
         sprmparam       = sccmd.Parameters.Add("@extra2", SqlDbType.VarChar);
         sprmparam.Value = barcodesettingsinfo.Extra2;
         sccmd.ExecuteNonQuery();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
     finally
     {
         sqlcon.Close();
     }
 }
Beispiel #2
0
 /// <summary>
 /// Save Or Edit Function
 /// </summary>
 public void SaveOrEdit()
 {
     try
     {
         bool isOk = true;
         if (cbxShowCompanyNAmeAs.Checked && txtShowCompanyName.Text.Trim() == string.Empty)
         {
             MessageBox.Show("Enter company code", "Oneaccount", MessageBoxButtons.OK, MessageBoxIcon.Information);
             txtShowCompanyName.Focus();
             isOk = false;
         }
         else if ((cbxShowPurchaseRate.Checked && CheckGroupBox()) || (!cbxShowPurchaseRate.Checked))
         {
             if (PublicVariables.isMessageAdd)
             {
                 if (Messages.SaveMessage())
                 {
                     isOk = true;
                 }
                 else
                 {
                     isOk = false;
                 }
             }
             if (isOk)
             {
                 BarcodeSettingsInfo InfoSettings = new BarcodeSettingsInfo();
                 InfoSettings.ShowMRP          = cbxShowMrp.Checked;
                 InfoSettings.ShowProductCode  = rbtnShowProductCode.Checked;
                 InfoSettings.ShowCompanyName  = cbxShowCompanyNAmeAs.Checked;
                 InfoSettings.ShowPurchaseRate = cbxShowPurchaseRate.Checked;
                 InfoSettings.CompanyName      = txtShowCompanyName.Text.Trim();
                 InfoSettings.Zero             = txtZero.Text.Trim();
                 InfoSettings.One    = txtOne.Text.Trim();
                 InfoSettings.Two    = txtTwo.Text.Trim();
                 InfoSettings.Three  = txtThree.Text.Trim();
                 InfoSettings.Four   = txtFour.Text.Trim();
                 InfoSettings.Five   = txtFive.Text.Trim();
                 InfoSettings.Six    = txtSix.Text.Trim();
                 InfoSettings.Seven  = txtSeven.Text.Trim();
                 InfoSettings.Eight  = txtEight.Text.Trim();
                 InfoSettings.Nine   = txtNine.Text.Trim();
                 InfoSettings.Point  = txtPoint.Text.Trim();
                 InfoSettings.Extra1 = string.Empty;
                 InfoSettings.Extra2 = string.Empty;
                 BarcodeSettingsSP spbarcodesetting = new BarcodeSettingsSP();
                 spbarcodesetting.BarcodeSettingsAdd(InfoSettings);
                 Messages.SavedMessage();
                 this.Close();
             }
         }
     }
     catch (Exception ex)
     {
         formMDI.infoError.ErrorString = "BS5:" + ex.Message;
     }
 }
Beispiel #3
0
        /// <summary>
        /// Function to view particular values based on parameter
        /// </summary>
        /// <param name="barcodeSettingsId"></param>
        /// <returns></returns>
        public BarcodeSettingsInfo BarcodeSettingsView(decimal barcodeSettingsId)
        {
            BarcodeSettingsInfo barcodesettingsinfo = new BarcodeSettingsInfo();
            SqlDataReader       sdrreader           = null;

            try
            {
                if (sqlcon.State == ConnectionState.Closed)
                {
                    sqlcon.Open();
                }
                SqlCommand sccmd = new SqlCommand("BarcodeSettingsView", sqlcon);
                sccmd.CommandType = CommandType.StoredProcedure;
                SqlParameter sprmparam = new SqlParameter();
                sprmparam       = sccmd.Parameters.Add("@barcodeSettingsId", SqlDbType.Decimal);
                sprmparam.Value = barcodeSettingsId;
                sdrreader       = sccmd.ExecuteReader();
                while (sdrreader.Read())
                {
                    barcodesettingsinfo.BarcodeSettingsId = decimal.Parse(sdrreader[0].ToString());
                    barcodesettingsinfo.ShowProductCode   = bool.Parse(sdrreader[1].ToString());
                    barcodesettingsinfo.ShowCompanyName   = bool.Parse(sdrreader[2].ToString());
                    barcodesettingsinfo.CompanyName       = sdrreader[3].ToString();
                    barcodesettingsinfo.ShowPurchaseRate  = bool.Parse(sdrreader[4].ToString());
                    barcodesettingsinfo.ShowMRP           = bool.Parse(sdrreader[5].ToString());
                    barcodesettingsinfo.Point             = sdrreader[6].ToString();
                    barcodesettingsinfo.Zero      = sdrreader[7].ToString();
                    barcodesettingsinfo.One       = sdrreader[8].ToString();
                    barcodesettingsinfo.Two       = sdrreader[9].ToString();
                    barcodesettingsinfo.Three     = sdrreader[10].ToString();
                    barcodesettingsinfo.Four      = sdrreader[11].ToString();
                    barcodesettingsinfo.Five      = sdrreader[12].ToString();
                    barcodesettingsinfo.Six       = sdrreader[13].ToString();
                    barcodesettingsinfo.Seven     = sdrreader[14].ToString();
                    barcodesettingsinfo.Eight     = sdrreader[15].ToString();
                    barcodesettingsinfo.Nine      = sdrreader[16].ToString();
                    barcodesettingsinfo.Extra1    = sdrreader[17].ToString();
                    barcodesettingsinfo.Extra2    = sdrreader[18].ToString();
                    barcodesettingsinfo.ExtraDate = DateTime.Parse(sdrreader[19].ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                sdrreader.Close();
                sqlcon.Close();
            }
            return(barcodesettingsinfo);
        }
Beispiel #4
0
        /// <summary>
        /// ExportToThermalPrinter
        /// </summary>
        public void ExportToPDFforThermalPrinter()
        {
            iTextSharp.text.Document pdfdoc = new iTextSharp.text.Document();
            try
            {
                DirectoryInfo dir1 = new DirectoryInfo(Application.StartupPath + "\\Barcode");
                if (!Directory.Exists(Application.StartupPath + "\\Barcode"))
                {
                    dir1.Create();
                }
                if (File.Exists(Application.StartupPath + "\\Barcode\\Barcode.pdf"))
                {
                    File.Delete(Application.StartupPath + "\\Barcode\\Barcode.pdf");
                }
                iTextSharp.text.Rectangle pgSize = new iTextSharp.text.Rectangle(227, 65);
                pdfdoc = new Document(pgSize, 6, 6, 0, 0);
                PdfWriter writer         = PdfWriter.GetInstance(pdfdoc, new FileStream(Application.StartupPath + "\\Barcode\\Barcode.pdf", FileMode.Create));
                PdfPTable tbl            = new PdfPTable(2);
                float[]   fltParentWidth = new float[] { 108f, 108f };
                tbl.TotalWidth  = 216;
                tbl.LockedWidth = true;
                tbl.SetWidths(fltParentWidth);
                tbl.DefaultCell.FixedHeight         = 57;
                tbl.DefaultCell.Border              = iTextSharp.text.Rectangle.NO_BORDER;
                tbl.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
                tbl.DefaultCell.VerticalAlignment   = Element.ALIGN_MIDDLE;
                pdfdoc.Open();
                int intotalCount         = 0;
                BarcodeSettingsInfo Info = new BarcodeSettingsInfo();
                SettingsSP          Sp   = new SettingsSP();
                Info = spBarcodeSettings.BarcodeSettingsViewForBarCodePrinting();
                for (int i = 0; i < dgvBarcodePrinting.Rows.Count; i++)
                {
                    if (dgvBarcodePrinting.Rows[i].Cells["dgvProductCode"].Value != null && dgvBarcodePrinting.Rows[i].Cells["dgvProductCode"].Value.ToString() != string.Empty)
                    {
                        int inCopies = 0;
                        if (dgvBarcodePrinting.Rows[i].Cells["dgvCopies"].Value != null)
                        {
                            int.TryParse(dgvBarcodePrinting.Rows[i].Cells["dgvCopies"].Value.ToString(), out inCopies);
                        }
                        for (int j = 0; j < inCopies; j++)
                        {
                            string strCode        = dgvBarcodePrinting.Rows[i].Cells["dgvProductCode"].Value.ToString();
                            string strCompanyName = string.Empty;
                            if (Info.ShowCompanyName)
                            {
                                strCompanyName = Info.CompanyName;
                            }
                            string strProductCode = string.Empty;
                            if (Info.ShowProductCode)
                            {
                                strProductCode = strCode;
                            }
                            else
                            {
                                strProductCode = dgvBarcodePrinting.Rows[i].Cells["dgvproductName"].Value.ToString();
                            }

                            string strMRP = string.Empty;
                            if (Info.ShowMRP)
                            {
                                strMRP = new CurrencySP().CurrencyView(PublicVariables._decCurrencyId).CurrencySymbol + ": " + dgvBarcodePrinting.Rows[i].Cells["dgvMRP"].Value.ToString();
                            }

                            string strSecretPurchaseRateCode = string.Empty;
                            if (Info.ShowPurchaseRate)
                            {
                                string strPurchaseRate = dgvBarcodePrinting.Rows[i].Cells["dgvPurchaseRate"].Value.ToString();

                                if (strPurchaseRate.Contains("."))
                                {
                                    strPurchaseRate = strPurchaseRate.TrimEnd('0');
                                    if (strPurchaseRate[strPurchaseRate.Length - 1] == '.')
                                    {
                                        strPurchaseRate = strPurchaseRate.Replace(".", "");
                                    }
                                }
                                for (int k = 0; k < strPurchaseRate.Length; k++)
                                {
                                    switch (strPurchaseRate[k])
                                    {
                                    case '0':
                                        strSecretPurchaseRateCode += Info.Zero;
                                        break;

                                    case '1':
                                        strSecretPurchaseRateCode += Info.One;
                                        break;

                                    case '2':
                                        strSecretPurchaseRateCode += Info.Two;
                                        break;

                                    case '3':
                                        strSecretPurchaseRateCode += Info.Three;
                                        break;

                                    case '4':
                                        strSecretPurchaseRateCode += Info.Four;
                                        break;

                                    case '5':
                                        strSecretPurchaseRateCode += Info.Five;
                                        break;

                                    case '6':
                                        strSecretPurchaseRateCode += Info.Six;
                                        break;

                                    case '7':
                                        strSecretPurchaseRateCode += Info.Seven;
                                        break;

                                    case '8':
                                        strSecretPurchaseRateCode += Info.Eight;
                                        break;

                                    case '9':
                                        strSecretPurchaseRateCode += Info.Nine;
                                        break;

                                    case '.':
                                        strSecretPurchaseRateCode += Info.Point;
                                        break;
                                    }
                                }
                            }

                            PdfContentByte pdfcb   = writer.DirectContent;
                            Barcode128     code128 = new Barcode128();
                            code128.Code          = strCode;
                            code128.Extended      = false;
                            code128.CodeType      = iTextSharp.text.pdf.Barcode.CODE128;
                            code128.AltText       = strProductCode;
                            code128.BarHeight     = 16;
                            code128.Size          = 9;
                            code128.Baseline      = 9;
                            code128.TextAlignment = Element.ALIGN_CENTER;
                            iTextSharp.text.Image image128 = code128.CreateImageWithBarcode(pdfcb, null, null);
                            Phrase phrase = new Phrase();

                            phrase.Add(new Chunk(strCompanyName, new iTextSharp.text.Font(-1, 9, iTextSharp.text.Font.BOLD)));
                            phrase.Add(new Chunk(Environment.NewLine + Environment.NewLine, new iTextSharp.text.Font(-1, 4)));
                            PdfPCell cell = new PdfPCell(phrase);
                            cell.HorizontalAlignment = Element.ALIGN_CENTER;
                            cell.VerticalAlignment   = Element.ALIGN_MIDDLE;
                            cell.Border = iTextSharp.text.Rectangle.NO_BORDER;
                            phrase.Add(new Chunk(image128, 0, 0));
                            phrase.Add(new Chunk(Environment.NewLine, new iTextSharp.text.Font(-1, 4)));
                            phrase.Add(new Chunk(strMRP, new iTextSharp.text.Font(-1, 8)));
                            phrase.Add(new Chunk(Environment.NewLine + strSecretPurchaseRateCode, new iTextSharp.text.Font(-1, 7)));
                            phrase.Add(new Chunk(Environment.NewLine + Environment.NewLine, new iTextSharp.text.Font(-1, 1.2f)));
                            tbl.AddCell(cell);
                            intotalCount++;
                        }
                    }
                }
                int reminder = intotalCount % 2;
                if (reminder != 0)
                {
                    for (int i = reminder; i < 2; ++i)
                    {
                        tbl.AddCell("");
                    }
                }
                if (tbl.Rows.Count != 0)
                {
                    pdfdoc.Add(tbl);
                    pdfdoc.Close();
                    System.Diagnostics.Process.Start(Application.StartupPath + "\\Barcode\\Barcode.pdf");
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("The process cannot access the file") && ex.Message.Contains("Barcode.pdf' because it is being used by another process."))
                {
                    MessageBox.Show("Close the PDF file and try again", "Oneaccount", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    formMDI.infoError.ErrorString = "BCP5:" + ex.Message;
                }
            }
            finally
            {
                try
                {
                    pdfdoc.Close();
                }
                catch
                {
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Export the Barcodes to PDF format here
        /// </summary>
        public void ExportToPDF()
        {
            iTextSharp.text.Document pdfdoc = new iTextSharp.text.Document();
            try
            {
                DirectoryInfo dir1 = new DirectoryInfo(Application.StartupPath + "\\Barcode");
                if (!Directory.Exists(Application.StartupPath + "\\Barcode"))
                {
                    dir1.Create();
                }
                if (File.Exists(Application.StartupPath + "\\Barcode\\Barcode.pdf"))
                {
                    File.Delete(Application.StartupPath + "\\Barcode\\Barcode.pdf");
                }
                pdfdoc = new Document(PageSize.A4, 12, 1, 20, 20);
                PdfWriter writer = PdfWriter.GetInstance(pdfdoc, new FileStream(Application.StartupPath + "\\Barcode\\Barcode.pdf", FileMode.Create));
                PdfPTable tbl    = new PdfPTable(5); // assigning 5 columns to pdf
                tbl.WidthPercentage    = 100;
                tbl.DefaultCell.Border = iTextSharp.text.Rectangle.NO_BORDER;
                tbl.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
                tbl.DefaultCell.VerticalAlignment   = Element.ALIGN_MIDDLE;
                pdfdoc.Open();
                int intotalCount         = 0;
                BarcodeSettingsInfo Info = new BarcodeSettingsInfo();
                Info = spBarcodeSettings.BarcodeSettingsViewForBarCodePrinting();
                for (int i = 0; i < dgvBarcodePrinting.Rows.Count; i++) // iterating grid to take each product
                {
                    if (dgvBarcodePrinting.Rows[i].Cells["dgvProductCode"].Value != null && dgvBarcodePrinting.Rows[i].Cells["dgvProductCode"].Value.ToString() != "")
                    {
                        int inCopies = 0;
                        if (dgvBarcodePrinting.Rows[i].Cells["dgvCopies"].Value != null)
                        {
                            int.TryParse(dgvBarcodePrinting.Rows[i].Cells["dgvCopies"].Value.ToString(), out inCopies); // number of copies of arcode to be printed
                        }
                        for (int j = 0; j < inCopies; j++)
                        {
                            string strCode = dgvBarcodePrinting.Rows[i].Cells["dgvBarcode"].Value.ToString();
                            // checking settings----------------------------------------------------------------------------------------------------------

                            string strCompanyName = " ";
                            if (Info.ShowCompanyName)
                            {
                                strCompanyName = Info.CompanyName;
                            }
                            //-----------------------------------
                            string strProductCode = " ";
                            if (Info.ShowProductCode)
                            {
                                strProductCode = strCode;
                            }
                            else
                            {
                                strProductCode = dgvBarcodePrinting.Rows[i].Cells["dgvproductName"].Value.ToString();
                            }
                            //-----------------------------------
                            string strMRP = " ";
                            if (Info.ShowMRP)
                            {
                                strMRP = new CurrencySP().CurrencyView(PublicVariables._decCurrencyId).CurrencySymbol + ": " + dgvBarcodePrinting.Rows[i].Cells["dgvMRP"].Value.ToString();
                            }
                            //-----------------------------------
                            string strSecretPurchaseRateCode = " ";
                            if (Info.ShowPurchaseRate)
                            {
                                string strPurchaseRate = dgvBarcodePrinting.Rows[i].Cells["dgvPurchaseRate"].Value.ToString();
                                //converting to secret code
                                if (strPurchaseRate.Contains("."))
                                {
                                    strPurchaseRate = strPurchaseRate.TrimEnd('0');
                                    if (strPurchaseRate[strPurchaseRate.Length - 1] == '.')
                                    {
                                        strPurchaseRate = strPurchaseRate.Replace(".", "");
                                    }
                                }
                                for (int k = 0; k < strPurchaseRate.Length; k++)
                                {
                                    switch (strPurchaseRate[k])
                                    {
                                    case '0':
                                        strSecretPurchaseRateCode += Info.Zero;
                                        break;

                                    case '1':
                                        strSecretPurchaseRateCode += Info.One;
                                        break;

                                    case '2':
                                        strSecretPurchaseRateCode += Info.Two;
                                        break;

                                    case '3':
                                        strSecretPurchaseRateCode += Info.Three;
                                        break;

                                    case '4':
                                        strSecretPurchaseRateCode += Info.Four;
                                        break;

                                    case '5':
                                        strSecretPurchaseRateCode += Info.Five;
                                        break;

                                    case '6':
                                        strSecretPurchaseRateCode += Info.Six;
                                        break;

                                    case '7':
                                        strSecretPurchaseRateCode += Info.Seven;
                                        break;

                                    case '8':
                                        strSecretPurchaseRateCode += Info.Eight;
                                        break;

                                    case '9':
                                        strSecretPurchaseRateCode += Info.Nine;
                                        break;

                                    case '.':
                                        strSecretPurchaseRateCode += Info.Point;
                                        break;
                                    }
                                }
                            }

                            // generating and assigning barcode to PDF

                            PdfContentByte pdfcb   = writer.DirectContent;
                            Barcode128     code128 = new Barcode128();
                            code128.Code          = strCode;
                            code128.Extended      = false;
                            code128.CodeType      = iTextSharp.text.pdf.Barcode.CODE128;
                            code128.AltText       = strProductCode;
                            code128.BarHeight     = 13;
                            code128.Size          = 6;
                            code128.Baseline      = 8;
                            code128.TextAlignment = Element.ALIGN_CENTER;
                            iTextSharp.text.Image image128 = code128.CreateImageWithBarcode(pdfcb, null, null);


                            Phrase phrase = new Phrase();
                            phrase.Font.Size = 8;
                            phrase.Add(new Chunk(strCompanyName + Environment.NewLine + Environment.NewLine));
                            PdfPCell cell = new PdfPCell(phrase);
                            cell.FixedHeight         = 61.69f;
                            cell.HorizontalAlignment = Element.ALIGN_CENTER;
                            cell.VerticalAlignment   = Element.ALIGN_MIDDLE;
                            cell.Border = iTextSharp.text.Rectangle.NO_BORDER;
                            phrase.Add(new Chunk(image128, 0, 0));
                            phrase.Add(new Chunk(Environment.NewLine + strMRP));
                            phrase.Add(new Chunk(Environment.NewLine + strSecretPurchaseRateCode));
                            tbl.AddCell(cell);
                            intotalCount++; // getting total number of barcode generated
                        }
                    }
                }
                // so we assign a null values to reaming columns
                int reminder = intotalCount % 5;
                if (reminder != 0)
                {
                    for (int i = reminder; i < 5; ++i)
                    {
                        tbl.AddCell("");
                    }
                }
                if (tbl.Rows.Count != 0)
                {
                    pdfdoc.Add(tbl);
                    pdfdoc.Close();
                    System.Diagnostics.Process.Start(Application.StartupPath + "\\Barcode\\Barcode.pdf");
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("The process cannot access the file") && ex.Message.Contains("Barcode.pdf' because it is being used by another process."))
                {
                    MessageBox.Show("Close the PDF file and try again", "Oneaccount", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("BCD4:" + ex.Message, "Oneaccount", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            finally
            {
                try
                {
                    pdfdoc.Close();
                }
                catch
                {
                }
            }
        }