Example #1
0
 //Only options used: "C" & "U"
 public void modifySalary(string action, Salary sal)
 {
    this.Database.ExecuteSqlCommand("EXEC uspLW1190_CRUDSalary @action, @TimeKeep, @Seq_no, @LocalSalary, @CurrCode, @EffectiveDate, @Comment",
                   new SqlParameter("@action", action),
                   new SqlParameter("@TimeKeep", sal.TimeKeep),
                   new SqlParameter("@Seq_no", sal.Seq_no),
                   new SqlParameter("@LocalSalary", sal.LocalSalary),
                   new SqlParameter("@CurrCode", sal.CurrCode),
                   new SqlParameter("@EffectiveDate", sal.EffectiveDate),
                   new SqlParameter("@Comment", sal.Comment));
 }
      protected void grdSalary_ItemCommand(object sender, GridCommandEventArgs e)
      {
         string id, code, comment;
         int seq;
         decimal salary;
         DateTime dteEff;

         if (e.Item.IsInEditMode && e.Item is GridEditableItem)
         {
            RadComboBox cbCCY = (RadComboBox)e.Item.FindControl("rcbCurrCodeEdit");
            code = cbCCY.SelectedValue;

            //Prepare new dictionary object
            Hashtable newValues = new Hashtable();

            switch (e.CommandName)
            {
               case RadGrid.PerformInsertCommandName:
                  if (Page.IsValid)       //Check required fields are populated:  Salary & Eff. Date    
                  {
                     GridDataInsertItem item = e.Item as GridDataInsertItem;

                     item.ExtractValues(newValues);

                     RadTab tab = tabAtty.FindTabByText("Personal");
                     RadPageView pgVw = tab.PageView;

                     id = ((RadTextBox)pgVw.FindControl("txtAttyID")).Text;
                     seq = 0;    //value will be determined by stored proc
                     salary = Decimal.Parse(newValues["LocalSalary"].ToString());
                     dteEff = DateTime.Parse(newValues["EffectiveDate"].ToString());
                     comment = (newValues["Comment"] == null ? String.Empty : newValues["Comment"].ToString());

                     var insSal = new Salary { TimeKeep = id, Seq_no = seq, LocalSalary = salary, CurrCode = code, EffectiveDate = dteEff, Comment = comment };

                     using (var ctx = new DBContext())
                        ctx.modifySalary("C", insSal);
                  }
                  break;
               case RadGrid.UpdateCommandName:
                  GridEditableItem editedItem = e.Item as GridEditableItem;

                  //editedItem.SavedOldValues: dictionary holds the old values
                  e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);

                  id = newValues["TimeKeep"].ToString();
                  seq = int.Parse(newValues["Seq_no"].ToString());
                  salary = Decimal.Parse(newValues["LocalSalary"].ToString());
                  dteEff = DateTime.Parse(newValues["EffectiveDate"].ToString());
                  comment = (newValues["Comment"] == null ? String.Empty : newValues["Comment"].ToString());

                  var updSal = new Salary { TimeKeep = id, Seq_no = seq, LocalSalary = salary, CurrCode = code, EffectiveDate = dteEff, Comment = comment };

                  using (var ctx = new DBContext())
                     ctx.modifySalary("U", updSal);
                  break;
               //case RadGrid.DeleteCommandName:        //AllowAutomaticDeletes="true"             
               //   break;
            }
         }
      }