private void addMeasureToBD(MeasureView msr)
        {
            using (SqlConnection sqlCon = new SqlConnection(AppSettings.GetConnectionString(typeof(Measure), application_cb.SelectedItem.ToString())))
            {
                sqlCon.Open();
                SqlCommand sqlCommand = DataManager.CreateCommand(
                    @"INSERT INTO [dbo].[Measure]([MeasureID],
                [AccountID],[ChannelID],[BaseMeasureID],[SourceName],[DisplayName],[StringFormat],[AcquisitionNum],[IntegrityCheckRequired])
                VALUES( @measureID:Int,@accountID:Int,@channelID:Int,@baseID:Int,@sourceName:Nvarchar,@displayName:Nvarchar,@stringFormat:Nvarchar,@acquisitionNum:Nvarchar,@check:Nvarchar)");

                sqlCommand.Parameters["@measureID"].Value      = getNewMeasureID();
                sqlCommand.Parameters["@accountID"].Value      = accounts_cb.SelectedValue;
                sqlCommand.Parameters["@channelID"].Value      = msr.m.Channel == null ? "-1" : msr.m.Channel.ID.ToString();
                sqlCommand.Parameters["@baseID"].Value         = msr.m.BaseMeasureID;
                sqlCommand.Parameters["@sourceName"].Value     = string.IsNullOrEmpty(msr.m.SourceName) ? DBNull.Value : (object)msr.m.SourceName;
                sqlCommand.Parameters["@displayName"].Value    = msr.m.DisplayName;
                sqlCommand.Parameters["@stringFormat"].Value   = string.IsNullOrEmpty(msr.m.StringFormat) ? DBNull.Value : (object)msr.m.StringFormat;
                sqlCommand.Parameters["@acquisitionNum"].Value = msr.m.AcquisitionNum == null ? DBNull.Value : (object)msr.m.AcquisitionNum;
                sqlCommand.Parameters["@check"].Value          = string.IsNullOrEmpty(msr.IntegrityCheckRequired) ? DBNull.Value : (object)msr.IntegrityCheckRequired;

                sqlCommand.Connection = sqlCon;
                sqlCommand.ExecuteNonQuery();
            }
            showMeasuresBtn_Click(null, null);
        }
        void AddMeasureHandler(object sender, EventArgs e)
        {
            MeasureView msr = (MeasureView)e;

            if (msr.m.Account == null)
            {
                addMeasureToBD(msr);
            }
            else
            {
                editMeasureInDB(msr);
            }
        }
Example #3
0
        private void editMeasureInDB(MeasureView msr)
        {
            using (SqlConnection sqlCon = new SqlConnection(AppSettings.GetConnectionString(typeof(Measure), application_cb.SelectedItem.ToString())))
            {
                bool includeStringFormat = !(msr.m.StringFormat.Equals("no change"));
                bool includeValidation   = !(msr.IntegrityCheckRequired.Equals("no change"));

                string command = string.Format(@"UPDATE [dbo].[Measure]
                SET [SourceName] = @sourceName:Nvarchar, [DisplayName] = @displayName:Nvarchar, [AcquisitionNum] = @acquisitionNum:Nvarchar{0}{1}
                WHERE [MeasureID] = @measureID:Int and [AccountID] = @accountID:Int and [ChannelID] = @channelID:Int and [BaseMeasureID] = @baseID:Int",
                                               includeStringFormat ? ", [StringFormat] = @stringFormat:Nvarchar" : "", includeValidation ? ", [IntegrityCheckRequired] = @check:Nvarchar" : "");

                sqlCon.Open();
                SqlCommand sqlCommand = DataManager.CreateCommand(command);

                sqlCommand.Parameters["@measureID"].Value      = msr.m.ID;
                sqlCommand.Parameters["@accountID"].Value      = msr.m.Account.ID;
                sqlCommand.Parameters["@channelID"].Value      = msr.m.Channel == null ? "-1" : msr.m.Channel.ID.ToString();
                sqlCommand.Parameters["@baseID"].Value         = msr.m.BaseMeasureID;
                sqlCommand.Parameters["@sourceName"].Value     = string.IsNullOrEmpty(msr.m.SourceName) ? DBNull.Value : (object)msr.m.SourceName;
                sqlCommand.Parameters["@displayName"].Value    = string.IsNullOrEmpty(msr.m.DisplayName) ? DBNull.Value : (object)msr.m.DisplayName;
                sqlCommand.Parameters["@acquisitionNum"].Value = msr.m.AcquisitionNum == null ? DBNull.Value : (object)msr.m.AcquisitionNum;
                if (includeValidation)
                {
                    sqlCommand.Parameters["@check"].Value = string.IsNullOrEmpty(msr.IntegrityCheckRequired) ? DBNull.Value : (object)msr.IntegrityCheckRequired;
                }
                if (includeStringFormat)
                {
                    sqlCommand.Parameters["@stringFormat"].Value = string.IsNullOrEmpty(msr.m.StringFormat) ? DBNull.Value : (object)msr.m.StringFormat;
                }

                sqlCommand.Connection = sqlCon;
                sqlCommand.ExecuteNonQuery();
            }
            if (!string.IsNullOrEmpty(msr.oldMeasure.AcquisitionNum.ToString()))
            {
                deleteAcquisitionCPA(msr.oldMeasure);
            }
            setAcquisitionCPA();
            showMeasuresBtn_Click(null, null);
        }