예제 #1
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            using (var dbcontext = new Model.Context())
            {
                int           iSelectedGridIndex = dataGridView1.CurrentCell.ColumnIndex;
                int           rowindex           = dataGridView1.CurrentCell.RowIndex;
                int           rowID     = Int32.Parse(dataGridView1.Rows[rowindex].Cells[2].Value.ToString());
                Model.archive model     = dbcontext.Archives.SingleOrDefault(x => x.ID == rowID);
                string        imageName = "";
                if (iSelectedGridIndex == 1)
                {
                    imageName = model.imageName;
                }
                else if (iSelectedGridIndex == 0)
                {
                    Model.tamin tmodel = dbcontext.tamins.SingleOrDefault(x => x.shomareSanad == model.shomareTamin);
                    imageName = tmodel.imageName;
                }

                if (imageName != "")
                {
                    try
                    {
                        var directory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

                        if (Path.GetExtension(imageName) == ".pdf")
                        {
                            try
                            {
                                factorPdf factore = new factorPdf(directory + imageName);
                                factore.Show();
                            }
                            catch (Exception error)
                            {
                                label1.Text = error.InnerException.Message;
                            }
                        }
                        else
                        {
                            factorImage factor = new factorImage(directory + imageName);
                            factor.Show();
                        }
                    }
                    catch (Exception error)
                    {
                    }
                }
            }
        }
예제 #2
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int         iSelectedGridIndex = dataGridView1.CurrentCell.ColumnIndex;
                int         rowindex           = dataGridView1.CurrentCell.RowIndex;
                int         rowID = Int32.Parse(dataGridView1.Rows[rowindex].Cells[2].Value.ToString());
                Model.tamin model = dbcontext.tamins.SingleOrDefault(x => x.ID == rowID);
                if (iSelectedGridIndex == 0)
                {
                    label1.Text      = "بانک تامین";
                    label1.ForeColor = Color.Black;

                    string imageName = model.imageName;
                    if (imageName != "")
                    {
                        var directory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                        try
                        {
                            if (Path.GetExtension(imageName) == ".pdf")
                            {
                                try
                                {
                                    //label1.Text = "takes too far";
                                    factorPdf factore = new factorPdf(directory + imageName);
                                    factore.Show();
                                }
                                catch (Exception error)
                                {
                                    label1.Text = error.InnerException.Message;
                                }
                            }
                            else
                            {
                                factorImage factor = new factorImage(directory + imageName);
                                factor.Show();
                            }
                        }
                        catch (Exception error)
                        {
                            label1.Text = "0000-" + error.InnerException.Message;
                        }
                    }
                }
                else if (iSelectedGridIndex == 1)
                {
                    string  IDsrt  = rowID.ToString();
                    archive rmodel = dbcontext.Archives.SingleOrDefault(x => x.shomareTamin == model.shomareSanad);
                    if (rmodel == null)
                    {
                        dbcontext.tamins.Remove(model);
                        dbcontext.SaveChanges();
                        List <Model.tamin> lst = (from p in dbcontext.tamins
                                                  where p.hesab == "0"
                                                  select p).OrderBy(x => x.ID).ToList();
                        dataGridView1.DataSource = lst;
                    }
                    else
                    {
                        label1.Text      = "تامین مورد نظر دارای فاکتور می باشد";
                        label1.ForeColor = Color.Red;
                    }
                }
            }
            catch (Exception er)
            {
                label1.Text = "111-" + er.InnerException.Message;
            }
        }