Esempio n. 1
0
      protected void btnDtlUpdate_Click(object sender, System.Web.UI.ImageClickEventArgs e)
      {
         //http://stackoverflow.com/questions/12879198/how-can-i-update-a-detached-entity-in-ef-cf-multi-tier-application
         //context.Entry(user).Property(u => u.Body).IsModified = true;
         //DataContext.Entry(entity).State = System.Data.EntityState.Modified;
         //http://msdn.microsoft.com/en-us/data/jj592676.aspx

         if (Page.IsValid)
         {
            RadTab tab = tabAtty.FindTabByText("Personal");
            RadPageView pgVw = tab.PageView;

            string id = ((RadTextBox)pgVw.FindControl("txtAttyID")).Text;

            if (!String.IsNullOrEmpty(id))
            {
               using (var ctx = new DBContext())
               {
                  var atty = ctx.Attorneys.Find(id);

                  atty.tsaudit_op = ntID;
                  atty.LastModified = DateTime.Now;
                  //atty.ProperCaseName = ((RadTextBox)pgVw.FindControl("txtFullName")).Text;
                  //NO need to update location code: tsloc
                  //atty.tspstd = ((RadNumericTextBox)pgVw.FindControl("txtStdPrnRate")).Value;          //Std Partner Rate
                  atty.tsunits = ((RadNumericTextBox)pgVw.FindControl("txtUnits")).Value;                //Units
                  atty.tsbonus = ((RadNumericTextBox)pgVw.FindControl("txtBonus")).Value;                //Bonus

                  atty.tsdeparture = ((RadComboBox)pgVw.FindControl("rcbDeparture")).SelectedValue;      //Departure?
                  atty.tsadjunits = ((RadNumericTextBox)pgVw.FindControl("txtAdjUnits")).Value;          //Adjusted Units
                  atty.tsdob = ((RadDatePicker)pgVw.FindControl("txtDOB")).DateInput.SelectedDate;       //Date of Birth
                  atty.tsdepartdt = (atty.tsdeparture == "Y" ?                                           //Departure Date
                        ((RadDatePicker)pgVw.FindControl("txtDepartDate")).DateInput.SelectedDate : null);
                  atty.tsunitval = ((RadNumericTextBox)pgVw.FindControl("txtUnitValue")).Value;          //Unit Value
                  atty.tstype = ((RadComboBox)pgVw.FindControl("rcbType")).SelectedValue;                //Type
                  if (atty.tstype == "I")                                                                //IP Level - Allowable values: 1-8, but no validation
                  {                                                                                      //[MinValue="1"; MaxValue="8"]
                     int n = 1;
                     if (int.TryParse(((RadNumericTextBox)pgVw.FindControl("txtIPLevel")).Text, out n))
                        atty.IPLevel = n;
                  }
                  else
                  {
                     atty.IPLevel = null;
                  }
                  atty.tsclass = ((RadMaskedTextBox)pgVw.FindControl("txtClass")).Text.Trim();           //Class
                  atty.tsfund = ((RadNumericTextBox)pgVw.FindControl("txtPreFundComp")).Value;           //Pre-Fund Compensation
                  atty.tstatus = ((RadComboBox)pgVw.FindControl("rcbRank")).SelectedValue;               //Rank
                  atty.tsevalclass = ((RadMaskedTextBox)pgVw.FindControl("txtEvalClass")).Text.Trim();   //Evaluation Class
                  atty.tspfund = ((RadNumericTextBox)pgVw.FindControl("txtPrnFund")).Value;              //Partner Fund
                  //atty.tsppgroup = ((RadTextBox)pgVw.FindControl("txtPrinPracGroup")).Text;            //Principal Practice Group [Read-only]
                  //atty.tsepadmindt = ((RadDatePicker)pgVw.FindControl("txtAdminDate")).DateInput.SelectedDate;   //Equity Partner Admission Date [Read-only]
                  //atty.tsBarState = ((RadTextBox)pgVw.FindControl("txtBar")).Text;                     //Bar [Read-only]
                  atty.tscomment = ((RadTextBox)pgVw.FindControl("txtComment")).Text;                    //Comment
                  ctx.SaveChanges();

                  //ctx.LogUser(ntID, Global.REPORT_ID);

                  RadWindowManager1.RadAlert("Personal info updated", 225, 125, "Personal", "");

                  //*** Joanne Joe's request: Upon saving the record, please clear the screen of data ***
                  ResetAttyInfo();
                  //    1. Afterward, clear attorney option selected
                  foreach (GridDataItem dataItem in grdAtty.MasterTableView.Items)
                  {
                     RadioButton rb = (dataItem.FindControl("rbAtty") as RadioButton);
                     rb.Checked = false;
                     dataItem.Selected = false;
                  }
               }
            }
         }
      }
