예제 #1
0
        protected void saveUpdateIndicatorsBtn_Click(object sender, EventArgs e)
        {
            //Simple test to check loading progress in any delay
            //System.Threading.Thread.Sleep(5000);

            //Save the datatable to the database
            DataTable _dt = ViewState["dt"] as DataTable;

            DataTable _disag_dt = ViewState["disag_dt"] as DataTable;

            if (_dt.Rows.Count > 0)
            {
                foreach (DataRow row in _dt.Rows)
                {
                    partner_indicators newIndicator = new partner_indicators();
                    newIndicator.project_id        = int.Parse(row["project_id"].ToString());
                    newIndicator.indicator_type_id = int.Parse(row["indicator_type_id"].ToString());
                    newIndicator.indicator         = row["indicator"].ToString();
                    newIndicator.target            = row["target"].ToString();
                    if (int.Parse(row["fsda_indicator_code_id"].ToString()) != 0)
                    {
                        newIndicator.fsda_indicator_id = int.Parse(row["fsda_indicator_code_id"].ToString());
                    }

                    db.partner_indicators.Add(newIndicator);

                    if (_disag_dt.Rows.Count > 0)
                    {
                        foreach (DataRow disagRow in _disag_dt.Rows)
                        {
                            /*indicator_disaggregation newDisaggregation = new indicator_disaggregation();
                             * newDisaggregation.partner_indicators = newIndicator;
                             * newDisaggregation.disaggregation = disagRow["disaggregation"].ToString();
                             *
                             * db.indicator_disaggregation.Add(newDisaggregation);*/

                            if (disagRow["foreign_id"].ToString() == row["id"].ToString())
                            {
                                project_indicator_disaggregation newDisaggregation = new project_indicator_disaggregation();
                                newDisaggregation.partner_indicators = newIndicator;
                                newDisaggregation.disaggregation_id  = int.Parse(disagRow["disaggregation_id"].ToString());

                                db.project_indicator_disaggregation.Add(newDisaggregation);
                            }
                        }
                    }
                }
                try
                {
                    if (db.SaveChanges() > 0)
                    {
                        db.SaveChanges();
                    }
                }
                catch
                {
                    throw new Exception();
                }
                finally
                {
                    AlertLabel.Text = _dt.Rows.Count.ToString() + " indicator(s) and " +
                                      _disag_dt.Rows.Count + " disaggratation(s) added to the database successfully!";

                    ScriptManager.RegisterStartupScript(
                        Page,
                        Page.GetType(),
                        "alertModal", "$('#alertModal').modal('show');",
                        true);
                }
            }
        }
예제 #2
0
        protected void SaveDisaggregationButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (IndicatorIDHiddenField.Value != null)
                {
                    if (Disaggregation3DropDown.SelectedItem != null)
                    {
                        if (Disaggregation3DropDown.SelectedItem.Value == "0" ||
                            Disaggregation3DropDown.SelectedItem.Value == "new")
                        {
                            if (Disaggregation2DropDown.SelectedItem.Value == "0" ||
                                Disaggregation2DropDown.SelectedItem.Value == "new")
                            {
                                if (Disaggregation1DropDown.SelectedItem.Value == "0" ||
                                    Disaggregation1DropDown.SelectedItem.Value == "new")
                                {
                                    //Nothing to save
                                    return;
                                }
                                else
                                {
                                    //Save the first disaggre
                                    int projIndicatorId = int.Parse(IndicatorIDHiddenField.Value.Trim());
                                    int disagId         = int.Parse(Disaggregation1DropDown.SelectedItem.Value.Trim());

                                    project_indicator_disaggregation newDisaggregation = new project_indicator_disaggregation();
                                    newDisaggregation.project_indicator_id = projIndicatorId;
                                    newDisaggregation.disaggregation_id    = disagId;

                                    db.project_indicator_disaggregation.Add(newDisaggregation);
                                }
                            }
                            else
                            {
                                //Save the second disagr
                                int projIndicatorId = int.Parse(IndicatorIDHiddenField.Value.Trim());
                                int disagId         = int.Parse(Disaggregation2DropDown.SelectedItem.Value.Trim());

                                project_indicator_disaggregation newDisaggregation = new project_indicator_disaggregation();
                                newDisaggregation.project_indicator_id = projIndicatorId;
                                newDisaggregation.disaggregation_id    = disagId;

                                db.project_indicator_disaggregation.Add(newDisaggregation);
                            }
                        }
                        else
                        {
                            //Save the thrid disagrr
                            int projIndicatorId = int.Parse(IndicatorIDHiddenField.Value.Trim());
                            int disagId         = int.Parse(Disaggregation3DropDown.SelectedItem.Value.Trim());

                            project_indicator_disaggregation newDisaggregation = new project_indicator_disaggregation();
                            newDisaggregation.project_indicator_id = projIndicatorId;
                            newDisaggregation.disaggregation_id    = disagId;

                            db.project_indicator_disaggregation.Add(newDisaggregation);
                        }
                    }
                    else if (Disaggregation2DropDown.SelectedItem != null)
                    {
                        if (Disaggregation2DropDown.SelectedItem.Value == "0" ||
                            Disaggregation2DropDown.SelectedItem.Value == "new")
                        {
                            if (Disaggregation1DropDown.SelectedItem.Value == "0" ||
                                Disaggregation1DropDown.SelectedItem.Value == "new")
                            {
                                //Nothing to save
                                return;
                            }
                            else
                            {
                                //Save the first disaggre
                                int projIndicatorId = int.Parse(IndicatorIDHiddenField.Value.Trim());
                                int disagId         = int.Parse(Disaggregation1DropDown.SelectedItem.Value.Trim());

                                project_indicator_disaggregation newDisaggregation = new project_indicator_disaggregation();
                                newDisaggregation.project_indicator_id = projIndicatorId;
                                newDisaggregation.disaggregation_id    = disagId;

                                db.project_indicator_disaggregation.Add(newDisaggregation);
                            }
                        }
                        else
                        {
                            //Save the second disagr
                            int projIndicatorId = int.Parse(IndicatorIDHiddenField.Value.Trim());
                            int disagId         = int.Parse(Disaggregation2DropDown.SelectedItem.Value.Trim());

                            project_indicator_disaggregation newDisaggregation = new project_indicator_disaggregation();
                            newDisaggregation.project_indicator_id = projIndicatorId;
                            newDisaggregation.disaggregation_id    = disagId;

                            db.project_indicator_disaggregation.Add(newDisaggregation);
                        }
                    }
                    else if (Disaggregation1DropDown.SelectedItem != null)
                    {
                        if (Disaggregation1DropDown.SelectedItem.Value == "0" ||
                            Disaggregation1DropDown.SelectedItem.Value == "new")
                        {
                            //Nothing to save
                            return;
                        }
                        else
                        {
                            //Save the first disaggre
                            int projIndicatorId = int.Parse(IndicatorIDHiddenField.Value.Trim());
                            int disagId         = int.Parse(Disaggregation1DropDown.SelectedItem.Value.Trim());

                            project_indicator_disaggregation newDisaggregation = new project_indicator_disaggregation();
                            newDisaggregation.project_indicator_id = projIndicatorId;
                            newDisaggregation.disaggregation_id    = disagId;

                            db.project_indicator_disaggregation.Add(newDisaggregation);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                if (db.SaveChanges() > 0)
                {
                    db.SaveChanges();
                    DisaggragationView.DataBind();
                }
            }
        }