Exemplo n.º 1
0
        public short Insert(BAJK12 model)
        {
            if (model == null)
            {
                LogManager.Instance.WriteLog("", new string[] { "" }
                                             , new object[] { model }, "参数不能为空");
                return(SystemData.ReturnValue.PARAM_ERROR);
            }
            if (model.KEY1201 == 0 || model.KEY1201 == 0)
            {
                return(SystemData.ReturnValue.EXCEPTION);
            }
            StringBuilder sbField = new StringBuilder();
            StringBuilder sbValue = new StringBuilder();

            PropertyInfo[] PropertyList = Reflect.GetProperties <BAJK12>(model);
            foreach (var item in PropertyList)
            {
                string name  = item.Name;
                object value = item.GetValue(model, null);

                switch (item.PropertyType.Name)
                {
                case "Decimal":
                    sbField.AppendFormat("{0},", name);
                    sbValue.AppendFormat("{0},", value);
                    break;

                case "DateTime":
                    DateTime dt = DateTime.Parse(value.ToString());
                    if (dt == model.DefaultTime ||
                        dt == model.DefaultTime2 ||
                        dt == model.DefaultTime3)
                    {
                        break;
                    }
                    sbField.AppendFormat("{0},", name);
                    sbValue.AppendFormat("{0},", base.BAJKDataAccess.GetSqlTimeFormat(dt));
                    break;

                default:
                    sbField.AppendFormat("{0},", name);
                    sbValue.AppendFormat("'{0}',", value);
                    break;
                }
            }
            string szField = sbField.ToString().Substring(0, sbField.Length - 1);
            string szValue = sbValue.ToString().Substring(0, sbValue.Length - 1);
            string szSQL   = string.Format(SystemData.SQL.INSERT
                                           , SystemData.DataTable_BAJK.BAJK12
                                           , szField
                                           , szValue);
            int nCount = 0;

            try
            {
                nCount = base.BAJKDataAccess.ExecuteNonQuery(szSQL, CommandType.Text);
            }
            catch (Exception ex)
            {
                LogManager.Instance.WriteLog("", new string[] { "szSQL" }, new object[] { szSQL }, ex);
                return(SystemData.ReturnValue.EXCEPTION);
            }
            if (nCount <= 0)
            {
                LogManager.Instance.WriteLog("", new string[] { "szSQL" }, new object[] { szSQL }, "SQL语句执行后返回0!");
                return(SystemData.ReturnValue.EXCEPTION);
            }
            return(SystemData.ReturnValue.OK);
        }
Exemplo n.º 2
0
        public short Update(RecBrowseRequest model)
        {
            if (model == null)
            {
                LogManager.Instance.WriteLog("", new string[] { "" }
                                             , new object[] { model }, "参数不能为空");
                return(SystemData.ReturnValue.PARAM_ERROR);
            }
            if (base.MedQCAccess == null)
            {
                return(SystemData.ReturnValue.PARAM_ERROR);
            }
            StringBuilder sbField = new StringBuilder();

            PropertyInfo[] PropertyList = Reflect.GetProperties <RecBrowseRequest>(model);
            foreach (var item in PropertyList)
            {
                string name  = item.Name;
                object value = item.GetValue(model, null);

                switch (item.PropertyType.Name)
                {
                case "Decimal":
                    sbField.AppendFormat("{0}={1},", name, value);
                    break;

                case "int":
                    sbField.AppendFormat("{0}={1},", name, value);
                    break;

                case "DateTime":
                    DateTime dt = DateTime.Parse(value.ToString());
                    if (dt == model.DefaultTime || dt == model.DefaultTime2 || dt == model.DefaultTime3)
                    {
                        break;
                    }
                    sbField.AppendFormat("{0}={1},", name, base.MedQCAccess.GetSqlTimeFormat(dt));
                    break;

                default:
                    sbField.AppendFormat("{0}='{1}',", name, value);
                    break;
                }
            }
            string szField     = sbField.ToString().Substring(0, sbField.Length - 1);
            string szCondition = string.Format("{0}='{1}'", KeyName, model.ID);
            string szSQL       = string.Format(SystemData.SQL.UPDATE, TableName, szField, szCondition);
            int    nCount      = 0;

            try
            {
                nCount = base.MedQCAccess.ExecuteNonQuery(szSQL, CommandType.Text);
            }
            catch (Exception ex)
            {
                LogManager.Instance.WriteLog("", new string[] { "szSQL" }, new object[] { szSQL }, ex);
                return(SystemData.ReturnValue.EXCEPTION);
            }
            if (nCount <= 0)
            {
                LogManager.Instance.WriteLog("", new string[] { "szSQL" }, new object[] { szSQL }, "SQL语句执行后返回0!");
                return(SystemData.ReturnValue.EXCEPTION);
            }
            return(SystemData.ReturnValue.OK);
        }