Exemple #1
0
        /// <summary>
        /// 提交工作空间修改信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public override bool Update(BaseModel model)
        {
            bool bResult = false;

            try
            {
                if (model is WorkspaceInfo info && !string.IsNullOrEmpty(info.WorkspaceName) && !string.IsNullOrEmpty(info.WorkspaceServerPath))
                {
                    List <string> values = new List <string>();

                    Type t = info.GetType();
                    foreach (PropertyInfo property in t.GetProperties())
                    {
                        values.Add(property.Name);
                    }

                    string conditions = "";
                    foreach (string name in values)
                    {
                        if (name.ToLower().Equals("id"))
                        {
                            continue;
                        }
                        if (name.ToLower().Equals("isupdate"))
                        {
                            string value = "0";

                            switch (info.GetType().GetProperty(name).GetValue(info, null))
                            {
                            case true:
                                value = "1";
                                break;

                            case false:
                                value = "0";
                                break;
                            }

                            conditions += string.Format("{0}='{1}'", name, value) + ",";
                        }
                        else
                        {
                            conditions += string.Format("{0}='{1}'", name, info.GetType().GetProperty(name).GetValue(info, null)) + ",";
                        }
                    }
                    if (conditions.Length > 0)
                    {
                        conditions = conditions.Substring(0, conditions.Length - 1);
                    }

                    string sql = "UPDATE {0} SET {1} WHERE {2}={3}";//UPDATE workspaceinfo SET WorkspaceName='舟山', IsUpdate=0 WHERE id=1
                    sql = string.Format(sql, Properties.Settings.Default.WorkspaceInfo, conditions, "id", info.ID);
                    if (DbHelperMySQL.ExecuteNonQuery(DbHelperMySQL.Conn, CommandType.Text, sql) > 0)
                    {
                        bResult = true;
                    }
                }
                else
                {
                    Log.ShowError("数据有误!");
                }
            }