Esempio n. 1
0
        private void YesOrNo_onBtnClick(object sender, bool e)
        {
            this.Enabled = true;
            Form f = (Form)sender;

            //this.Close();
            if (e)
            {
                using (var eb = new EBarangayEntities())
                {
                    var c = eb.Citizens.FirstOrDefault(x => x.IdNumber == IDTxt.Text);

                    //foreach (var rec in c.Records.ToArray())
                    //    eb.Records.Remove(rec);
                    var instances = eb.CitizenToComplaints.Where(x => x.Citizen.IdNumber == IDTxt.Text);
                    foreach (var i in instances)
                    {
                        eb.CitizenToComplaints.Remove(i);
                    }
                    eb.Citizens.Remove(c);

                    eb.SaveChanges();

                    f.Close();

                    MessageBox.Show("successfully deleted Entry with id(" + IDTxt.Text + ")");
                    OnRecordDeleted?.Invoke(this, new EventArgs());
                    this.Close();
                }
            }
            ///throw new NotImplementedException();
        }
        void connectComplaintToCitizen(Complaint comp, DataGridView dgv)
        {
            using (var ent = new EBarangayEntities())
            {
                for (int i = 0; i < dgv.RowCount; i++)
                {
                    if (dgv.Rows[i].Cells[0].Value != null)
                    {
                        string  id = dgv.Rows[i].Cells[1].Value.ToString();
                        Citizen c  = ent.Citizens.FirstOrDefault(x => x.IdNumber == id);
                        if (c != null)
                        {
                            //c.RefRecords += (string.IsNullOrEmpty(c.RefRecords)) ? controlNumber : "," + controlNumber;
                            CitizenToComplaint cc = new CitizenToComplaint();
                            //cc.Id = 1;
                            cc.ComplaintId = comp.ID;
                            cc.Citizen     = c;

                            ent.CitizenToComplaints.Add(cc);
                        }
                    }
                }
                ent.SaveChanges();
            }
        }
Esempio n. 3
0
 private void areaTable_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
     using (var p = new EBarangayEntities())
     {
         var t = p.Areas.FirstOrDefault(x => x.ID == targetId);
         t.Name = areaTable.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
         p.SaveChanges();
     }
 }
Esempio n. 4
0
 private void settleSched_ValueChanged(object sender, EventArgs e)
 {
     using (var eb = new EBarangayEntities())
     {
         var id = Convert.ToInt32(controlNumberField.Text);
         var c  = eb.Complaints.FirstOrDefault(x => x.ID == id);
         c.SettlementDate = settleSched.Value;
         eb.SaveChanges();
     }
     OnComplaintChanges?.Invoke(this, new EventArgs());
 }
Esempio n. 5
0
        void registerCitizen()
        {
            using (var eb = new EBarangayEntities())
            {
                var c = eb.Citizens.FirstOrDefault(x => x.IdNumber == Id.Text);
                if (c != null)
                {
                    MessageBox.Show("Id is already taken.");
                    return;
                }
                Citizen citizen = new Citizen();

                var a = eb.Areas.FirstOrDefault(x => x.Name == area.Text);
                citizen.Area = a;

                citizen.Picture = Class.ImageConverter.imageToByteArray(picBox.Image);

                citizen.IdNumber   = Id.Text;
                citizen.FirstName  = firstName.Text;
                citizen.MiddleName = middleName.Text;
                citizen.LastName   = lastName.Text;
                citizen.Extension  = extensionName.Text;

                citizen.Address     = address.Text;
                citizen.Birthday    = birthdate.Value;
                citizen.Gender      = sex.Text;
                citizen.ContactInfo = contact.Text;
                citizen.CivilStatus = civilStatus.Text;

                citizen.SpouseName  = !string.IsNullOrEmpty(spouseName.Text) ? spouseName.Text : null;
                citizen.FathersName = !string.IsNullOrEmpty(fathersName.Text) ? fathersName.Text : null;
                citizen.MothersName = !string.IsNullOrEmpty(mothersName.Text) ? mothersName.Text : null;

                citizen.Indigent      = indigent.Checked;
                citizen.Student       = student.Checked;
                citizen.PWD           = pwd.Checked;
                citizen.SeniorCitizen = senior.Checked;

                citizen.SSS            = !string.IsNullOrEmpty(sss.Text) ? sss.Text : null;
                citizen.Philhealth     = !string.IsNullOrEmpty(philhealth.Text) ? philhealth.Text : null;
                citizen.PagIbig        = !string.IsNullOrEmpty(pagibig.Text) ? pagibig.Text : null;
                citizen.VoterID        = !string.IsNullOrEmpty(votersId.Text) ? votersId.Text : null;
                citizen.PrecinctNumber = !string.IsNullOrEmpty(precinctNumber.Text) ? precinctNumber.Text : null;

                eb.Citizens.Add(citizen);
                eb.SaveChanges();
            }
        }
Esempio n. 6
0
 void save(params Control[] control)
 {
     using (var eb = new EBarangayEntities())
     {
         for (int i = 0; i < officialsMarker.Length; i++)
         {
             if (officialsMarker[i].save)
             {
                 int id = officialsMarker[i].Id;
                 var o  = eb.Officials.FirstOrDefault(x => x.ID == id);
                 o.Name = control[i].Text;
             }
         }
         eb.SaveChanges();
     }
     MessageBox.Show("Edit Successful.");
 }
Esempio n. 7
0
        void markAsDone()
        {
            using (var eb = new EBarangayEntities())
            {
                var rec = eb.Complaints.FirstOrDefault(r => r.ID == currRec.ID);
                if (rec == null)
                {
                    MessageBox.Show("error in changing");
                    return;
                }
                if (rec.Status == ComplaintStatus.Settled.ToString())
                {
                    return;
                }

                rec.Status = "Settled";
                eb.SaveChanges();
                OnComplaintChanges?.Invoke(this, new EventArgs());
            }
        }
Esempio n. 8
0
        protected override void SaveToDatabase()
        {
            using (var eb = new EBarangayEntities())
            {
                var citizen = eb.Citizens.FirstOrDefault(x => x.IdNumber == idField.Text);
                if (citizen == null)
                {
                    MessageBox.Show("Document not saved in citizen");
                    return;
                }

                var newDocument = new Document();
                newDocument.Citizen       = citizen;
                newDocument.DocumentTitle = this.Text;
                newDocument.DateIssued    = DateTime.Now;
                newDocument.ControlNumber = Guid.NewGuid().ToString();
                eb.Documents.Add(newDocument);
                eb.SaveChanges();
            }
        }
Esempio n. 9
0
        void saveCitizen()
        {
            using (var eb = new EBarangayEntities())
            {
                var c = eb.Citizens.FirstOrDefault(x => x.ID == citizen.ID);

                var a = eb.Areas.FirstOrDefault(x => x.Name == area.Text);
                c.Area    = a;
                c.Picture = Class.ImageConverter.imageToByteArray(picBox.Image);

                c.IdNumber   = Id.Text;
                c.FirstName  = firstName.Text;
                c.MiddleName = middleName.Text;
                c.LastName   = lastName.Text;
                c.Extension  = extensionName.Text;

                c.Address     = address.Text;
                c.Birthday    = birthdate.Value;
                c.Gender      = sex.Text;
                c.ContactInfo = contact.Text;
                c.CivilStatus = civilStatus.Text;

                c.SpouseName  = !string.IsNullOrEmpty(spouseName.Text) ? spouseName.Text : null;
                c.FathersName = !string.IsNullOrEmpty(fathersName.Text) ? fathersName.Text : null;
                c.MothersName = !string.IsNullOrEmpty(mothersName.Text) ? mothersName.Text : null;

                c.Indigent      = indigent.Checked;
                c.Student       = student.Checked;
                c.PWD           = pwd.Checked;
                c.SeniorCitizen = senior.Checked;

                c.SSS            = !string.IsNullOrEmpty(sss.Text) ? sss.Text : null;
                c.Philhealth     = !string.IsNullOrEmpty(philhealth.Text) ? philhealth.Text : null;
                c.PagIbig        = !string.IsNullOrEmpty(pagibig.Text) ? pagibig.Text : null;
                c.VoterID        = !string.IsNullOrEmpty(votersId.Text) ? votersId.Text : null;
                c.PrecinctNumber = !string.IsNullOrEmpty(precinctNumber.Text) ? precinctNumber.Text : null;

                eb.SaveChanges();
                Onsave?.Invoke(this, null);
            }
        }
