示例#1
0
        //Loaded data into Dropdowns
        void loadAllCmbx()
        {
            using (DB_AddressEntities db = new DB_AddressEntities())
            {
                //Land Dropdown
                cmbxCountry.DataSource    = db.Countries.ToList();
                cmbxCountry.ValueMember   = "CountryID";
                cmbxCountry.DisplayMember = "CountryName";
                cmbxCountry.SelectedValue = 0;

                //Stadt Dropdown
                cmbxStadt.DataSource    = db.Stadts.ToList();
                cmbxStadt.ValueMember   = "StadtID";
                cmbxStadt.DisplayMember = "StadtName";
                cmbxStadt.SelectedValue = 0;
            }
        }
示例#2
0
 void deleteEntry()
 {
     if (MessageBox.Show("Sind Sie sicher, dass Sie den Datensatz löschen wollen?", " Adressverwaltung", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         using (DB_AddressEntities db = new DB_AddressEntities())
         {
             var entry = db.Entry(anschriftModel);
             if (entry.State == EntityState.Detached)
             {
                 db.Anschrifts.Attach(anschriftModel);
             }
             db.Anschrifts.Remove(anschriftModel);
             db.SaveChanges();
             clean();
             MessageBox.Show("Delete Succesfully!");
         }
     }
 }
示例#3
0
        /// <summary>
        /// Used to save and update ;
        /// Also checked the duplicate data before Insert and Update a entry.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (initializeDataFields())
            {
                anschriftModel.HashCode = GetHashCode().ToString();
                if (checkDuplicateEntity(GetHashCode().ToString())) //check duplicacy Entry
                {
                    MessageBox.Show("Data Already Exits!");
                }
                else
                {
                    try
                    {
                        using (DB_AddressEntities db = new DB_AddressEntities())
                        {
                            if (anschriftModel.AnschriftID == 0)//Insert
                            {
                                db.Anschrifts.Add(anschriftModel);
                            }
                            else//Update
                            {
                                db.Entry(anschriftModel).State = EntityState.Modified;
                                //string s=getHashCode();
                            }


                            db.SaveChanges();
                        }
                        clean();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        return;
                    }
                    loadGridviewData();
                    MessageBox.Show("Submitted Succesfully!");
                }
            }
        }
示例#4
0
 // Filled the DataGridView from database which has displayed on form.
 void loadGridviewData()
 {
     dgvAddress.AutoGenerateColumns = false;
     using (DB_AddressEntities db = new DB_AddressEntities())
     {
         var query = (from A in db.Anschrifts
                      join C in db.Countries on A.LandId equals C.CountryID
                      join S in db.Stadts on A.StadtId equals S.StadtID
                      select new {
             AnschriftID = A.AnschriftID,
             StraßeName = A.StraßeName,
             WohnungNummer = A.WohnungNummer,
             PLZ = A.PLZ,
             Land = C.CountryName,
             Stadt = S.StadtName,
             StadtId = A.StadtId,
             LandId = A.LandId,
             HashCode = A.HashCode
         }).ToList();
         dgvAddress.DataSource = query;
     }
 }
示例#5
0
        //selecte a Item to Update or Delete from VIEW
        private void dgvAddress_DoubleClick(object sender, EventArgs e)
        {
            if (dgvAddress.CurrentRow.Index != -1)
            {
                btnSave.Enabled            = true;
                anschriftModel.AnschriftID = Convert.ToInt32(dgvAddress.CurrentRow.Cells["AnschriftID"].Value);
                using (DB_AddressEntities db = new DB_AddressEntities())
                {
                    anschriftModel = db.Anschrifts.Where(x => x.AnschriftID == anschriftModel.AnschriftID).FirstOrDefault();

                    txtbxPostCode.Text        = anschriftModel.PLZ;
                    txtbxWohnungNr.Text       = anschriftModel.WohnungNummer;
                    txtbxStreetName.Text      = anschriftModel.StraßeName;
                    cmbxStadt.SelectedValue   = anschriftModel.StadtId;
                    cmbxCountry.SelectedValue = anschriftModel.LandId;

                    //Generate hashValue
                    //int hashcode=GetHashCode();
                }
                btnDelete.Enabled = true;
                btnSave.Text      = "Update";
            }
        }