コード例 #1
0
ファイル: CommDal.cs プロジェクト: jjg0519/OA
        //public bool Delete(TEntity entity)
        //{
        //    try
        //    {
        //        base.Delete(entity);
        //        return true;
        //    }
        //    catch (Exception ex)
        //    {
        //        return false;
        //        throw (ex);
        //    }
        //}

        /// <summary>
        /// 修改实体审核状态
        /// </summary>
        /// <param name="strEntityName">实体名</param>
        /// <param name="EntityKeyName">主键名</param>
        /// <param name="EntityKeyValue">主键值</param>
        /// <param name="CheckState">审核状态</param>
        public int UpdateCheckState(string strEntityName, string EntityKeyName, string EntityKeyValue, string CheckState)
        {
            int    IntReturn = 0;
            string qualifiedEntitySetName         = ConfigurationManager.AppSettings["DBContextName"] + ".";
            Dictionary <object, object> Prameters = new Dictionary <object, object>();

            Prameters.Add("CHECKSTATE", CheckState);
            try
            {
                System.Data.EntityKey entityKey = new System.Data.EntityKey(qualifiedEntitySetName + strEntityName, EntityKeyName, EntityKeyValue);
                object obj = GetObjectByEntityKey(entityKey);
                if (obj != null)
                {
                    Type a = obj.GetType();

                    PropertyInfo[] infos = a.GetProperties();
                    foreach (PropertyInfo prop in infos)
                    {
                        if (Prameters.ContainsKey(prop.Name))
                        {
                            prop.SetValue(obj, Prameters[prop.Name], null);
                        }
                    }
                    IntReturn = base.Update(obj);
                }
            }
            catch (Exception ex)
            {
                Tracer.Debug("手机审单调用了" + strEntityName + "表单ID为:" + EntityKeyValue + "错误信息为:" + System.DateTime.Now.ToString() + ex.ToString());
                throw (ex);
            }
            return(IntReturn);
        }
コード例 #2
0
    protected void EntityDataSourceItems_Updating(object sender, EntityDataSourceChangingEventArgs e)
    {
        Entidades.Plantilla ItemPlantilla = (Entidades.Plantilla)e.Entity;

        long id = Convert.ToInt64(ViewState["IdRol"]);

        IEnumerable <KeyValuePair <string, object> > entityKeyValues =
            new KeyValuePair <string, object>[] {
            new KeyValuePair <string, object>("IdSegRol", id)
        };

        System.Data.EntityKey key  = new System.Data.EntityKey("EntidadesConosud.SegRol", entityKeyValues);
        Entidades.SegRol      _rol = (Entidades.SegRol)e.Context.GetObjectByKey(key);
        ItemPlantilla.RolesPlanilla.Load();

        if (ItemPlantilla.RolesPlanilla.Count == 0)
        {
            Entidades.RolesPlanilla rolP = new Entidades.RolesPlanilla();
            rolP.Plantilla = ItemPlantilla;
            rolP.SegRol    = _rol;
            e.Context.AddObject("EntidadesConosud.RolesPlanilla", rolP);
        }
        else
        {
            ItemPlantilla.RolesPlanilla.First().SegRol = _rol;
        }

        e.Context.SaveChanges();
    }
