示例#1
0
        private void MiOgrenciBelgesi_Click(object sender, EventArgs e)
        {
            if (selectedRowIndex != -1)
            {
                SQLQry qryOgrenciBelgesi = new SQLQry();
                qryOgrenciBelgesi.SQLText = "SELECT OGRENCI_BELGESI, OGRENCI_BELGESI_YOLU FROM TBLOGRENCI WHERE REC_ID = " + Convert.ToInt32(grdOgrenciListe.Rows[selectedRowIndex].Cells["grdREC_ID"].Value);
                qryOgrenciBelgesi.Open();
                if (qryOgrenciBelgesi.Found())
                {
                    string belgeStr = qryOgrenciBelgesi.GetString("OGRENCI_BELGESI_YOLU");
                    string uzanti   = "";
                    string belgeAdi = "";

                    for (int i = belgeStr.Length - 1; i > -1; i--)
                    {
                        if (belgeStr[i] == '.')
                        {
                            break;
                        }
                        uzanti += belgeStr[i].ToString();
                    }
                    uzanti   = OgrenciLib.StringReverse(uzanti);
                    uzanti   = uzanti.ToUpper();
                    belgeAdi = DateTime.Now.Ticks.ToString() + "-" + belgeStr;
                    string path = AppDomain.CurrentDomain.BaseDirectory + "\\Belgeler\\" + DateTime.Now.Ticks.ToString();
                    if (imageTypeList.Contains(uzanti))
                    {
                        try
                        {
                            pbOgrenciBelgesi.Image = qryOgrenciBelgesi.GetImage("OGRENCI_BELGESI");
                            if (uzanti == "PNG")
                            {
                                pbOgrenciBelgesi.Image.Save(path + "-img.png", System.Drawing.Imaging.ImageFormat.Png);
                                Process.Start(path + "-img.png");
                            }
                            else
                            {
                                OgrenciBelge form = new OgrenciBelge();
                                form.belge   = pbOgrenciBelgesi.Image;
                                form.ogrenci = grdOgrenciListe.Rows[selectedRowIndex].Cells["grdOGRENCI_ADI"].Value.ToString() + " " + grdOgrenciListe.Rows[selectedRowIndex].Cells["grdOGRENCI_SOYADI"].Value.ToString();
                                form.ShowDialog();
                            }
                        }
                        catch (Exception ex)
                        {
                            MetroFramework.MetroMessageBox.Show(OgrenciLib.mainForm, "Dosya Açılamadı ", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else if (uzanti == "PDF")
                    {
                        try
                        {
                            System.IO.File.WriteAllBytes(path + "-pdf.pdf", qryOgrenciBelgesi.GetBytes("OGRENCI_BELGESI"));
                            Process.Start(path + "-pdf.pdf");
                        }
                        catch (Exception ex)
                        {
                            MetroFramework.MetroMessageBox.Show(OgrenciLib.mainForm, "Dosya Açılamadı", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
        }