Exemplo n.º 1
0
        public void EvaluateFields()
        {
            var model = new FieldsModel();

            model.internalInt = 10;
            model.publicInt   = 5;

            var type                  = typeof(FieldsModel);
            var publicIntField        = type.GetField("publicInt", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
            var internalIntField      = type.GetField("internalInt", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            var privateIntField       = type.GetField("privateInt", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            var privateStaticIntField = type.GetField("privateStaticInt", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);

            Assert.IsNotNull(publicIntField);
            Assert.IsNotNull(internalIntField);
            Assert.IsNotNull(privateIntField);
            Assert.IsNotNull(privateStaticIntField);

            Assert.AreEqual(model.publicInt, publicIntField.GetValue(model));

            int internalIntValue      = 3;
            int privateIntValue       = 12;
            int privateStaticIntValue = 20;

            internalIntField.SetValue(model, internalIntValue);
            privateIntField.SetValue(model, privateIntValue);
            privateStaticIntField.SetValue(null, privateStaticIntValue);

            Assert.AreEqual(internalIntField.GetValue(model), internalIntValue);
            Assert.AreEqual(privateIntField.GetValue(model), privateIntValue);
            Assert.AreEqual(privateStaticIntField.GetValue(null), privateStaticIntValue);
        }
Exemplo n.º 2
0
        private bool CheckFieldDef(FieldsModel pField, out string error)
        {
            error = "";
            bool success = true;

            if (!string.IsNullOrEmpty(pField.DEF_VAL))
            {
                if (pField.FIELD_Type == "TEXT" && pField.DEF_VAL.Length > pField.MAX_VALUE)
                {
                    error   = string.Format("طول مقدار پیش فرض نباید از {0} بزرگتر باشد", pField.MAX_VALUE);
                    success = false;
                }
                int i = 0;
                if (pField.FIELD_Type == "INT" && !int.TryParse(pField.DEF_VAL, out i))
                {
                    error   = "مقدار پیش فرض باید عدد صحیح باشد";
                    success = false;
                }
                double j = 0;
                if (pField.FIELD_Type == "DOUBLE" && !double.TryParse(pField.DEF_VAL, out j))
                {
                    error   = "مقدار پیش فرض باید عدد باشد";
                    success = false;
                }
            }

            return(success);
        }
Exemplo n.º 3
0
 public JsonResult DeleteField([DataSourceRequest] DataSourceRequest request, FieldsModel pField)
 {
     if (pField != null)
     {
         if (!_FieldsBL.DeleteField(pField.ID))
         {
             ModelState.AddModelError("FIELD_Name", "خطایی در حذف ستون رخ داده است.مجددا تلاش کنید");
         }
     }
     return(Json(new[] { pField }.ToDataSourceResult(request, ModelState)));
 }
Exemplo n.º 4
0
        public JsonResult CreateField([DataSourceRequest] DataSourceRequest request, FieldsModel pField)
        {
            if (pField != null && ModelState.IsValid)
            {
                Classes       oClass        = _ClassesBL.getClass(pField.Class_ID ?? -1);
                List <string> specialFields = new List <string>()
                {
                    oClass.AdressField, oClass.DateOf, oClass.UserId, oClass.SupervisorDateOfField, oClass.SupervisorField
                };
                if (!specialFields.Contains(pField.FIELD_Name))
                {
                    List <Fields> oFields = _FieldsBL.getClassFields(oClass);
                    if (pField.FIELD_Type == "TEXT")
                    {
                        pField.MAX_VALUE = _ClassesBL.GetTextFieldLengthFromDB(pField.Class_ID ?? -1, pField.FIELD_Name);
                    }
                    string error = "";
                    if (CheckFieldDef(pField, out error))
                    {
                        if (oFields.Where(a => a.FIELD_Name.ToUpper() == pField.FIELD_Name.ToUpper()).Count() == 0)
                        {
                            int id = _FieldsBL.createNewFields(pField.Class_ID,
                                                               pField.FIELD_Name,
                                                               pField.FIELD_Type,
                                                               pField.FIELD_Caption,
                                                               pField.Domain_ID,
                                                               pField.MAX_VALUE,
                                                               pField.MIN_VALUE,
                                                               pField.ORDER,
                                                               pField.REQUIERD,
                                                               pField.DEF_VAL);
                            if (id == -1)
                            {
                                ModelState.AddModelError("FIELD_Name", "خطایی در ذخیره جدول رخ داده است.مجددا تلاش کنید");
                            }
                        }
                        else
                        {
                            ModelState.AddModelError("FIELD_Name", "ستون وارد شده تکراری می باشد");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("DEF_VAL", "خطا در مقدار پیش فرض. " + error);
                    }
                }
                else
                {
                    ModelState.AddModelError("FIELD_Name", "ستون وارد شده در لیست ستون های خاص است");
                }
            }

            return(Json(new[] { pField }.ToDataSourceResult(request, ModelState)));
        }
Exemplo n.º 5
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public int Update(FieldsModel model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update tbFields set ");
            strSql.Append(" UpdateTime = @UpdateTime , ");
            strSql.Append(" UpdateBy = @UpdateBy , ");
            strSql.Append(" TabId = @TabId , ");
            strSql.Append(" FieldName = @FieldName , ");
            strSql.Append(" FieldViewName = @FieldViewName , ");
            strSql.Append(" FieldDataTypeId = @FieldDataTypeId , ");
            strSql.Append(" IsActive = @IsActive , ");
            strSql.Append(" CreateTime = @CreateTime , ");
            strSql.Append(" CreateBy = @CreateBy , ");
            strSql.Append(" Sort = @Sort , ");
            strSql.Append(" IsSearch = @IsSearch ");
            strSql.Append(" where Id=@Id ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@Id",              SqlDbType.Int,        4),
                new SqlParameter("@UpdateTime",      SqlDbType.DateTime),
                new SqlParameter("@UpdateBy",        SqlDbType.NVarChar,  50),
                new SqlParameter("@TabId",           SqlDbType.Int,        4),
                new SqlParameter("@FieldName",       SqlDbType.NVarChar,  50),
                new SqlParameter("@FieldViewName",   SqlDbType.NVarChar,  50),
                new SqlParameter("@FieldDataTypeId", SqlDbType.Int,        4),
                new SqlParameter("@IsActive",        SqlDbType.Bit,        1),
                new SqlParameter("@CreateTime",      SqlDbType.DateTime),
                new SqlParameter("@CreateBy",        SqlDbType.NVarChar,  50),
                new SqlParameter("@Sort",            SqlDbType.Int,        4),
                new SqlParameter("@IsSearch",        SqlDbType.Bit, 1)
            };
            parameters[0].Value  = model.Id;
            parameters[1].Value  = model.UpdateTime;
            parameters[2].Value  = model.UpdateBy;
            parameters[3].Value  = model.TabId;
            parameters[4].Value  = model.FieldName;
            parameters[5].Value  = model.FieldViewName;
            parameters[6].Value  = model.FieldDataTypeId;
            parameters[7].Value  = model.IsActive;
            parameters[8].Value  = model.CreateTime;
            parameters[9].Value  = model.CreateBy;
            parameters[10].Value = model.Sort;
            parameters[11].Value = model.IsSearch;

            object obj = SqlHelper.ExecuteNonQuery(SqlHelper.connStr, CommandType.Text, strSql.ToString(), parameters);

            return(Convert.ToInt32(obj));
        }
Exemplo n.º 6
0
        public void EvaluateFieldsBad()
        {
            var model = new FieldsModel();

            var type           = typeof(FieldsModel);
            var publicIntField = type.GetField("publicInt", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);

            Assert.IsNotNull(publicIntField);

            try
            {
                publicIntField.SetValue(model, model);
            }
            catch (ArgumentException)
            {
            }

            try
            {
                publicIntField.SetValue(model, byte.MaxValue);
            }
            catch (ArgumentException)
            {
            }

            try
            {
                publicIntField.SetValue(model, true);
            }
            catch (ArgumentException)
            {
            }

            try
            {
                publicIntField.SetValue(model, (long)0);
            }
            catch (ArgumentException)
            {
            }

            try
            {
                publicIntField.SetValue(model, long.MaxValue);
            }
            catch (ArgumentException)
            {
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Make an API call to the Jira server, save the targeted information
        /// in a local cache, and make its results available to the application
        /// within a <c>List<FieldsModel></c> object.
        /// </summary>
        private void updateCache()
        {
            //Fetch the list of available fields
            Object fields = Jira.RPC(API_FIELD_LIST);
            IEnumerable <Object> fieldList = fields as IEnumerable <Object>;

            //Search for the desired field name in the list
            int    found = 0;
            string name;

            foreach (Dictionary <String, Object> field in fieldList)
            {
                name = field["name"] as string;

                //Log the desired field
                if (name == EPIC_FIELD_NAME || name == SPRINT_FIELD_NAME)
                {
                    //Collect the data
                    FieldsModel fm = new FieldsModel();
                    fm.ID   = field["id"] as string;
                    fm.Name = name;

                    //Log the transaction
                    List.Add(fm);

                    ++found;
                }

                //Don't over iterate!
                if (found == 2)
                {
                    break;
                }
            }

            //Write these values to the database file
            SW.WriteLine(List[0].ID);
            SW.WriteLine(List[0].Name);
            SW.WriteLine(List[1].ID);
            SW.WriteLine(List[1].Name);

            //Close the StreamWriter
            SW.Close();
        }
Exemplo n.º 8
0
        public JsonResult UpdateField([DataSourceRequest] DataSourceRequest request, FieldsModel pField)
        {
            if (pField != null && ModelState.IsValid)
            {
                Classes       oClass  = _ClassesBL.getClass(pField.Class_ID ?? -1);
                List <Fields> oFields = _FieldsBL.getClassFields(oClass);
                if (oFields.Where(a => a.FIELD_Name.ToUpper() != pField.FIELD_Name.ToUpper() && a.ID == pField.ID).Count() == 0)
                {
                    string error = "";
                    if (CheckFieldDef(pField, out error))
                    {
                        Fields field = oFields.Where(a => a.ID == pField.ID).Select(a => a).First();

                        field.FIELD_Name    = pField.FIELD_Name;
                        field.FIELD_Type    = pField.FIELD_Type;
                        field.FIELD_Caption = pField.FIELD_Caption;
                        field.DEF_VAL       = pField.DEF_VAL;
                        field.Domain_ID     = pField.Domain_ID;
                        field.MAX_VALUE     = pField.MAX_VALUE;
                        field.MIN_VALUE     = pField.MIN_VALUE;
                        field.ORDER         = pField.ORDER;
                        field.REQUIERD      = pField.REQUIERD;

                        if (!_FieldsBL.Update(field))
                        {
                            ModelState.AddModelError("FIELD_Name", "خطایی در ذخیره جدول رخ داده است.مجددا تلاش کنید");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("DEF_VAL", "خطا در مقدار پیش فرض. " + error);
                    }
                }
                else
                {
                    ModelState.AddModelError("FIELD_Name", "در هنگام ویرایش، تغییر نام ستون غیر مجاز است");
                }
            }

            return(Json(new[] { pField }.ToDataSourceResult(request, ModelState)));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Fetch field data from the local cache file and make its results
        /// available to the application within a <c>List<FieldsModel></c> object.
        /// </summary>
        private void extractFields()
        {
            //First field
            FieldsModel fm1 = new FieldsModel();

            fm1.ID   = SR.ReadLine() as string;
            fm1.Name = SR.ReadLine() as string;

            //Second field
            FieldsModel fm2 = new FieldsModel();

            fm2.ID   = SR.ReadLine() as string;
            fm2.Name = SR.ReadLine() as string;

            //Make these values publicly available
            List.Add(fm1);
            List.Add(fm2);

            //Close the StreamReader
            SR.Close();
        }
Exemplo n.º 10
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(FieldsModel model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into tbFields(");
            strSql.Append("UpdateTime,UpdateBy,TabId,FieldName,FieldViewName,FieldDataTypeId,IsActive,CreateTime,CreateBy,Sort,IsSearch");
            strSql.Append(") values (");
            strSql.Append("@UpdateTime,@UpdateBy,@TabId,@FieldName,@FieldViewName,@FieldDataTypeId,@IsActive,@CreateTime,@CreateBy,@Sort,@IsSearch");
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UpdateTime",      SqlDbType.DateTime),
                new SqlParameter("@UpdateBy",        SqlDbType.NVarChar,  50),
                new SqlParameter("@TabId",           SqlDbType.Int,        4),
                new SqlParameter("@FieldName",       SqlDbType.NVarChar,  50),
                new SqlParameter("@FieldViewName",   SqlDbType.NVarChar,  50),
                new SqlParameter("@FieldDataTypeId", SqlDbType.Int,        4),
                new SqlParameter("@IsActive",        SqlDbType.Bit,        1),
                new SqlParameter("@CreateTime",      SqlDbType.DateTime),
                new SqlParameter("@CreateBy",        SqlDbType.NVarChar,  50),
                new SqlParameter("@Sort",            SqlDbType.Int,        4),
                new SqlParameter("@IsSearch",        SqlDbType.Bit, 1)
            };

            parameters[0].Value  = model.UpdateTime;
            parameters[1].Value  = model.UpdateBy;
            parameters[2].Value  = model.TabId;
            parameters[3].Value  = model.FieldName;
            parameters[4].Value  = model.FieldViewName;
            parameters[5].Value  = model.FieldDataTypeId;
            parameters[6].Value  = model.IsActive;
            parameters[7].Value  = model.CreateTime;
            parameters[8].Value  = model.CreateBy;
            parameters[9].Value  = model.Sort;
            parameters[10].Value = model.IsSearch;
            object obj = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.connStr, CommandType.Text, strSql.ToString(), parameters));

            return(Convert.ToInt32(obj));
        }
Exemplo n.º 11
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public int Update(FieldsModel model)
 {
     return(dal.Update(model));
 }
Exemplo n.º 12
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(FieldsModel model)
 {
     return(dal.Add(model));
 }
Exemplo n.º 13
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public FieldsModel GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select Id, UpdateTime, UpdateBy, TabId, FieldName, FieldViewName, FieldDataTypeId, Sort, IsActive, CreateTime, CreateBy ,IsSearch ");
            strSql.Append("  from tbFields ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id", SqlDbType.Int, 4)
            };
            parameters[0].Value = Id;

            FieldsModel model = new FieldsModel();
            DataTable   dt    = SqlHelper.GetDataTable(SqlHelper.connStr, CommandType.Text, strSql.ToString(), parameters);

            if (dt.Rows.Count > 0)
            {
                if (dt.Rows[0]["Id"].ToString() != "")
                {
                    model.Id = int.Parse(dt.Rows[0]["Id"].ToString());
                }
                if (dt.Rows[0]["UpdateTime"].ToString() != "")
                {
                    model.UpdateTime = DateTime.Parse(dt.Rows[0]["UpdateTime"].ToString());
                }
                model.UpdateBy = dt.Rows[0]["UpdateBy"].ToString();
                if (dt.Rows[0]["TabId"].ToString() != "")
                {
                    model.TabId = int.Parse(dt.Rows[0]["TabId"].ToString());
                }
                model.FieldName     = dt.Rows[0]["FieldName"].ToString();
                model.FieldViewName = dt.Rows[0]["FieldViewName"].ToString();
                if (dt.Rows[0]["FieldDataTypeId"].ToString() != "")
                {
                    model.FieldDataTypeId = int.Parse(dt.Rows[0]["FieldDataTypeId"].ToString());
                }
                if (dt.Rows[0]["IsActive"].ToString() != "")
                {
                    if ((dt.Rows[0]["IsActive"].ToString() == "1") || (dt.Rows[0]["IsActive"].ToString().ToLower() == "true"))
                    {
                        model.IsActive = true;
                    }
                    else
                    {
                        model.IsActive = false;
                    }
                }
                if (dt.Rows[0]["IsSearch"].ToString() != "")
                {
                    if ((dt.Rows[0]["IsSearch"].ToString() == "1") || (dt.Rows[0]["IsSearch"].ToString().ToLower() == "true"))
                    {
                        model.IsSearch = true;
                    }
                    else
                    {
                        model.IsSearch = false;
                    }
                }
                if (dt.Rows[0]["Sort"].ToString() != "")
                {
                    model.Sort = int.Parse(dt.Rows[0]["Sort"].ToString());
                }
                if (dt.Rows[0]["CreateTime"].ToString() != "")
                {
                    model.CreateTime = DateTime.Parse(dt.Rows[0]["CreateTime"].ToString());
                }
                model.CreateBy = dt.Rows[0]["CreateBy"].ToString();

                return(model);
            }
            else
            {
                return(null);
            }
        }