Esempio n. 2
0
      protected void grdCommittee_ItemCommand(object sender, GridCommandEventArgs e)
      {
         string id;

         #region Iff all fields are bound by GridBoundColumn
         /*
         if (e.Item.IsInEditMode && e.Item is GridEditableItem)
         {
            GridEditableItem editedItem = e.Item as GridEditableItem;

            //Prepare new dictionary object
            Hashtable newValues = new Hashtable();
            e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);

            int newNum = int.Parse(newValues["cnum"].ToString());
            string newChair = newValues["cchair"].ToString();

            switch (e.CommandName)
            {
               case RadGrid.PerformInsertCommandName:
                  RadTab tab = tabAtty.FindTabByText("Personal");
                  RadPageView pgVw = tab.PageView;

                  id = ((RadTextBox)pgVw.FindControl("txtAttyID")).Text;

                  using (var ctx = new DBContext())
                  {
                     var com = new Committee { tkinit = id, cnum = newNum, cchair = newChair };
                     ctx.Committees.Add(com);
                     ctx.SaveChanges();
                  }
                  break;
               case RadGrid.UpdateCommandName:
                  //editedItem.SavedOldValues: dictionary holds the old values
                  id = editedItem.SavedOldValues["tkinit"].ToString();
                  int oldNum = int.Parse(editedItem.SavedOldValues["cnum"].ToString());

                  var comm = new Committee { tkinit = id, cnum = newNum, cchair = newChair };
                  using (var ctx = new DBContext())
                  {
                     ////*** Notes:  You cannot update the primary key through EF. ***
                     //// A referential integrity constraint violation occurred: A primary key property that is a part of 
                     //// referential integrity constraint cannot be changed when the dependent object is Unchanged 
                     //// unless it is being set to the association's principal object. 
                     //// The principal object must be tracked and not marked for deletion.
                     //var com = ctx.Committees.Find(id, oldNum);
                     //var comMas = ctx.CommitteeMasters.Find(newNum);
                     ////com.cnum = newNum;
                     ////com.cnum = comMas.cnum;
                     //com.CommitteeMaster = comMas;
                     //com.cchair = newChair;
                     //ctx.SaveChanges();

                     ctx.updateCom(comm, oldNum);
                  }
                  break;
               //case RadGrid.DeleteCommandName:        //AllowAutomaticDeletes="true"             
               //   break;
            }
         }
         */
         #endregion

         if (e.Item.IsInEditMode && e.Item is GridEditableItem)
         {
            RadComboBox cbChair = (RadComboBox)e.Item.FindControl("rcbChairEdit");
            RadComboBox cbCode = (RadComboBox)e.Item.FindControl("rcbComCodeEdit");

            int newNum = int.Parse(cbCode.SelectedValue);
            string newChair = cbChair.SelectedValue;

            switch (e.CommandName)
            {
               case RadGrid.PerformInsertCommandName:
                  //e.Item as GridDataInsertItem
                  RadTab tab = tabAtty.FindTabByText("Personal");
                  RadPageView pgVw = tab.PageView;

                  id = ((RadTextBox)pgVw.FindControl("txtAttyID")).Text;

                  using (var ctx = new DBContext())
                  {
                     var com = new Committee { tkinit = id, cnum = newNum, cchair = newChair };
                     ctx.Committees.Add(com);
                     ctx.SaveChanges();
                  }

                  break;
               case RadGrid.UpdateCommandName:
                  GridEditableItem editedItem = e.Item as GridEditableItem;

                  //editedItem.SavedOldValues: dictionary holds the old values
                  id = editedItem.SavedOldValues["tkinit"].ToString();
                  int oldNum = int.Parse(editedItem.SavedOldValues["cnum"].ToString());

                  var comm = new Committee { tkinit = id, cnum = newNum, cchair = newChair };
                  using (var ctx = new DBContext())
                     ctx.updCommittee(comm, oldNum);
                  break;
               //case RadGrid.DeleteCommandName:        //AllowAutomaticDeletes="true"             
               //   break;
            }

         }
      }
