Beispiel #1
0
 private static string GetFormatedText(EF6.Workplace target, string[] textField, string textFormatString)
 {
     for (int i = 0; i < textField.Length; i++)
     {
         PropertyInfo pi = target.GetType().GetProperty(textField[i]);
         textFormatString = textFormatString.Replace("{" + i.ToString() + "}", pi != null ? pi.GetValue(target, null).ToString() : string.Empty);
     }
     return(textFormatString);
 }
Beispiel #2
0
        /// <summary>
        /// Get a EF6.Workplace object from the database using the given WorkplaceId
        /// </summary>
        /// <param name="workplaceId">The primary key value</param>
        /// <returns>A EF6.Workplace object</returns>
        public static EF6.Workplace Get(Guid workplaceId)
        {
            EF6.Workplace result = null;

            using (var ctx = new EF6.RT2020Entities())
            {
                result = ctx.Workplace.Where(x => x.WorkplaceId == workplaceId).AsNoTracking().FirstOrDefault();
            }

            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Get a EF6.Workplace object from the database using the given QueryString
        /// </summary>
        /// <param name="workplaceId">The primary key value</param>
        /// <returns>A EF6.Workplace object</returns>
        public static EF6.Workplace Get(string whereClause)
        {
            EF6.Workplace result = null;

            using (var ctx = new EF6.RT2020Entities())
            {
                result = ctx.Workplace
                         .SqlQuery(string.Format("Select * from Workplace Where {0}", whereClause))
                         .AsNoTracking()
                         .FirstOrDefault();
            }

            return(result);
        }
Beispiel #4
0
        public static EF6.Workplace GetWorkplaceById(Guid id)
        {
            EF6.Workplace result = null;

            using (var ctx = new EF6.RT2020Entities())
            {
                var p = ctx.Workplace.Where(x => x.WorkplaceId == id).FirstOrDefault();
                if (p != null)
                {
                    result = p;
                }
            }

            return(result);
        }
Beispiel #5
0
        private bool SaveData()
        {
            bool result = false;

            using (var ctx = new EF6.RT2020Entities())
            {
                using (var scope = ctx.Database.BeginTransaction())
                {
                    try
                    {
                        #region save Wokrplace core data
                        var wp = ctx.Workplace.Find(_WorkplaceId);
                        if (wp == null)
                        {
                            #region add new dbo.Workplace
                            wp               = new EF6.Workplace();
                            wp.WorkplaceId   = Guid.NewGuid();
                            wp.WorkplaceCode = txtLoc.Text.Trim();
                            wp.CreatedOn     = DateTime.Now;
                            wp.CreatedBy     = ConfigHelper.CurrentUserId;
                            wp.Status        = (int)EnumHelper.Status.Active;

                            ctx.Workplace.Add(wp);
                            _WorkplaceId = wp.WorkplaceId;
                            #endregion
                        }
                        wp.WorkplaceInitial  = txtInitial.Text.Trim();
                        wp.WorkplaceName     = txtName.Text.Trim();
                        wp.WorkplaceName_Chs = txtNameChs.Text.Trim();
                        wp.WorkplaceName_Cht = txtNameCht.Text.Trim();
                        //wp.AlternateWorkplaceCode = txtSmartTag3.Text;
                        wp.Priority = Convert.ToInt32((txtPriority.Text.Length == 0) ? "0" : txtPriority.Text.Trim());
                        wp.Email    = txtPhoneTag2.Text.Trim();
                        wp.Password = txtPassword.Text.Trim();

                        if ((Guid)cboNature.SelectedValue != Guid.Empty)
                        {
                            wp.NatureId = (Guid)cboNature.SelectedValue;
                        }
                        wp.ZoneId = (Guid)cboZone.SelectedValue;
                        if ((Guid)cboLOO.SelectedValue != Guid.Empty)
                        {
                            wp.LineOfOperationId = (Guid)cboLOO.SelectedValue;
                        }
                        wp.DownloadToCounter = true;
                        wp.DownloadToPOS     = true;
                        wp.DownloadToShop    = true;

                        wp.Status = ctx.Entry(wp).State == EntityState.Added ?
                                    (int)EnumHelper.Status.Active : (int)EnumHelper.Status.Modified;
                        wp.ModifiedOn = DateTime.Now;
                        wp.ModifiedBy = ConfigHelper.CurrentUserId;

                        ctx.SaveChanges();
                        #endregion

                        #region save WorkplaceAddress
                        var address = ctx.WorkplaceAddress.Where(x => x.WorkplaceId == _WorkplaceId).FirstOrDefault();
                        if (address == null)
                        {
                            #region add new dboWorkplaceAddress
                            address             = new EF6.WorkplaceAddress();
                            address.AddressId   = Guid.NewGuid();
                            address.WorkplaceId = _WorkplaceId;

                            ctx.WorkplaceAddress.Add(address);
                            #endregion
                        }
                        address.Address    = txtAddress.Text.Trim();
                        address.PostalCode = txtPostal.Text.Trim();
                        if ((Guid)cboCountry.SelectedValue != Guid.Empty)
                        {
                            address.CountryId = (Guid)cboCountry.SelectedValue;
                        }
                        if ((Guid)cboProvince.SelectedValue != Guid.Empty)
                        {
                            address.ProvinceId = (Guid)cboProvince.SelectedValue;
                        }
                        if ((Guid)cboCity.SelectedValue != Guid.Empty)
                        {
                            address.CityId = (Guid)cboCity.SelectedValue;
                        }
                        address.District = txtDistrict.Text.Trim();

                        // Phone Tag 1
                        address.PhoneTag1      = PhoneTagEx.GetPhoneTagIdByPriority(1);
                        address.PhoneTag1Value = txtPhoneTag1.Text;

                        // Phone Tag 3
                        address.PhoneTag3       = PhoneTagEx.GetPhoneTagIdByPriority(3);
                        address.Phonetage3Value = txtPhoneTag3.Text;

                        // Phone Tag 4
                        address.PhoneTag4      = PhoneTagEx.GetPhoneTagIdByPriority(4);
                        address.PhoneTag4Value = txtPhoneTag4.Text;

                        ctx.SaveChanges();
                        #endregion

                        #region save Smart Tags
                        #region Smart Tag 1
                        var oTag1 = ctx.WorkplaceSmartTag.Where(x => x.WorkplaceId == _WorkplaceId && x.TagId == (Guid)txtSmartTag1.Tag).FirstOrDefault();
                        if (oTag1 == null)
                        {
                            oTag1             = new EF6.WorkplaceSmartTag();
                            oTag1.SmartTagId  = Guid.NewGuid();
                            oTag1.WorkplaceId = _WorkplaceId;
                            oTag1.TagId       = (txtSmartTag1.Tag == null) ? Guid.Empty : new Guid(txtSmartTag1.Tag.ToString());
                            ctx.WorkplaceSmartTag.Add(oTag1);
                        }
                        oTag1.SmartTagValue = txtSmartTag1.Text;
                        ctx.SaveChanges();
                        #endregion

                        #region Smart Tag 2
                        var oTag2 = ctx.WorkplaceSmartTag.Where(x => x.WorkplaceId == _WorkplaceId && x.TagId == (Guid)txtSmartTag2.Tag).FirstOrDefault();
                        if (oTag2 == null)
                        {
                            oTag2             = new EF6.WorkplaceSmartTag();
                            oTag2.SmartTagId  = Guid.NewGuid();
                            oTag2.WorkplaceId = _WorkplaceId;
                            oTag2.TagId       = (txtSmartTag2.Tag == null) ? Guid.Empty : new Guid(txtSmartTag2.Tag.ToString());
                            ctx.WorkplaceSmartTag.Add(oTag2);
                        }
                        oTag2.SmartTagValue = txtSmartTag2.Text;
                        ctx.SaveChanges();
                        #endregion
                        #endregion

                        scope.Commit();
                        result = true;
                    }
                    catch (Exception ex)
                    {
                        scope.Rollback();
                    }
                }
            }

            return(result);

            /** abbendon
             * int priority = 0;
             * if (txtLoc.Text.Trim().Length <= 0)
             * {
             *  errorProvider.SetError(txtLoc, "Cannot be blank!");
             *  return false;
             * }
             * else if (!int.TryParse(txtPriority.Text.Trim(), out priority))
             * {
             *  errorProvider.SetError(txtPriority, Resources.Common.DigitalNeeded);
             *  return false;
             * }
             * else
             * {
             *  errorProvider.SetError(txtLoc, string.Empty);
             *  errorProvider.SetError(txtPriority, string.Empty);
             *
             *  if (txtLoc.ReadOnly)
             *  {
             *      var workplaceId = AddWorkplace(_WorkplaceId);
             *      _WorkplaceId = workplaceId;
             *
             *      if (workplaceId != Guid.Empty)
             *      {
             *          AddWorkplaceAddress(workplaceId);
             *          AddWorkplaceSmart(workplaceId);
             *      }
             *  }
             *  else
             *  {
             *      var workplaceId = AddWorkplace(Guid.Empty);
             *      if (workplaceId != Guid.Empty)
             *      {
             *          AddWorkplaceAddress(workplaceId);
             *          AddWorkplaceSmart(workplaceId);
             *      }
             *  }
             *  if (_WorkplaceId != Guid.Empty)
             *  {
             *      txtLoc.ReadOnly = true;
             *      txtLoc.BackColor = Color.LightYellow;
             *
             *      ClearForm();
             *      MessageBox.Show("Save successfully!", "Save Result");
             *
             *      return true;
             *  }
             *  else
             *  {
             *      return false;
             *  }
             * }
             */
        }