Esempio n. 10
0
        private void areaTable_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex != 2)
            {
                return;
            }

            if (MessageBox.Show("Are you sure you want to remove item?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
            {
                return;
            }

            var id = (int)(areaTable.Rows[e.RowIndex].Cells[0].Value);

            using (var p = new EBarangayEntities())
            {
                var a = p.Areas.FirstOrDefault(x => x.ID == id);
                p.Areas.Remove(a);
                p.SaveChanges();
            }
            areaTable.Rows.RemoveAt(e.RowIndex);
        }
Esempio n. 11
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (areaName.Text == string.Empty)
            {
                return;
            }
            var an = areaName.Text.Trim(' ');

            using (var p = new EBarangayEntities())
            {
                if (p.Areas.Any(x => x.Name == an))
                {
                    MessageBox.Show("Already registered");
                    return;
                }
                var a = new Area();
                a.Name = an;
                p.Areas.Add(a);
                p.SaveChanges();
                areaTable.Rows.Add(a.ID, a.Name, "Remove");
            }
            MessageBox.Show("Area added.");
        }
        private void SaveRecord(object sender, bool e)
        {
            if (!e)
            {
                return;
            }


            var rec = new Complaint();

            //rec.ID = string.IsNullOrEmpty(controlNumberField.Text) ? Guid.NewGuid().ToString() : controlNumberField.Text;
            rec.Location       = locationField.Text.TrimStart(' ').TrimEnd(' ');
            rec.DateHappened   = dtIncident.Value;
            rec.DateIssued     = DateTime.Now;
            rec.SettlementDate = dtSettlement.Value;
            rec.Narrative      = narrativeField.Text;
            rec.Status         = ComplaintStatus.Pending.ToString();

            /// saving names in comps and resps
            //for (int i = 0; i < dgvComplainants.RowCount; i++)
            //{
            //    if (dgvComplainants.Rows[i].Cells[0].Value != null)
            //    {
            //        ///get the string of the id column
            //        string idString = dgvComplainants.Rows[i].Cells[1].Value.ToString();
            //        //if (!string.IsNullOrEmpty(idString))
            //        //    rec.CompNames += dgvComplainants.Rows[i].Cells[1].Value.ToString() + (i == dgvComplainants.RowCount - 2 ? "" : ",");
            //        Citizen c;
            //        if (CitizenExtensions.CitizenById(idString, out c))
            //            rec.CompNames += dgvComplainants.Rows[i].Cells[1].Value.ToString() + (i == dgvComplainants.RowCount - 2 ? "" : ",");

            //        else
            //            rec.CompNames += dgvComplainants.Rows[i].Cells[0].Value.ToString() + (i == dgvComplainants.RowCount - 2 ? "" : ",");
            //    }
            //}

            //for (int i = 0; i < dgvRespondents.RowCount; i++)
            //{
            //    if (dgvRespondents.Rows[i].Cells[0].Value != null)
            //    {
            //        ///get the string of the id column
            //        string idString = dgvRespondents.Rows[i].Cells[1].Value.ToString();
            //        Citizen c;
            //        if (CitizenExtensions.CitizenById(idString, out c))
            //            rec.RespNames += dgvRespondents.Rows[i].Cells[1].Value.ToString() + (i == dgvRespondents.RowCount - 2 ? "" : ",");

            //        else
            //            rec.RespNames += dgvRespondents.Rows[i].Cells[0].Value.ToString() + (i == dgvRespondents.RowCount - 2 ? "" : ",");

            //    }
            //}
            //for (int i = 0; i < dgvComplainants.RowCount; i++)
            //{
            //    if (dgvComplainants.Rows[i].Cells[0].Value != null)
            //        rec.CompNames += dgvComplainants.Rows[i].Cells[0].Value.ToString() + (i == dgvComplainants.RowCount - 2 ? "" : ",");
            //}
            //for (int i = 0; i < dgvRespondents.RowCount; i++)
            //{
            //    if (dgvRespondents.Rows[i].Cells[0].Value != null)
            //        rec.RespNames += dgvRespondents.Rows[i].Cells[0].Value.ToString() + (i == dgvRespondents.RowCount - 2 ? "" : ",");
            //}
            ///end if



            using (var ent = new EBarangayEntities())
            {
                ent.Complaints.Add(rec);
                ent.SaveChanges();
            }

            connectComplaintToCitizen(rec, dgvComplainants);
            connectComplaintToCitizen(rec, dgvRespondents);

            ComplaintAdded?.Invoke(this, new EventArgs());
            Cleanup();
        }