예제 #1
0
파일: Form9.cs 프로젝트: natz247/FGMIS2
        private void SaveData(int saveOrUpdate)
        {
            //mainFieldsValid();
            if (mainFieldsValid())
            {
                Activity0Helper helper   = new Activity0Helper();
                Activity9       activity = new Activity9();

                activity.Region          = comboBox1.Text;
                activity.Zone            = comboBox2.Text;
                activity.Woreda          = comboBox3.Text;
                activity.Kebele          = comboBox5.Text;
                activity.ActivityDate    = dateTimePicker1.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
                    {
                        Participant9 participant = new Participant9();
                        if (dataGridView2.Rows[i].Cells[1].Value != null)
                        {
                            participant.Name = dataGridView2.Rows[i].Cells[1].Value.ToString();
                        }

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

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

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

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

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

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

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

                        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();
                }
            }
        }
예제 #2
0
파일: Form3.cs 프로젝트: natz247/FGMIS2
        private void SaveData(int saveOrUpdate)
        {
            //mainFieldsValid();
            if (mainFieldsValid())
            {
                //MessageBox.Show("All fields valid. Ready to submit data to database.");
                Activity0Helper helper   = new Activity0Helper();
                Activity3       activity = new Activity3();
                //(region, zone, woreda, kebele, activity_date, user_id, facilitator_name, position, localtimestamp, mac)
                activity.Region              = comboBox1.Text;
                activity.Zone                = comboBox2.Text;
                activity.Woreda              = comboBox3.Text;
                activity.Trainingtitle       = textBox1.Text;
                activity.Trainingfacilitator = textBox2.Text;
                activity.ActivityDate        = dateTimePicker1.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
                    {
                        Participant3 participant = new Participant3();
                        if (dataGridView2.Rows[i].Cells[1].Value != null)
                        {
                            participant.Name = dataGridView2.Rows[i].Cells[1].Value.ToString();
                        }
                        if (dataGridView2.Rows[i].Cells[2].Value != null)
                        {
                            participant.Sex = dataGridView2.Rows[i].Cells[2].Value.ToString();
                        }
                        if (dataGridView2.Rows[i].Cells[3].Value != null)
                        {
                            participant.Organization = dataGridView2.Rows[i].Cells[3].Value.ToString();
                        }
                        if (dataGridView2.Rows[i].Cells[4].Value != null)
                        {
                            participant.Position = dataGridView2.Rows[i].Cells[4].Value.ToString();
                        }
                        if (dataGridView2.Rows[i].Cells[5].Value != null)
                        {
                            participant.Woreda = dataGridView2.Rows[i].Cells[5].Value.ToString();
                        }
                        if (dataGridView2.Rows[i].Cells[6].Value != null)
                        {
                            participant.Kebele = dataGridView2.Rows[i].Cells[6].Value.ToString();
                        }


                        participantsList.Add(participant);
                    }
                }
                //MessageBox.Show(activity.Position);
                int id = helper.Insert(3, 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();
                }
            }
        }