コード例 #3
0
        /// <summary>
        /// 手动更新实体属性
        /// </summary>
        /// <param name="strEntityName">实体名称,需要带DataCotext前缀</param>
        /// <param name="EntityKeyName">实体主键</param>
        /// <param name="EntityKeyValue">实体主键值</param>
        /// <param name="CheckState">需要更新的实体属性和值的集合</param>
        public void UpdateCheckState(string strEntityName, string EntityKeyName, string EntityKeyValue, Dictionary <object, object> Prameters)
        {
            try
            {
                System.Data.EntityKey entityKey = new System.Data.EntityKey(strEntityName, EntityKeyName, EntityKeyValue);
                object obj = null;
                //var q=from a
                lbc.TryGetObjectByKey(entityKey, out obj);
                if (obj != null)
                {
                    Type a = obj.GetType();

                    PropertyInfo[] infos = a.GetProperties();
                    foreach (PropertyInfo prop in infos)
                    {
                        if (Prameters.ContainsKey(prop.Name))
                        {
                            prop.SetValue(obj, Prameters[prop.Name], null);
                        }
                    }
                    // context.Update(entity);
                    lbc.ApplyPropertyChanges(strEntityName, obj);
                    lbc.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Tracer.Debug(ex.Message);
                throw (ex);
            }
        }
コード例 #4
0
        //static healthychefEntities cont
        //{
        //    get { return healthychefEntities.Default; }
        //}

        public void Save()
        {
            try
            {
                using (var cont = new healthychefEntities())
                {
                    System.Data.EntityKey key = cont.CreateEntityKey("hccCartItemCalendars", this);
                    object oldObj;

                    if (cont.TryGetObjectByKey(key, out oldObj))
                    {
                        cont.ApplyCurrentValues("hccCartItemCalendars", this);
                    }
                    else
                    {
                        cont.hccCartItemCalendars.AddObject(this);
                    }

                    cont.SaveChanges();
                    //cont.Refresh(RefreshMode.StoreWins, this);
                }
            }
            catch
            {
                throw;
            }
        }
コード例 #5
0
        public void Delete()
        {
            try
            {
                using (var cont = new healthychefEntities())
                {
                    System.Data.EntityKey key = cont.CreateEntityKey("hccCartItemCalendars", this);
                    object originalItem       = null;

                    if (cont.TryGetObjectByKey(key, out originalItem))
                    {
                        hccCartItemCalendar item = cont.hccCartItemCalendars
                                                   .Where(a => a.CartCalendarID == this.CartCalendarID).SingleOrDefault();

                        if (item != null)
                        {
                            cont.hccCartItemCalendars.DeleteObject(item);
                            cont.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #6
0
        private void btnREMOVE_Click(object sender, EventArgs e)
        {
            if (_context.Shifts.Where(w => w.ShiftName == cboxSHIFTNAMEW.Text).Select(s => s.ShiftID).Count() == 0 ||
                _context.Cardholders.Where(w => w.Name == cboxCARDHOLDER.Text).Select(s => s.CardholderID).Count() == 0)
            {
            }
            else
            {
                SHIFTID      = _context.Shifts.Where(w => w.ShiftName == cboxSHIFTNAMEW.Text).Select(s => s.ShiftID).First();
                CARDHOLDERID = _context.Cardholders.Where(w => w.Name == cboxCARDHOLDER.Text).Select(s => s.CardholderID).First();

                try
                {
                    //var shiftQuery = from i in _context.Shifts
                    //                 where i.ShiftName == cboxSHIFTNAME.Text
                    //                 select new { i.ShiftID };
                    //foreach (var item in shiftQuery)
                    //{
                    //    SHIFTID = item.ShiftID;
                    //}
                    if (SHIFTID == 0)
                    {
                    }
                    else
                    {
                        if (MessageBox.Show("Do you really want to remove shift from selected worker?", "Delete",
                                            MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                        {
                            System.Data.EntityKey cardholdershiftKey = new System.Data.EntityKey("MojaEntities.CardholderShifts", "CardholderShiftID", CARDHOLDERSHIFTID);
                            var cardholdershiftDelete = _context.GetObjectByKey(cardholdershiftKey);
                            _context.DeleteObject(cardholdershiftDelete);
                            _context.SaveChanges();


                            MessageBox.Show("You have successfully removed shift from selected worker!", "Success",
                                            MessageBoxButtons.OK, MessageBoxIcon.Asterisk);


                            if (cboxSHIFTNAME.Text != "")
                            {
                                cboxSHIFTNAME.DataSource = _context.Shifts.ToList();
                            }

                            ListSHIFT = null;
                            ListSHIFT = _context.Shifts.ToList();

                            cboxSHIFTNAMEW.DataSource = _context.Shifts.ToList();
                            cboxSHIFTNAME.Text        = "";
                            cboxSHIFTNAMEW.Text       = "";
                            cboxCARDHOLDER.Text       = "";
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Delete operation was not successful. Please, contact your administrator.", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #7
0
        private void btnRemoveReligion_Click(object sender, EventArgs e)
        {
            try
            {
                if (_context.Religions.Where(j => j.Name == cbxReligionName.Text).Select(s => s.ReligionID).Count() != 0)
                {
                    if (MessageBox.Show("Do you really want to delete religion?", "Delete",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        RELIGIONID = _context.Religions.Where(j => j.Name == cbxReligionName.Text).Select(s => s.ReligionID).First();

                        System.Data.EntityKey religionKey = new System.Data.EntityKey("MojaEntities.Religions", "ReligionID", RELIGIONID);
                        var religionDelete = _context.GetObjectByKey(religionKey);
                        _context.DeleteObject(religionDelete);
                        _context.SaveChanges();

                        MessageBox.Show("You have successfully deleted religion from database.", "Successful",
                                        MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        cbxReligionName.Text = "";

                        cbxReligionName.DataSource = _context.Religions.OrderBy(o => o.Name).ToList();
                    }
                }
            }
            catch
            {
                MessageBox.Show("Delete operation was not successful. Please, contact your administrator.", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #8
0
        //static healthychefEntities cont
        //{
        //    get
        //    {
        //        if (System.Web.HttpContext.Current != null)
        //            return healthychefEntities.Default;
        //        else
        //            return new healthychefEntities(WebConfigurationManager.ConnectionStrings["healthychefEntities"].ConnectionString);
        //    }
        //}

        /// <summary>
        /// Saves this user to the database.  If this user hasn't been created yet
        /// this user will be added to the database.
        /// </summary>
        public void Save()
        {
            try
            {
                using (var cont = new healthychefEntities(WebConfigurationManager.ConnectionStrings["healthychefEntities"].ConnectionString))
                {
                    System.Data.EntityKey key = cont.CreateEntityKey("hccUserProfiles", this);
                    object oldObj;

                    if (cont.TryGetObjectByKey(key, out oldObj))
                    {
                        cont.ApplyCurrentValues("hccUserProfiles", this);
                    }
                    else
                    {
                        cont.hccUserProfiles.AddObject(this);
                    }

                    cont.SaveChanges();
                    //cont.Refresh(System.Data.Objects.RefreshMode.StoreWins, this);
                }
            }
            catch
            {
                throw;
            }
        }
コード例 #9
0
        private void btnRemoveReligionDates_Click(object sender, EventArgs e)
        {
            try
            {
                RELIGIONID = _context.Religions.Where(j => j.Name == cbxReligionName.Text).Select(s => s.ReligionID).First();
                if (_context.ReligionHolidays.Where(j => (j.ReligionID == RELIGIONID) && j.ReligionHolidaysDate == dateTimePicker1.Value.Date).Select(s => s.ReligionHolidaysDate).Count() != 0)
                {
                    if (MessageBox.Show("Do you really want to delete this date?", "Delete",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        RELIGIONHOLIDAYSID = _context.ReligionHolidays.Where(j => (j.ReligionID == RELIGIONID) && j.ReligionHolidaysDate == dateTimePicker1.Value.Date).Select(s => s.ReligionHolidaysID).First();
                        System.Data.EntityKey religionKey = new System.Data.EntityKey("MojaEntities.ReligionHolidays", "ReligionHolidaysID", RELIGIONHOLIDAYSID);
                        var religionHolidayDelete         = _context.GetObjectByKey(religionKey);
                        _context.DeleteObject(religionHolidayDelete);
                        _context.SaveChanges();

                        MessageBox.Show("You have successfully deleted religion from database.", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        TOTALRELIGIONDAYS  = _context.Religions.Where(w => w.Name == cbxReligionName.Text).Select(s => s.TotalReligiousDays).First();
                        TOTALRELIGIONDAYS -= 1;
                        var Religion = _context.Religions.First(k => k.ReligionID == RELIGIONID);
                        Religion.TotalReligiousDays = TOTALRELIGIONDAYS;
                        txtTotalReligionDays.Text   = "" + TOTALRELIGIONDAYS.ToString();
                        _context.SaveChanges();
                        RefreshDates();
                    }
                }
            }
            catch
            {
                MessageBox.Show("Delete operation was not successful. Please, contact your administrator.", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #10
0
        //static healthychefEntities cont
        //{
        //    get { return healthychefEntities.Default; }
        //}

        public void Save()
        {
            try
            {
                using (var cont = new healthychefEntities())
                {
                    System.Data.EntityKey key = cont.CreateEntityKey("hccMenuItemIngredients", this);
                    object oldObj;

                    if (cont.TryGetObjectByKey(key, out oldObj))
                    {
                        cont.ApplyCurrentValues("hccMenuItemIngredients", this);
                    }
                    else
                    {
                        cont.hccMenuItemIngredients.AddObject(this);
                    }

                    cont.SaveChanges();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #11
0
        private void btnREMOVE_Click(object sender, EventArgs e)
        {
            try
            {
                if (_context.Firms.Where(j => j.Name == cboxFIRM.Text).Select(s => s.FirmID).Count() != 0)
                {
                    if (MessageBox.Show("Do you really want to delete shift?", "Delete",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        FIRMID = _context.Firms.Where(j => j.Name == cboxFIRM.Text).Select(s => s.FirmID).First();

                        System.Data.EntityKey firmKey = new System.Data.EntityKey("MojaEntities.Firms", "FirmID", FIRMID);
                        var firmDelete = _context.GetObjectByKey(firmKey);
                        _context.DeleteObject(firmDelete);
                        _context.SaveChanges();

                        MessageBox.Show("You have successfully deleted firm from database.", "Successful",
                                        MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                        cboxFIRM.Text = "";

                        cboxFIRM.DataSource = _context.Firms.OrderBy(o => o.Name).ToList();
                    }
                }
            }
            catch
            {
                MessageBox.Show("Delete operation was not successful. Please, contact your administrator.", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #12
0
        public object GetObjectByID <TEntity>(string ObjectKeyName, string ObjectKeyValue)
        {
            string EntityName = typeof(TEntity).Name;

            EntityName = DALFacoty.DBContextName + EntityName;
            System.Data.EntityKey entityKey = new System.Data.EntityKey(EntityName, ObjectKeyName, ObjectKeyValue);
            object entity = lbc.GetObjectByEntityKey(entityKey);

            return(entity);
        }
コード例 #13
0
        private void btnDELETE_Click(object sender, EventArgs e)
        {
            if (_context.Shifts.Where(w => w.ShiftName == cboxSHIFTNAME.Text).Select(s => s.ShiftID).Count() == 0)
            {
            }
            else
            {
                SHIFTID = _context.Shifts.Where(w => w.ShiftName == cboxSHIFTNAME.Text).Select(s => s.ShiftID).First();


                try
                {
                    var shiftQuery = from i in _context.Shifts
                                     where i.ShiftName == cboxSHIFTNAME.Text
                                     select new { i.ShiftID };
                    foreach (var item in shiftQuery)
                    {
                        SHIFTID = item.ShiftID;
                    }
                    if (SHIFTID == 0)
                    {
                    }
                    else
                    {
                        if (MessageBox.Show("Do you really want to delete shift?", "Delete",
                                            MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                        {
                            System.Data.EntityKey shiftsKey = new System.Data.EntityKey("MojaEntities.Shifts", "ShiftID", SHIFTID);
                            var shiftDelete = _context.GetObjectByKey(shiftsKey);
                            _context.DeleteObject(shiftDelete);
                            _context.SaveChanges();


                            MessageBox.Show("You have successfully deleted assigned shift!", "Success",
                                            MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                            ListSHIFT = null;
                            ListSHIFT = _context.Shifts.ToList();
                            cboxSHIFTNAME.DataSource  = _context.Shifts.ToList();
                            cboxSHIFTNAMEW.DataSource = _context.Shifts.ToList();
                            cboxSHIFTNAME.Text        = "";
                            cboxSHIFTNAMEW.Text       = "";
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Delete operation was not successful. Please, contact your administrator.", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #14
0
        //public bool Delete(TEntity entity)
        //{
        //    try
        //    {
        //        base.Delete(entity);
        //        return true;
        //    }
        //    catch (Exception ex)
        //    {
        //        return false;
        //        throw (ex);
        //    }
        //}

        /// <summary>
        /// 修改实体审核状态
        /// </summary>
        /// <param name="strEntityName">实体名</param>
        /// <param name="EntityKeyName">主键名</param>
        /// <param name="EntityKeyValue">主键值</param>
        /// <param name="CheckState">审核状态</param>
        public int UpdateCheckState(string strEntityName, string EntityKeyName, string EntityKeyValue, string CheckState)
        {
            int    UpdateCont                     = 0;
            string qualifiedEntitySetName         = ConfigurationManager.AppSettings["DBContextName"] + ".";
            Dictionary <object, object> Prameters = new Dictionary <object, object>();

            if (!string.IsNullOrEmpty(CheckState))
            {
                Prameters.Add("CHECKSTATES", System.Convert.ToDecimal(CheckState));
            }
            try
            {
                Tracer.Debug("更新到了修改状态------------进入try");
                System.Data.EntityKey entityKey = new System.Data.EntityKey(qualifiedEntitySetName + strEntityName, EntityKeyName, EntityKeyValue);
                object obj = GetObjectByEntityKey(entityKey);
                if (obj != null)
                {
                    Type a = obj.GetType();

                    PropertyInfo[] infos = a.GetProperties();
                    foreach (PropertyInfo prop in infos)
                    {
                        if (Prameters.ContainsKey(prop.Name))
                        {
                            prop.SetValue(obj, Prameters[prop.Name], null);
                        }
                    }
                    UpdateCont = base.Update(obj);
                    Tracer.Debug("更新到了修改状态" + UpdateCont.ToString());
                }
            }
            catch (Exception ex)
            {
                Tracer.Debug("捕捉到异常信息Message:" + ex.Message + ",Source:" + ex.Source + ",StackTrace:" + ex.StackTrace + ",DateTime:" + System.DateTime.Now.ToString());
                //throw (ex);
            }
            return(UpdateCont);
        }
コード例 #15
0
        public static void Import(out int count)
        {
            using (StreamWriter writer = new StreamWriter(@"C:\HCCCustomerOutput.txt"))
            {
                Console.SetOut(writer);

                count = 0;
                List <string> errorReport = new List <string>();

                try
                {
                    List <ImportedCustomer> impCusts = GetAll();

                    foreach (ImportedCustomer impCust in impCusts)
                    {
                        Console.WriteLine(count + " : ");
                        if (!impCust.IsValid)
                        {
                            impCust.Email = "admin" + count.ToString() + "@healthychefcreations.com";
                        }
                        else if (impCust.Email.Contains("info@healthychef") || impCust.Email.Contains("thehealthyassistant@earthlink"))
                        {
                            impCust.Email = "admin" + count.ToString() + "@healthychefcreations.com";
                        }

                        Console.WriteLine(impCust.Email);

                        if (impCust.IsValid)
                        {
                            count++;

                            string         userName    = impCust.Email.Trim().Split('@')[0] + DateTime.Now.ToString("yyyyMMddHHmmtt");
                            string         password    = OrderNumberGenerator.GenerateOrderNumber("?#?#?#?#");
                            string         aspUserName = Membership.GetUserNameByEmail(impCust.Email.Trim());
                            MembershipUser newUser     = null;

                            if (!string.IsNullOrWhiteSpace(aspUserName))
                            {
                                newUser = Membership.GetUser(aspUserName);
                            }

                            MembershipCreateStatus createResult = MembershipCreateStatus.UserRejected;

                            if (newUser == null)
                            {
                                newUser = Membership.CreateUser(userName, password, impCust.Email.Trim(), "import", "import", true, out createResult);

                                if (newUser != null)
                                {
                                    Console.WriteLine(newUser.UserName + "New user.");
                                }
                            }
                            else
                            {
                                Console.WriteLine(newUser.UserName + " Existing user.");
                                createResult = MembershipCreateStatus.Success;
                            }

                            if (newUser != null)
                            {
                                if (createResult == MembershipCreateStatus.Success)
                                {
                                    //Assign Customer role to newUser
                                    try
                                    {
                                        if (!Roles.IsUserInRole(newUser.UserName, "Customer"))
                                        {
                                            Roles.AddUserToRole(newUser.UserName, "Customer");
                                            Console.WriteLine(newUser.UserName + " Role assigned.");
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(newUser.UserName + " =Assign role failed." + ex.Message + ex.StackTrace);
                                    }
                                    //Send E-mail notification to account user
                                    //HealthyChef.Email.EmailController ec = new HealthyChef.Email.EmailController();
                                    //ec.SendMail_NewUserConfirmation(email, password);

                                    //Create a Healthy Chef profile for this new user
                                    hccUserProfile newProfile = hccUserProfile.GetBy((Guid)newUser.ProviderUserKey).SingleOrDefault(a => !a.ParentProfileID.HasValue);

                                    if (newProfile == null)
                                    {
                                        try
                                        {
                                            newProfile = new hccUserProfile
                                            {
                                                MembershipID   = (Guid)newUser.ProviderUserKey,
                                                CreatedBy      = (Membership.GetUser() == null ? Guid.Empty : (Guid)Membership.GetUser().ProviderUserKey),
                                                CreatedDate    = DateTime.Now,
                                                AccountBalance = 0.00m,
                                                IsActive       = true,
                                                FirstName      = impCust.FirstName.Trim(),
                                                LastName       = impCust.LastName.Trim(),
                                                ProfileName    = impCust.FirstName.Trim()
                                            };

                                            //Save all hccProfile information
                                            using (var cont = new healthychefEntities())
                                            {
                                                System.Data.EntityKey key = cont.CreateEntityKey("hccUserProfiles", newProfile);
                                                object oldObj;

                                                if (cont.TryGetObjectByKey(key, out oldObj))
                                                {
                                                    cont.ApplyCurrentValues("hccUserProfiles", newProfile);
                                                }
                                                else
                                                {
                                                    cont.hccUserProfiles.AddObject(newProfile);
                                                }

                                                cont.SaveChanges();
                                            }
                                            //cont.Refresh(System.Data.Objects.RefreshMode.StoreWins, newProfile);
                                            Console.WriteLine(newUser.UserName + " New profile.");
                                        }
                                        catch (Exception)
                                        {
                                            Console.WriteLine("=" + newUser.UserName + " Save Profile failed.");
                                        }
                                    }
                                    else
                                    {
                                        Console.WriteLine(newUser.UserName + " Existing profile.");
                                        createResult = MembershipCreateStatus.Success;
                                    }

                                    if (newProfile != null && newProfile.UserProfileID > 0)
                                    {
                                        if (impCust.OtherDeliveryInfo != null && !string.IsNullOrWhiteSpace(impCust.OtherDeliveryInfo))
                                        {
                                            hccUserProfileNote shipNote = new hccUserProfileNote
                                            {
                                                DateCreated   = DateTime.Now,
                                                DisplayToUser = false,
                                                UserProfileID = newProfile.UserProfileID,
                                                IsActive      = true,
                                                Note          = impCust.OtherDeliveryInfo,
                                                NoteTypeID    = (int)Enums.UserProfileNoteTypes.ShippingNote
                                            };

                                            using (var cont = new healthychefEntities())
                                            {
                                                EntityKey key          = cont.CreateEntityKey("hccUserProfileNotes", shipNote);
                                                object    originalItem = null;

                                                if (cont.TryGetObjectByKey(key, out originalItem))
                                                {
                                                    cont.ApplyCurrentValues(key.EntitySetName, shipNote);
                                                }
                                                else
                                                {
                                                    cont.hccUserProfileNotes.AddObject(shipNote);
                                                }

                                                cont.SaveChanges();
                                            }
                                        }

                                        if (impCust.HowDidYouHear != null && !string.IsNullOrWhiteSpace(impCust.HowDidYouHear))
                                        {
                                            hccUserProfileNote hearNote = new hccUserProfileNote
                                            {
                                                DateCreated   = DateTime.Now,
                                                DisplayToUser = false,
                                                UserProfileID = newProfile.UserProfileID,
                                                IsActive      = true,
                                                Note          = impCust.HowDidYouHear,
                                                NoteTypeID    = (int)Enums.UserProfileNoteTypes.GeneralNote
                                            };

                                            using (var cont = new healthychefEntities())
                                            {
                                                EntityKey key          = cont.CreateEntityKey("hccUserProfileNotes", hearNote);
                                                object    originalItem = null;

                                                if (cont.TryGetObjectByKey(key, out originalItem))
                                                {
                                                    cont.ApplyCurrentValues(key.EntitySetName, hearNote);
                                                }
                                                else
                                                {
                                                    cont.hccUserProfileNotes.AddObject(hearNote);
                                                }

                                                cont.SaveChanges();
                                            }
                                        }

                                        try
                                        {
                                            //save Shipping Address
                                            hccAddress shipAddr = null;

                                            if (newProfile.ShippingAddressID.HasValue)
                                            {
                                                shipAddr = hccAddress.GetById(newProfile.ShippingAddressID.Value);
                                            }

                                            if (shipAddr != null)
                                            {
                                                try
                                                {
                                                    newProfile.ShippingAddressID = null;
                                                    //Save all hccProfile information
                                                    using (var cont = new healthychefEntities())
                                                    {
                                                        System.Data.EntityKey key1 = cont.CreateEntityKey("hccUserProfiles", newProfile);
                                                        object oldObj1;

                                                        if (cont.TryGetObjectByKey(key1, out oldObj1))
                                                        {
                                                            cont.ApplyCurrentValues("hccUserProfiles", newProfile);
                                                        }
                                                        else
                                                        {
                                                            cont.hccUserProfiles.AddObject(newProfile);
                                                        }
                                                        cont.SaveChanges();
                                                    }
                                                    //cont.Refresh(System.Data.Objects.RefreshMode.StoreWins, newProfile);
                                                    using (var cont = new healthychefEntities())
                                                    {
                                                        EntityKey key          = cont.CreateEntityKey("hccAddresses", shipAddr);
                                                        object    originalItem = null;

                                                        if (cont.TryGetObjectByKey(key, out originalItem))
                                                        {
                                                            cont.AttachTo(shipAddr.EntityKey.EntitySetName, shipAddr);
                                                            cont.DeleteObject(shipAddr);
                                                        }
                                                        cont.SaveChanges();
                                                    }

                                                    shipAddr = null;
                                                }
                                                catch (Exception ex)
                                                {
                                                    Console.WriteLine(newUser.UserName + " =Delete old shipping address failed." + ex.Message + ex.StackTrace);
                                                }
                                            }

                                            if (shipAddr == null)
                                            {
                                                shipAddr = new hccAddress();
                                            }

                                            if (impCust.ShippingAddress1 != null)
                                            {
                                                shipAddr.Address1 = (string.IsNullOrWhiteSpace(impCust.ShippingAddress1) ? "" : impCust.ShippingAddress1.Trim());
                                            }
                                            else
                                            {
                                                shipAddr.Address1 = "";
                                            }

                                            if (impCust.ShippingAddress2 != null)
                                            {
                                                shipAddr.Address2 = (string.IsNullOrWhiteSpace(impCust.ShippingAddress2) ? "" : impCust.ShippingAddress2.Trim());
                                            }
                                            else
                                            {
                                                shipAddr.Address2 = "";
                                            }

                                            if (impCust.ShippingAddress3 != null)
                                            {
                                                shipAddr.Address2 += " " + (string.IsNullOrWhiteSpace(impCust.ShippingAddress3) ? "" : impCust.ShippingAddress3.Trim());
                                            }

                                            shipAddr.AddressTypeID = (int)Enums.AddressType.Shipping;

                                            if (impCust.ShippingCity != null)
                                            {
                                                shipAddr.City = (string.IsNullOrWhiteSpace(impCust.ShippingCity) ? "" : impCust.ShippingCity.Trim());
                                            }
                                            else
                                            {
                                                shipAddr.City = "";
                                            }

                                            shipAddr.Country = "US";

                                            if (impCust.FirstName != null)
                                            {
                                                shipAddr.FirstName = (string.IsNullOrWhiteSpace(impCust.FirstName) ? "" : impCust.FirstName.Trim());
                                            }
                                            else
                                            {
                                                shipAddr.FirstName = "";
                                            }

                                            shipAddr.IsBusiness = false;

                                            if (impCust.LastName != null)
                                            {
                                                shipAddr.LastName = (string.IsNullOrWhiteSpace(impCust.LastName) ? "" : impCust.LastName.Trim());
                                            }
                                            else
                                            {
                                                shipAddr.LastName = "";
                                            }

                                            if (impCust.Phone1 != null)
                                            {
                                                shipAddr.Phone = (string.IsNullOrWhiteSpace(impCust.Phone1) ? "" : impCust.Phone1.Trim());
                                            }
                                            else
                                            {
                                                shipAddr.Phone = "";
                                            }

                                            if (impCust.Phone1Ext != null)
                                            {
                                                shipAddr.Phone += (string.IsNullOrWhiteSpace(impCust.Phone1Ext.Trim()) ? "" : " x" + impCust.Phone1Ext.Trim());
                                            }
                                            else
                                            {
                                                shipAddr.Phone = "";
                                            }

                                            if (impCust.ShippingZipCode != null)
                                            {
                                                shipAddr.PostalCode = (string.IsNullOrWhiteSpace(impCust.ShippingZipCode) ? "" : impCust.ShippingZipCode.Trim());
                                            }
                                            else
                                            {
                                                shipAddr.PostalCode = "";
                                            }

                                            if (impCust.ShippingState != null)
                                            {
                                                shipAddr.State = (string.IsNullOrWhiteSpace(impCust.ShippingState) ? "" : impCust.ShippingState.Trim());
                                            }
                                            else
                                            {
                                                shipAddr.State = "";
                                            }

                                            if (impCust.ShipMethod == null)
                                            {
                                                shipAddr.DefaultShippingTypeID = (int)Enums.DeliveryTypes.Delivery;
                                            }
                                            else if (impCust.ShipMethod.Trim() == "F")
                                            {
                                                shipAddr.DefaultShippingTypeID = (int)Enums.DeliveryTypes.Delivery;
                                            }
                                            else if (impCust.ShipMethod.Trim() == "P")
                                            {
                                                shipAddr.DefaultShippingTypeID = (int)Enums.DeliveryTypes.LocalPickUp;
                                            }
                                            else if (impCust.ShipMethod.Trim() == "D")
                                            {
                                                shipAddr.DefaultShippingTypeID = (int)Enums.DeliveryTypes.LocalDelivery;
                                            }
                                            else
                                            {
                                                shipAddr.DefaultShippingTypeID = (int)Enums.DeliveryTypes.Delivery;
                                            }

                                            if (shipAddr != null)
                                            {
                                                try
                                                {
                                                    using (var cont = new healthychefEntities())
                                                    {
                                                        EntityKey key          = cont.CreateEntityKey("hccAddresses", shipAddr);
                                                        object    originalItem = null;

                                                        if (cont.TryGetObjectByKey(key, out originalItem))
                                                        {
                                                            cont.hccAddresses.ApplyCurrentValues((hccAddress)originalItem);
                                                        }
                                                        else
                                                        {
                                                            cont.hccAddresses.AddObject(shipAddr);
                                                        }

                                                        cont.SaveChanges();
                                                    }
                                                    //cont.Refresh(System.Data.Objects.RefreshMode.StoreWins, shipAddr);
                                                }
                                                catch (Exception ex)
                                                {
                                                    Console.WriteLine(newUser.UserName + " =Shipping address save failed." + ex.Message + ex.StackTrace);
                                                }
                                            }

                                            if (shipAddr != null && shipAddr.AddressID > 0)
                                            {
                                                newProfile.ShippingAddressID = shipAddr.AddressID;
                                            }
                                            else
                                            {
                                                newProfile.ShippingAddressID = null;
                                            }

                                            using (var cont = new healthychefEntities())
                                            {
                                                System.Data.EntityKey upkey = cont.CreateEntityKey("hccUserProfiles", newProfile);
                                                object oldObj;

                                                if (cont.TryGetObjectByKey(upkey, out oldObj))
                                                {
                                                    cont.ApplyCurrentValues("hccUserProfiles", newProfile);
                                                }
                                                else
                                                {
                                                    cont.hccUserProfiles.AddObject(newProfile);
                                                }

                                                cont.SaveChanges();
                                            }

                                            Console.WriteLine(newUser.UserName + " Shipping address saved.");
                                        }
                                        catch (Exception ex)
                                        {
                                            Console.WriteLine(newUser.UserName + " =Shipping address not created." + ex.Message + ex.StackTrace);
                                        }
                                    }
                                    else
                                    {
                                        Console.WriteLine("User Profile for user: "******" ID not created.");
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("=New user for user: "******" not created.");
                                }
                            }
                            else
                            {
                                Console.WriteLine(createResult.ToString() + " : " + impCust.Email);
                            }
                        }
                        else
                        {
                            count++; Console.WriteLine("=Customer: " + impCust.FirstName + " " + impCust.LastName + " has no email address.");
                        }
                    }
                }
                catch (Exception ex) { Console.WriteLine("=" + ex.Message + " : " + ex.StackTrace); }
            }
        }
コード例 #16
0
        private void dgSICKLEAVE_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //SAVE BUTTON IN DATAGRIDVIEW
            if (e.ColumnIndex == 1)
            {
                DataGridViewRow row = this.dgSICKLEAVE.Rows[e.RowIndex];


                if (!row.IsNewRow)
                {
                    var      date        = row.Cells["Date"].Value;
                    DateTime dateTime    = Convert.ToDateTime(date);
                    int      SICKLEAVEID = Convert.ToInt16(row.Cells["SickLeaveIDCell"].Value);

                    if (_context.SickLeaves.Where(w => w.SickLeaveID == SICKLEAVEID).Select(s => s.SickLeaveID).Count() == 0)
                    {
                    }
                    else
                    {
                        if (_context.SickLeaves.Where(j => j.Date == dateTime && j.CardholderID == CARDHOLDERID).Select(s => s.SickLeaveID).Count() != 0)
                        {
                            MessageBox.Show("Save operation was not successful. Input date already exists.", "Error",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);


                            _context               = new MojaEntities();
                            ListaSICKLEAVE         = _context.SickLeaves.OrderBy(o => o.Date).ToList();
                            dgSICKLEAVE.DataSource = ListaSICKLEAVE.Where(j => j.CardholderID == CARDHOLDERID).ToList();
                        }
                        else
                        {
                            //SICKLEAVEID = _context.SickLeaves.Where(w => w.CardholderID == CARDHOLDERID && w.Date == dateTime).Select(s => s.SickLeaveID).First();
                            var leaveQuery    = _context.SickLeaves.Where(w => w.SickLeaveID == SICKLEAVEID).ToList();
                            var sickleavesave = leaveQuery[0];
                            sickleavesave.Date = Convert.ToDateTime(row.Cells["Date"].Value);

                            _context.SaveChanges();

                            MessageBox.Show("Sick leave date has been successfully changed.", "Successful",
                                            MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        }
                    }
                }
            }

            //BRISANJE SELEKTOVANOG REDA

            if (e.ColumnIndex == 2)
            {
                try
                {
                    DataGridViewRow row = this.dgSICKLEAVE.Rows[e.RowIndex];

                    if (!row.IsNewRow)
                    {
                        var      date     = row.Cells["Date"].Value;
                        DateTime dateTime = Convert.ToDateTime(date);

                        if (_context.SickLeaves.Where(w => w.Date == dateTime).Select(s => s.SickLeaveID).Count() == 0)
                        {
                        }
                        else
                        {
                            if (MessageBox.Show("Do you really want to delete sick leave date?", "Delete",
                                                MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                            {
                                SICKLEAVEID = _context.SickLeaves.Where(w => w.Date == dateTime && w.CardholderID == CARDHOLDERID).Select(s => s.SickLeaveID).First();

                                System.Data.EntityKey sickleaveKey = new System.Data.EntityKey("MojaEntities.SickLeaves", "SickLeaveID", SICKLEAVEID);
                                var SickLeaveDelete = _context.GetObjectByKey(sickleaveKey);
                                _context.DeleteObject(SickLeaveDelete);
                                _context.SaveChanges();

                                MessageBox.Show("Contract has been successfully deleted!", "Success",
                                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                                ListaSICKLEAVE         = _context.SickLeaves.OrderBy(o => o.Date).ToList();
                                dgSICKLEAVE.DataSource = ListaSICKLEAVE.Where(j => j.CardholderID == CARDHOLDERID).ToList();
                            }
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Delete operation was not successful. Please, contact your administrator.", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #17
0
        /// <summary>
        /// Deletes the hccCartItem object.
        /// </summary>
        /// <exception cref="System.Exception">re-thrown exception</exception>
        /// <returns>Returns void.</returns>
        public void Delete(List <hccRecurringOrder> recurringItemList)
        {
            try
            {
                using (var cont = new healthychefEntities())
                {
                    System.Data.EntityKey key = cont.CreateEntityKey("hccCartItems", this);
                    object originalItem       = null;

                    if (cont.TryGetObjectByKey(key, out originalItem))
                    {
                        hccCartItem cartItem = (hccCartItem)originalItem;

                        if (((Enums.CartItemType)cartItem.ItemTypeID) == Enums.CartItemType.AlaCarte)
                        {
                            List <hccCartItemMealPreference> prefs = hccCartItemMealPreference.GetBy(cartItem.CartItemID);
                            prefs.ForEach(a => a.Delete());
                        }
                        else if (((Enums.CartItemType)cartItem.ItemTypeID) == Enums.CartItemType.DefinedPlan)
                        {
                            List <hccCartItemMealPreference> prefs = hccCartItemMealPreference.GetBy(cartItem.CartItemID);
                            prefs.ForEach(a => a.Delete());

                            List <hccCartItemCalendar> cartCals = hccCartItemCalendar.GetByCartItemID(cartItem.CartItemID);

                            cartCals.ForEach(delegate(hccCartItemCalendar cartCal)
                            {
                                List <hccCartDefaultMenuException> menuExs = hccCartDefaultMenuException.GetBy(cartCal.CartCalendarID);
                                foreach (var defaultmenu in menuExs)
                                {
                                    int defaultmenexceptionid = defaultmenu.DefaultMenuExceptID;
                                    var cartDefaultMenuExPref = hccCartDefaultMenuExPref.GetBy(defaultmenexceptionid);
                                    if (cartDefaultMenuExPref.Count() > 0)
                                    {
                                        cartDefaultMenuExPref.ForEach(a => a.Delete());
                                    }
                                }
                                menuExs.ForEach(a => a.Delete());
                            });

                            cartCals.ForEach(delegate(hccCartItemCalendar cartCal)
                            {
                                cartCal.Delete();
                            });
                        }

                        if (HttpContext.Current.Session["id"] != null && HttpContext.Current.Session["meals"] != null)
                        {
                            cartItem.CartID        = (int)HttpContext.Current.Session["id"];
                            cartItem.NumberOfMeals = (int)HttpContext.Current.Session["meals"];
                        }
                        var hcccartMenuExPrefs = hccCartMenuExPref.GetByCartItem(cartItem.CartItemID);
                        if (hcccartMenuExPrefs.Count() > 0)
                        {
                            hcccartMenuExPrefs.ForEach(a => a.Delete());
                        }
                        cont.hccCartItems.DeleteObject(cartItem);
                        cont.SaveChanges();

                        // Check for recurring items
                        if (recurringItemList != null)
                        {
                            var itemDeleted = recurringItemList.Find(x => x.CartID == this.CartID && x.CartItemID == this.CartItemID);
                            recurringItemList.Remove(itemDeleted);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #18
0
        private void btnDELETE_Click(object sender, EventArgs e)
        {
            if (CARDHOLDERID == 0)
            {
                errorProvider1.SetError(cboxCARDHOLDER, "Please, choose the worker.");
                cboxCARDHOLDER.Focus();
                cboxCARDHOLDER.TextChanged += (s, ex) => { errorProvider1.SetError(cboxCARDHOLDER, ""); };
                return;
            }
            if (_context.Contracts.Where(j => j.CardholderID == CARDHOLDERID && j.ActiveState == true).Select(s => s.ContractID).Count() == 0)
            {
            }
            else
            {
                try
                {
                    if (MessageBox.Show("Do you really want to delete contract?", "Delete",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        CONTRACTID = _context.Contracts.Where(j => j.CardholderID == CARDHOLDERID && j.ActiveState == true).Select(s => s.ContractID).First();
                        double?b = _context.Contracts.Where(j => j.CardholderID == CARDHOLDERID && j.ActiveState == true).Select(s => s.FreeDays).First();

                        var k = new NonWorkingDay();
                        k.CardholderID = CARDHOLDERID;
                        k.TotalNWD     = a;
                        k.Description  = "Contract -" + b;
                        _context.NonWorkingDays.AddObject(k);
                        _context.SaveChanges();

                        var queryCARDHOLDER = _context.Cardholders.Where(j => j.CardholderID == CARDHOLDERID).ToList();
                        var CardholderVar   = queryCARDHOLDER[0];
                        CardholderVar.SumNWD = CardholderVar.SumNWD - b;
                        _context.SaveChanges();

                        txtTOTAL.Text = CardholderVar.SumNWD.ToString();
                        if (_context.Cardholders.Where(w => w.CardholderID == CARDHOLDERID).Select(s => s.SumNWD).First() is null)
                        {
                            txtTOTAL.Text = "";
                        }
                        else
                        {
                            txtTOTAL.Text = queryCARDHOLDER.First().SumNWD.ToString();
                        }
                        gbCONTRACT.BackColor = Color.FromArgb(255, 0, 0);

                        System.Data.EntityKey contractKey = new System.Data.EntityKey("MojaEntities.Contracts", "ContractID", CONTRACTID);
                        var ContractDelete = _context.GetObjectByKey(contractKey);
                        _context.DeleteObject(ContractDelete);
                        _context.SaveChanges();


                        MessageBox.Show("Contract has been successfully deleted!", "Success",
                                        MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                        cboxCARDHOLDER.Text  = "";
                        gbCONTRACT.BackColor = System.Drawing.SystemColors.ControlLightLight;
                    }
                }
                catch
                {
                    MessageBox.Show("Delete operation was not successful. Please, contact your administrator.", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }