Exemplo n.º 1
0
        private void oPERATORBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            TextEditCode.Focus();
            int contactID = 0;

            if (OperatorBindingSource.Current == null)
            {
                return;
            }
            GridViewOper.CloseEditor();
            if (GridViewAdditionalContacts.RowCount > 0)
            {
                contactID = (int)GridViewAdditionalContacts.GetFocusedRowCellValue("ID");
            }


            bool temp = newRec;

            if (checkForms())
            {
                contactNewRowRec = false;
                errorProvider1.Clear();
                setReadOnly(true);
                if (contactID == int.MaxValue)
                {
                    int newID   = (int)GridViewAdditionalContacts.GetFocusedRowCellValue("ID");
                    var values1 = from rec in context.RPTTYPE where rec.RecipientType == "Operator" select new { rec.CODE };
                    foreach (var result in values1)
                    {
                        if (globalRptType.Contains(result.CODE))
                        {
                            RptContact lol = new RptContact();
                            lol.Code       = TextEditCode.Text;
                            lol.RptType    = result.CODE;
                            lol.Contact_ID = newID;
                            context.RptContact.AddObject(lol);
                        }
                    }
                    globalRptType = string.Empty;
                    context.SaveChanges();
                }
                contactNewRowRec           = false;
                panelControlStatus.Visible = true;
                LabelStatus.Text           = "Record Saved";
                rowStatusSave          = new Timer();
                rowStatusSave.Interval = 3000;
                rowStatusSave.Start();
                rowStatusSave.Tick += TimedEventSave;
            }

            if (!temp && !modified)
            {
                context.Refresh(System.Data.Entity.Core.Objects.RefreshMode.StoreWins, (OPERATOR)OperatorBindingSource.Current);
            }
        }
Exemplo n.º 2
0
 private void GridViewAdditionalContacts_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
 {
     if (e.Column.FieldName == "RptType" && e.IsGetData)
     {
         CONTACT conRec = (CONTACT)e.Row;
         int     id     = conRec.ID;
         string  load   = String.Empty;
         if (id == int.MaxValue)
         {
             if (firstLoad == true)
             {
                 var values = from rec in context.RPTTYPE where rec.RecipientType == "Operator" select new { rec.CODE };
                 foreach (var result in values)
                 {
                     if (!string.IsNullOrWhiteSpace(load))
                     {
                         load += "," + result.CODE;
                     }
                     else
                     {
                         load += result.CODE;
                     }
                 }
                 globalRptType = load;
                 firstLoad     = false;
             }
             else
             {
                 load = globalRptType;
             }
         }
         else
         {
             var val = from rec in context.RptContact where rec.Contact_ID == id && rec.Code == TextEditCode.Text select new { rec.RptType };
             foreach (var result in val)
             {
                 if (!string.IsNullOrWhiteSpace(load))
                 {
                     load += "," + result.RptType;
                 }
                 else
                 {
                     load += result.RptType;
                 }
             }
         }
         e.Value = load;
     }
     if (e.Column.FieldName == "RptType" && e.IsSetData)
     {
         CONTACT conRec = (CONTACT)e.Row;
         int     id     = conRec.ID;
         if (id == int.MaxValue)
         {
             globalRptType = e.Value.ToString();
             modified      = true;
         }
         else
         {
             string value   = e.Value.ToString();
             var    results = from rptRec in context.RptContact where !value.Contains(rptRec.RptType) && rptRec.Code == TextEditCode.Text && rptRec.Contact_ID == id select rptRec;
             foreach (var result in results)
             {
                 context.RptContact.DeleteObject(result);
             }
             var val1 = (from rptRec in context.RPTTYPE
                         where value.Contains(rptRec.CODE)
                         select new { rptRec.CODE });
             foreach (var result1 in val1)
             {
                 if ((from rptCont in context.RptContact where rptCont.Contact_ID == id && rptCont.Code == TextEditCode.Text && rptCont.RptType == result1.CODE select new { rptCont.Code }).Count() == 0)
                 {
                     RptContact lol = new RptContact();
                     lol.Code       = TextEditCode.Text;
                     lol.RptType    = result1.CODE;
                     lol.Contact_ID = id;
                     context.RptContact.AddObject(lol);
                 }
             }
             context.SaveChanges();
         }
     }
 }