Exemple #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (doc_file_name[0] != "" && file_name != "")
            {
                try
                {
                    string appPath         = Path.GetDirectoryName(Application.ExecutablePath) + @"\docs\"; // <---
                    string appPath_profile = Path.GetDirectoryName(Application.ExecutablePath) + @"\allotteeProfile\";
                    string ext             = Path.GetExtension(file_name);
                    string pic_name        = Guid.NewGuid().ToString() + ext;


                    try
                    {
                        db = new giedaEntities();
                        long   num;
                        string nic = nic_textBox.Text;
                        num = long.Parse(nic);
                        var addAllottee = new allottee()
                        {
                            name        = txtName.Text,
                            father_name = txtFname.Text,
                            address     = txtAddress.Text,
                            city        = txtCity.Text,
                            province    = txtProvince.Text,
                            domicile    = txtDomicile.Text,
                            pds_number  = txtPdsNumber.Text,
                            nic         = num,
                            af_number   = txtAfNumber.Text,
                            picture     = pic_name,
                            created_at  = DateTime.Now,
                            updated_at  = DateTime.Now
                        };
                        db.allottees.Add(addAllottee);

                        db.SaveChanges();
                        File.Copy(file_path, appPath_profile + pic_name);
                        int id = addAllottee.id;
                        for (int i = 0; i < doc_file_path.Length; i++)
                        {
                            string extt     = Path.GetExtension(doc_file_name[i]);
                            string doc_name = Guid.NewGuid().ToString() + ext;
                            db = new giedaEntities();
                            allottee_documents allotteeDocuments = new allottee_documents()
                            {
                                title      = "Allottee Document",
                                document   = doc_name,
                                allotee_id = id,
                                created_at = DateTime.Now,
                                updated_at = DateTime.Now
                            };

                            db.allottee_documents.Add(allotteeDocuments);
                            db.SaveChanges();
                        }
                        db = new giedaEntities();
                        var allotteePlot = new allotee_plots()
                        {
                            allottee_id = id,
                            plot_id     = Int32.Parse(txtPlot.SelectedValue.ToString())
                        };
                        db.allotee_plots.Add(allotteePlot);
                        db.SaveChanges();



                        MessageBox.Show("Record inserted Successfully");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Invalid action " + ex.Message);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Invalid action " + ex.Message);
                }
            }
            else
            {
                MessageBox.Show("Kindly Upload image or documents");
            }
        }
Exemple #2
0
        private void btn_Submit_Click(object sender, EventArgs e)
        {
            int user_id = 0;

            if (txtPdsNo.Text == "")
            {
                MessageBox.Show("Kindly Enter a Pds Number");
            }
            else
            {
                con = new Logic.connection();
                con.Select("select id from allottees where pds_number=" + Int32.Parse(txtPdsNo.Text));
                DataTable dt = new DataTable();
                con.sda.Fill(dt);

                foreach (DataRow row in dt.Rows)
                {
                    user_id = Int32.Parse(row["id"].ToString());
                }


                if (user_id == 0)
                {
                    MessageBox.Show("Kindly enter a valid pds Number");
                }
                else
                {
                    try
                    {
                        string pic_name = "";
                        for (int i = 0; i < file_names.Length; i++)
                        {
                            string appPath = Path.GetDirectoryName(Application.ExecutablePath) + @"\docs\";

                            string ext = Path.GetExtension(file_names[i]);
                            pic_name = Guid.NewGuid().ToString() + ext;
                            File.Copy(file_paths[i], appPath + pic_name);
                            string query = "INSERT INTO allottee_documents  (title, [document], allotee_id, created_at,updated_at) VALUES('Allottee Document', '" + pic_name + "'," + user_id + "," + DateTime.Now + "," + DateTime.Now + ")";


                            db = new giedaEntities();
                            allottee_documents allotteeDocuments = new allottee_documents()
                            {
                                title      = "Allottee Document",
                                document   = pic_name,
                                allotee_id = user_id,
                                created_at = DateTime.Now,
                                updated_at = DateTime.Now
                            };

                            db.allottee_documents.Add(allotteeDocuments);
                            db.SaveChanges();
                        }



                        if (pic_name != "")
                        {
                            MessageBox.Show("Docs Uploaded");
                        }
                        else
                        {
                            MessageBox.Show("No Image Selected");
                        }
                    }
                    catch (Exception ee)
                    {
                        MessageBox.Show("Error: " + ee.Message);
                    }
                }
            }
        }