Beispiel #1
0
        private void pbSaveClient_Click(object sender, EventArgs e)
        {
            if (newClient)
            {
                Clientss client = new Clientss();
                GetDataFromControls(client);
                if (txtName.Text == "")
                {
                    MessageBox.Show("Complete at least Client Name!", "Atention!", MessageBoxButtons.OK);
                }
                else
                {
                    try
                    {
                        Tables.TblClients.InsertOnSubmit(client);
                        Exacta.Menu.db.SubmitChanges();
                    }
                    catch (Exception err)
                    {
                        MessageBox.Show("There was an error. " + err);
                    }
                    newClient = false;
                }
            }
            else
            {
                if (dgvClients.Rows.Count == 0)
                {
                    return;
                }

                var dialog = MessageBox.Show("Do you want to update Client?", "Client update", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dialog == DialogResult.No)
                {
                    return;
                }

                Clientss client = Exacta.Menu.db.GetTable <Clientss>().SingleOrDefault(cl => cl.Id.ToString() == selectedClient);
                try
                {
                    Articole art = Exacta.Menu.db.GetTable <Articole>().SingleOrDefault(ar => ar.Client == client.Name);
                    if (art != null)
                    {
                        art.Client = txtName.Text;
                    }

                    GetDataFromControls(client);
                    Exacta.Menu.db.SubmitChanges();
                }
                catch (Exception err)
                {
                    MessageBox.Show("There was an error. " + err);
                }
            }

            LoadClients();
            dgvClients.Enabled = true;
            Additional.FillTheFilter(dgvClients, cbClient, 1);
        }
Beispiel #2
0
        private void btn_save_article_Click(object sender, EventArgs e)
        {
            if (_canSaveArt == 0)
            {
                return;
            }

            if (_isNewArticle)
            //insert new record
            {
                try
                {
                    var lQuery = (from art in Tables.TblArticole
                                  where art.Articol == txt_Article.Text
                                  select art).ToList();

                    if (lQuery.Count > 0)
                    {
                        MessageBox.Show("Article already exists");
                        return;
                    }

                    Articole articol = new Articole();
                    articol.Articol    = txt_Article.Text;
                    articol.Descriere  = txt_description_article.Text;
                    articol.Collection = cbCollection.Text;
                    articol.Client     = cbClient.Text;
                    Tables.TblArticole.InsertOnSubmit(articol);

                    Exacta.Menu.db.SubmitChanges();

                    txt_Article.BackColor             = Color.White;
                    txt_description_article.BackColor = Color.White;

                    _isNewArticle = false;
                    btn_add_article_fase.Enabled = true;
                    _canSaveArt = 0;
                }
                catch (Exception ex)
                {
                    _canSaveArt   = 0;
                    _isNewArticle = false;
                    MessageBox.Show(ex.Message);
                }
            }
            else
            //update record
            {
                var dr = MessageBox.Show("Do you want to update " + _selectedArticle + "?", "Article update", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dr == DialogResult.No)
                {
                    return;
                }

                try
                {
                    //var lQuery = (from art in Tables.TblArticole
                    //              where art.Articol == txt_Article.Text
                    //              select art).ToList();

                    //if (lQuery.Count > 0)
                    //    {
                    //    MessageBox.Show("Article already exists");
                    //    return;
                    //    }

                    var lsQuery = (from art in Tables.TblArticole
                                   where art.Id.ToString() == _selectedArticle
                                   select art).SingleOrDefault();

                    Articole articola = Exacta.Menu.db.GetTable <Articole>().SingleOrDefault(arti => arti.Id.ToString() == _selectedArticle);

                    articola.Articol    = txt_Article.Text;
                    articola.Descriere  = txt_description_article.Text;
                    articola.Collection = cbCollection.Text;
                    articola.Client     = cbClient.Text;

                    Exacta.Menu.db.SubmitChanges();
                    _canSaveArt = 0;
                }
                catch (Exception ex)
                {
                    _canSaveArt = 0;
                    MessageBox.Show(ex.ToString());
                }
            }

            LoadArticles();

            var Query = (from art in Tables.TblArticole
                         select art).ToList();

            dgvArticles.Rows[Query.Count - 1].Selected = true;

            btn_save_article.Enabled   = false;
            btn_cancel_article.Enabled = false;
            btn_Add_Article.Enabled    = true;
            btn_Edit_Article.Enabled   = true;
            btn_Delete_Article.Enabled = true;
            dgvArticles.Enabled        = true;
            Additional.FillTheFilter(dgvArticles, cbArticle, 1);
            dgv_FaseArticles.Enabled = true;
            EnableArticleFields(false);
        }