Esempio n. 3
0
      /* Not needed
      protected void grdAtty_ItemDataBound(object sender, GridItemEventArgs e)
      {
         if (e.Item.IsInEditMode && e.Item is GridEditFormItem)      //FormTemplate
         // OR
         //if (e.Item.IsInEditMode && e.Item is GridEditableItem)
         {
            GridEditableItem editedItem = e.Item as GridEditableItem;
            RadGrid grid = (RadGrid)editedItem.FindControl("grdNewAtty");

            if (e.Item.OwnerTableView.IsItemInserted)
            {
               //This event occurs twice - before & after the actual insertion
               //*** item is about to be inserted ***
               //Populate controls in EditForm Template
               grid.DataBind();
            }
            else
            {
               //item is about to be edited
            }
         }
      }
      */

      protected void grdAtty_ItemCommand(object sender, GridCommandEventArgs e)
      {
         switch (e.CommandName)
         {
            //case RadGrid.InitInsertCommandName:             //"InitInsert"
            case RadGrid.FilterCommandName:
            case RadGrid.PageCommandName:
            case RadGrid.CancelCommandName:
               ResetAttyInfo();
               break;
            case RadGrid.PerformInsertCommandName:          //"PerformInsert"
               //GridDataInsertItem editItem = (GridDataInsertItem)grdAtty.MasterTableView.GetInsertItem();
               //string OrderId = (editItem["OrderID"].Controls[0] as TextBox).Text;
               //string ShipName = (editItem["ShipName"].Controls[0] as TextBox).Text;
               //DateTime OrderDate = Convert.ToDateTime((editItem["OrderDate"].Controls[0] as RadDatePicker).SelectedDate);

               /*
               //Automatic EditForms
               // http://www.telerik.com/community/forums/aspnet-ajax/grid/extracting-values-from-edited-items-in-a-radgrid-editform.aspx
               // http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/templateformupdate/defaultvb.aspx
               GridEditableItem editItem = e.Item as GridEditableItem;

               RadGrid grid = e.Item.FindControl("grdNewAtty") as RadGrid;

               //When using custom edit forms from template or user control, the ExtractValuesFromitem() method won't work for you, 
               //as it can extract values only from auto-generated grid edit forms
               Hashtable newValues = new Hashtable();
               e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editItem);

               string sID = newValues["AttyID"].ToString();
               */

               GridEditFormInsertItem insItem = e.Item as GridEditFormInsertItem;
               GridTableView vw = insItem.FindControl("grdNewAtty").Controls[1] as GridTableView;

               foreach (GridDataItem item in vw.Items)
               {
                  RadioButton rb = (item["rbNewAttyTemplateColumn"].FindControl("rbNewAtty") as RadioButton);

                  if (rb.Checked)
                  {
                     string sType;
                     switch (item["TitleCode"].Text)
                     {
                        case "0":                        //Type: lw_pdsm.tstype
                        case "1":                        //   E:	Equity			   0-1
                           sType = "E";                  //   I:	Income
                           break;                        //   C:	Counsel			   2
                        case "2":                        //   O:	Of Counsel
                           sType = "C";                  //   A:	Associate		   3
                           break;
                        case "3":
                        default:
                           sType = "A";
                           break;
                     }

                     var atty = new Attorney
                     {
                        tstk = item["AttyID"].Text,
                        tsloc = item["Loc"].Text,     //Not nullable       
                        tsunits = 99999,              //Units
                        tsadjunits = 0,               //Adjusted Value
                        tsunitval = 0,                //Unit Value
                        tsfund = 0,                   //Pre-Fund Compensation
                        tspfund = 0,                  //Partner Fund
                        tsbonus = 0,                  //Bonus
                        tstype = sType,               //Type: Must be 'E','I','C','O','A' to be displayed; see uspLW1190_Attys
                        tstatus = "2",                //Rank
                        tsaudit_op = ntID,            //Modified by
                        LastModified = DateTime.Now   //Last Modifed
                     };

                     using (var ctx = new DBContext())
                     {
                        ctx.Attorneys.Add(atty);
                        ctx.SaveChanges();

                        //ctx.LogUser(ntID, Global.REPORT_ID);
                     }

                     Debug.WriteLine("grdAtty_ItemCommand --> ID:{0}, Location:{1}, Last:{2}, First:{3}, Title:{4}", item["AttyID"].Text, item["Loc"].Text, item["LastName"].Text, item["FirstName"].Text, item["Title"].Text);

                     //http://www.telerik.com/help/aspnet-ajax/grid-operate-with-filter-expression-manually.html
                     //Need to set [grdAtty.EnableLinqExpressions = false;] ELSE have to set 
                     //[grdAtty.MasterTableView.FilterExpression = "(it["Atty ID"].ToString().ToUpper().Contains("04819".ToUpper()))";]

                     //grdAtty.MasterTableView.FilterExpression = "([Atty ID] LIKE \'%" + item["AttyID"].Text + "%\')";
                     grdAtty.MasterTableView.FilterExpression = "([Atty ID] = \'" + item["AttyID"].Text + "\')";        //"([Atty ID] = '04592')"

                     GridColumn column = grdAtty.MasterTableView.GetColumnSafe("AttyID");
                     column.CurrentFilterFunction = GridKnownFunction.EqualTo;
                     column.CurrentFilterValue = item["AttyID"].Text;

                     grdAtty.MasterTableView.Rebind();

                     ResetAttyInfo();
                     break;
                  }
               }

               break;
            case RadGrid.DeleteCommandName:
               GridEditableItem editItem = e.Item as GridEditableItem;
               var pId = editItem.GetDataKeyValue("Atty ID").ToString();
               //OR e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Atty ID"]

               using (var ctx = new DBContext())
               {
                  var atty = ctx.Attorneys.Find(pId);
                  // *** For cascade delete, explicitly load committees & salaries related to a given atty. ***
                  //ctx.Entry(atty).Collection(c => c.Committees).Load();    
                  //ctx.Entry(atty).Collection(s => s.Salaries).Load();
                  ctx.Entry(atty).Collection("Committees").Load();
                  ctx.Entry(atty).Collection("Salaries").Load();

                  ctx.Attorneys.Remove(atty);
                  ctx.SaveChanges();

                  //ctx.LogUser(ntID, Global.REPORT_ID);
               }

               //Clear filters
               foreach (GridColumn col in grdAtty.MasterTableView.Columns)
               {
                  col.CurrentFilterFunction = GridKnownFunction.NoFilter;
                  col.CurrentFilterValue = string.Empty;
               }
               grdAtty.MasterTableView.FilterExpression = string.Empty;
               grdAtty.MasterTableView.Rebind();

               ResetAttyInfo();
               break;
         }
      }