コード例 #1
0
        private void PopulateFields(int activityId)
        {
            Activity0Helper helper    = new Activity0Helper();
            Activity0       activity0 = helper.GetActivityData(ACTIVITY_TYPE, activityId);
            Activity5       activity  = (Activity5)activity0;


            if (activity != null)
            {
                comboBox1.Text = activity.Region;
                comboBox2.Text = activity.Zone;
                comboBox3.Text = activity.Woreda;
                comboBox5.Text = activity.Kebele;
                DateTime newDateTime = new DateTime(Convert.ToInt32(activity.Year), 1, 1);
                dateTimePicker1.Value = Convert.ToDateTime(newDateTime);
                dateTimePicker4.Value = activity.ActivityDate;
                textBox3.Text         = activity.IssuesRaised;
                textBox4.Text         = activity.AgreedActionPoints;
                textBox7.Text         = activity.FacilitatorName;
                textBox6.Text         = activity.Position;
            }
            List <Participant> participantsList = helper.GetParticpantData(ACTIVITY_TYPE, activityId);

            for (int i = 0; i < participantsList.Count; i++)
            {
                Participant  participant0 = participantsList[i];
                Participant5 participant  = (Participant5)participant0;

                string[] row = { dataGridView2.RowCount + "", participant.Pdate.ToString(), participant.Code, participant.Town, participant.Age.ToString(), GetStringFromInt(participant.Disabled), participant.Dateofvisit.ToString(), participant.Identifiedcase, participant.Others };
                dataGridView2.Rows.Add(row);
                dataGridView2.Rows[dataGridView2.RowCount - 2].Cells[9].Value  = GetBoolFromInt(participant.Referralhealth);
                dataGridView2.Rows[dataGridView2.RowCount - 2].Cells[10].Value = GetBoolFromInt(participant.Referralpolice);
                dataGridView2.Rows[dataGridView2.RowCount - 2].Cells[11].Value = GetBoolFromInt(participant.Referrallegal);
                dataGridView2.Rows[dataGridView2.RowCount - 2].Cells[12].Value = GetBoolFromInt(participant.Referralpsycho);
            }
        }
コード例 #2
0
        private void SaveData(int saveOrUpdate)
        {
            //mainFieldsValid();
            if (mainFieldsValid())
            {
                Activity0Helper helper   = new Activity0Helper();
                Activity5       activity = new Activity5();

                activity.Region          = comboBox1.Text;
                activity.Zone            = comboBox2.Text;
                activity.Woreda          = comboBox3.Text;
                activity.Kebele          = comboBox5.Text;
                activity.Year            = dateTimePicker1.Value.Year.ToString();
                activity.ActivityDate    = dateTimePicker4.Value;
                activity.UserId          = Properties.Settings.Default.UID; //change this using property stored id of currently logged in user
                activity.FacilitatorName = textBox7.Text;                   //make name of logged in user available in this field
                activity.Position        = textBox6.Text;
                activity.LocalTimeStamp  = DateTime.Now;
                activity.Mac             = StringCipher.GetMacAddress();

                activity.IssuesRaised       = textBox3.Text;
                activity.AgreedActionPoints = textBox4.Text;


                List <Participant> participantsList = new List <Participant>();
                if (dataGridView2.RowCount > 1)
                {
                    for (int i = 0; i < dataGridView2.Rows.Count - 1; i++)//-1 to avoid empty row
                    {
                        Participant5 participant = new Participant5();
                        if (dataGridView2.Rows[i].Cells[1].Value != null)
                        {
                            participant.Pdate = Convert.ToDateTime(dataGridView2.Rows[i].Cells[1].Value.ToString());
                        }

                        if (dataGridView2.Rows[i].Cells[2].Value != null)
                        {
                            participant.Code = dataGridView2.Rows[i].Cells[2].Value.ToString();
                        }

                        if (dataGridView2.Rows[i].Cells[3].Value != null)
                        {
                            participant.Town = dataGridView2.Rows[i].Cells[3].Value.ToString();
                        }

                        if (dataGridView2.Rows[i].Cells[4].Value != null)
                        {
                            participant.Age = Convert.ToInt32(dataGridView2.Rows[i].Cells[4].Value.ToString());
                        }

                        if (dataGridView2.Rows[i].Cells[5].Value != null)
                        {
                            participant.Disabled = GetDisabledInt(dataGridView2.Rows[i].Cells[5].Value.ToString());
                        }

                        if (dataGridView2.Rows[i].Cells[6].Value != null)
                        {
                            participant.Dateofvisit = Convert.ToDateTime(dataGridView2.Rows[i].Cells[6].Value.ToString());
                        }

                        if (dataGridView2.Rows[i].Cells[7].Value != null)
                        {
                            participant.Identifiedcase = dataGridView2.Rows[i].Cells[7].Value.ToString();
                        }

                        if (dataGridView2.Rows[i].Cells[8].Value != null)
                        {
                            participant.Others = dataGridView2.Rows[i].Cells[8].Value.ToString();
                        }

                        if (dataGridView2.Rows[i].Cells[9].Value != null)
                        {
                            participant.Referralhealth = GetIntFromBool(Convert.ToBoolean(dataGridView2.Rows[i].Cells[9].FormattedValue));
                        }
                        if (dataGridView2.Rows[i].Cells[10].Value != null)
                        {
                            participant.Referralpolice = GetIntFromBool(Convert.ToBoolean(dataGridView2.Rows[i].Cells[10].FormattedValue));
                        }
                        if (dataGridView2.Rows[i].Cells[11].Value != null)
                        {
                            participant.Referrallegal = GetIntFromBool(Convert.ToBoolean(dataGridView2.Rows[i].Cells[11].FormattedValue));
                        }
                        if (dataGridView2.Rows[i].Cells[12].Value != null)
                        {
                            participant.Referralpsycho = GetIntFromBool(Convert.ToBoolean(dataGridView2.Rows[i].Cells[12].FormattedValue));
                        }


                        participantsList.Add(participant);
                    }
                }
                //MessageBox.Show(activity.Position);
                int id = helper.Insert(ACTIVITY_TYPE, activity, participantsList);

                if (id > 0)
                {
                    InsertRegionAndKebeleData();
                    //MessageBox.Show("Activity data added successfully!");
                    MessageBox.Show("Activity data added successfully!", "Successfully Addition", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    //check internet connection before syncing data
                    if (saveOrUpdate == 1)//update button clicked
                    {
                        //if (StringCipher.CheckInternet("http://" + Session.Properties.Settings.Default.RemoteDatabaseAddress))
                        SyncData();
                    }
                    //this.Close(); //or Reset fields

                    this.Close();
                }
            }
        }