Beispiel #3
0
        private void pbSaveCollection_Click(object sender, EventArgs e)
        {
            if (newCollection)
            {
                if (String.IsNullOrEmpty(txtCollection.Text) || String.IsNullOrEmpty(txtCode.Text))
                {
                    newCollection = false;
                    return;
                }
                Collections collection = new Collections();
                GetDataFromControls(collection);
                if (digit)
                {
                    try
                    {
                        Tables.TblCollections.InsertOnSubmit(collection);
                        Exacta.Menu.db.SubmitChanges();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("The Collection ID aready exists\n Try with another ID.", "Atention!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    newCollection = false;
                }
                else
                {
                    return;
                }
            }
            else
            {
                if (dgvCollection.Rows.Count == 0)
                {
                    return;
                }

                var dialog = MessageBox.Show("Do you want to update Collection?", "Collection update", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dialog == DialogResult.No)
                {
                    return;
                }

                Collections collection = Exacta.Menu.db.GetTable <Collections>().Single(cl => cl.Id.ToString() == selectedCollection);
                try
                {
                    Articole art = Exacta.Menu.db.GetTable <Articole>().SingleOrDefault(ar => ar.Collection == collection.Code);
                    if (art != null)
                    {
                        art.Collection = txtCode.Text;
                    }

                    GetDataFromControls(collection);
                    Exacta.Menu.db.SubmitChanges();
                }
                catch (Exception err)
                {
                    MessageBox.Show("There was an error. " + err);
                }
            }
            LoadCollections();
            dgvCollection.Enabled = true;
            Additional.FillTheFilter(dgvCollection, cbCollection, 1);
        }
Beispiel #4
0
        private void PrintArticlePDF()
        {
            //custom font
            string slnPath = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()));

            slnPath = slnPath + "\\Fonts\\arial.ttf";
            BaseFont arial = BaseFont.CreateFont(slnPath, BaseFont.CP1250, BaseFont.EMBEDDED);

            BaseFont bf = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1250, BaseFont.EMBEDDED);

            iTextSharp.text.Font text = new iTextSharp.text.Font(arial, 10, iTextSharp.text.Font.NORMAL);

            //article table
            PdfPTable articlePdfTable = new PdfPTable(6);

            articlePdfTable.DefaultCell.Padding     = 3;
            articlePdfTable.WidthPercentage         = 100;
            articlePdfTable.HorizontalAlignment     = Element.ALIGN_LEFT;
            articlePdfTable.DefaultCell.BorderWidth = 1;
            articlePdfTable.SpacingAfter            = 30;

            foreach (DataGridViewColumn column in dgvArticles.Columns)
            {
                PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText, text));
                cell.BackgroundColor = new iTextSharp.text.BaseColor(Color.Coral);
                articlePdfTable.AddCell(cell);
            }

            Articole art = Exacta.Menu.db.GetTable <Articole>().SingleOrDefault(a => a.Id.ToString() == _selectedArticle);

            articlePdfTable.DefaultCell.BackgroundColor = new iTextSharp.text.BaseColor(Color.White);
            articlePdfTable.AddCell(new Phrase(art.Id.ToString(), text));
            articlePdfTable.AddCell(new Phrase(art.Articol, text));
            articlePdfTable.AddCell(new Phrase(art.Descriere, text));
            articlePdfTable.AddCell(new Phrase(art.Collection, text));
            articlePdfTable.AddCell(new Phrase(art.Client, text));

            //phase table
            PdfPTable phasePdfTable = new PdfPTable(3);

            phasePdfTable.DefaultCell.Padding     = 3;
            phasePdfTable.WidthPercentage         = 100;
            phasePdfTable.HorizontalAlignment     = Element.ALIGN_LEFT;
            phasePdfTable.DefaultCell.BorderWidth = 1;

            foreach (DataGridViewColumn column in dgv_FaseArticles.Columns)
            {
                PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText, text));
                cell.BackgroundColor = new iTextSharp.text.BaseColor(Color.Coral);
                phasePdfTable.AddCell(cell);
            }

            foreach (DataGridViewRow row in dgv_FaseArticles.Rows)
            {
                foreach (DataGridViewCell cell in row.Cells)
                {
                    phasePdfTable.AddCell(new Phrase(cell.Value.ToString(), text));
                }
            }

            //Main title
            iTextSharp.text.Font titleFont = new iTextSharp.text.Font(arial, 36, iTextSharp.text.Font.NORMAL);
            Paragraph            title     = new Paragraph("Article Report", titleFont);

            title.Alignment    = Element.ALIGN_CENTER;
            title.SpacingAfter = 20;

            //date
            DateTime dateTime = DateTime.Now;

            iTextSharp.text.Font dateTimeFont = new iTextSharp.text.Font(arial, 16, iTextSharp.text.Font.NORMAL);
            Paragraph            date         = new Paragraph("Date: " + dateTime.ToString("dd-MM-yyyy"), dateTimeFont);

            date.Alignment    = Element.ALIGN_RIGHT;
            date.SpacingAfter = 5;
            //dateFont.SetColor(169, 169, 169);

            //time
            Paragraph time = new Paragraph("Time: " + dateTime.ToString("HH:mm:ss"), dateTimeFont);

            time.Alignment    = Element.ALIGN_RIGHT;
            time.SpacingAfter = 30;

            //line separators
            Paragraph sepLine = new Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, iTextSharp.text.BaseColor.BLACK, Element.ALIGN_LEFT, 1)));

            sepLine.SpacingAfter = -10;
            Paragraph sepLine2 = new Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, iTextSharp.text.BaseColor.BLACK, Element.ALIGN_LEFT, 1)));

            sepLine2.SpacingAfter = 40;

            //signature
            iTextSharp.text.Font footFont  = new iTextSharp.text.Font(arial, 16, iTextSharp.text.Font.NORMAL);
            Paragraph            signature = new Paragraph("E X A C T A", footFont);

            signature.Alignment    = Element.ALIGN_LEFT;
            signature.SpacingAfter = 30;

            //title2
            iTextSharp.text.Font titFont = new iTextSharp.text.Font(arial, 26, iTextSharp.text.Font.NORMAL);
            Paragraph            tit     = new Paragraph("Phases For Current Article", titFont);

            tit.Alignment    = Element.ALIGN_CENTER;
            tit.SpacingAfter = 40;

            var sfd = new SaveFileDialog();

            sfd.FileName   = "Article" + art.Id.ToString();
            sfd.DefaultExt = ".pdf";
            sfd.Filter     = "PDF(*.pdf)|*.pdf";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                using (FileStream fs = new FileStream(sfd.FileName, FileMode.Create))
                {
                    Document doc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
                    PdfWriter.GetInstance(doc, fs);

                    doc.Open();
                    doc.Add(signature);
                    doc.Add(title);
                    doc.Add(date);
                    doc.Add(time);
                    doc.Add(sepLine);
                    doc.Add(sepLine2);
                    doc.Add(articlePdfTable);
                    doc.Add(tit);
                    doc.Add(phasePdfTable);
                    doc.Close();
                    fs.Close();
                }
                sfd.Dispose();
            }
        }