示例#1
0
        public override BaseResult SetCoding(object entity, Type type = null, string setPropertyName = "dh")
        {
            BaseResult br = new BaseResult();

            try
            {
                if (type == null)
                {
                    type = entity.GetType();
                }
                string    tableName = GetTableName(type);
                long      xh        = 1;
                long      id_master = CySoft.Frame.Common.TypeConvert.ToInt64((entity.GetValue("id_gys") ?? "0"), 0);
                Hashtable param     = new Hashtable();
                param.Add("coding", tableName);
                param.Add("lx", "2");
                Ts_Codingrule codingrule = DAL.GetItem <Ts_Codingrule>(typeof(Ts_Codingrule), param);
                if (codingrule == null)
                {
                    br.Success = false;
                    br.Message.Clear();
                    br.Message.Add(string.Format("对象'{0}'没有编码规则!请联系管理员!", tableName));
                    br.Level = ErrorLevel.Warning;
                    return(br);
                }
                string ymd = DAL.GetDbDateTime().ToString("yyyyMMdd");
                param.Clear();
                param.Add("billcode", tableName);
                param.Add("ymd", ymd);
                param.Add("id_master", id_master);

                if (DAL.GetCount(typeof(Ts_Max_Billcode), param) > 0)
                {
                    Ts_Max_Billcode model = DAL.GetItem <Ts_Max_Billcode>(typeof(Ts_Max_Billcode), param);
                    xh = model.max_dh.Value + codingrule.step.Value;
                    param.Add("new_max_dh", xh);
                    DAL.UpdatePart(typeof(Ts_Max_Billcode), param);
                }
                else
                {
                    Ts_Max_Billcode newItem = new Ts_Max_Billcode();
                    newItem.billcode  = tableName;
                    newItem.ymd       = ymd;
                    newItem.max_dh    = xh;
                    newItem.id_master = id_master;
                    DAL.Add(newItem);
                }

                int    codeLength = GetCodeLength("", codingrule.length.Value, 1) + 10;
                string bm         = string.Empty;
                if (!id_master.Equals(0))
                {
                    bm          = id_master.ToString().Length > 7 ? id_master.ToString() : string.Format("{0:0000000}", id_master);
                    codeLength += bm.Length;
                }
                string format = this.GetFormat(codingrule.prefix + ymd + bm, codeLength);
                string coding = String.Format(format, xh);
                entity.SetValue(setPropertyName, coding);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            br.Success = true;
            return(br);
        }
示例#2
0
        public override BaseResult SetCoding(object entity, Type type = null, string setPropertyName = "bm")
        {
            BaseResult br = new BaseResult();

            try
            {
                if (type == null)
                {
                    type = entity.GetType();
                }
                string tableName  = GetTableName(type);
                bool   flag_add   = true;
                bool   flag_hasxh = false;
                if (entity.HasProperty("xh"))
                {
                    flag_hasxh = true;
                }
                long      id    = Convert.ToInt64(entity.GetValue("id"));
                long      xh    = 0;
                Hashtable param = new Hashtable();
                param.Add("id", id);
                if (DAL.GetCount(type, param) > 0)
                {
                    flag_add = false;
                    if (flag_hasxh)
                    {
                        xh = Convert.ToInt64(entity.GetValue("xh"));
                    }
                }
                string coding = entity.GetValue(setPropertyName).ToString().Trim();

                param.Clear();
                param.Add("coding", tableName);
                param.Add("lx", "1");
                Ts_Codingrule codingrule = DAL.GetItem <Ts_Codingrule>(typeof(Ts_Codingrule), param);
                if (codingrule == null)
                {
                    br.Success = false;
                    br.Message.Clear();
                    br.Message.Add(string.Format("对象'{0}'没有编码规则!请联系管理员!", tableName));
                    br.Level = ErrorLevel.Warning;
                    return(br);
                }
                int codeLength = GetCodeLength(codingrule.prefix, codingrule.length.Value, 1);
                if (!String.IsNullOrEmpty(coding))
                {
                    if (flag_add && !coding.StartsWith(codingrule.prefix))
                    {
                        coding = codingrule.prefix + coding;
                    }
                    if (coding.Length != codeLength)
                    {
                        br.Success = false;
                        br.Message.Clear();
                        br.Message.Add(string.Format("本级的编码长度为 '{0}' 位,当前编码 '{1}' 不满足系统定义!请检查后再试!", codeLength, coding));
                        br.Level = ErrorLevel.Warning;
                        return(br);
                    }
                    param.Clear();
                    if (!flag_add)
                    {
                        param.Add("not_id", id);
                    }
                    if (flag_hasxh)
                    {
                        object id_gys = entity.GetValue("id_gys");
                        if (id_gys != null)
                        {
                            param.Add("id_gys", entity.GetValue("id_gys"));
                        }
                    }
                    param.Add(setPropertyName, coding);
                    if (DAL.GetCount(type, param) >= 1)
                    {
                        br.Success = false;
                        br.Message.Clear();
                        br.Message.Add(string.Format("编码[{0}]已存在,请使用其他编码!", coding));
                        br.Level = ErrorLevel.Warning;
                        return(br);
                    }
                }
                else if (flag_add)
                {
                    if (flag_hasxh)
                    {
                        xh  = DAL.GetNextXh(type) - 1;
                        xh += codingrule.step.Value;
                    }
                    else
                    {
                        param.Clear();
                        param.Add("table_name", tableName);
                        if (DAL.GetCount(typeof(Ts_Number_Max), param) > 0)
                        {
                            param.Clear();
                            param.Add("table_name", tableName);
                            Ts_Number_Max model = DAL.GetItem <Ts_Number_Max>(typeof(Ts_Number_Max), param);
                            xh = model.xh_max.Value + codingrule.step.Value;
                        }
                        else
                        {
                            Ts_Number_Max newItem = new Ts_Number_Max();
                            newItem.table_name = tableName;
                            newItem.xh_max     = 1;
                            DAL.Add(newItem);
                            xh = 1;
                        }
                    }
                    string format = this.GetFormat(codingrule.prefix, codeLength);
                    param.Clear();
                    if (flag_hasxh)
                    {
                        object id_gys = entity.GetValue("id_gys");
                        if (id_gys != null)
                        {
                            param.Add("id_gys", entity.GetValue("id_gys"));
                        }
                    }
                    while (true)
                    {
                        coding = String.Format(format, xh);
                        if (coding.Length != codeLength)
                        {
                            br.Success = false;
                            br.Message.Clear();
                            br.Message.Add("系统的编码资源已用完, 请检查编码规则或手工录入编码");
                            br.Level = ErrorLevel.Warning;
                            return(br);
                        }
                        param[setPropertyName] = coding;
                        if (DAL.GetCount(type, param) < 1)
                        {
                            break;
                        }
                        xh += codingrule.step.Value;
                    }
                }
                else
                {
                    //br.Success = false;
                    //br.Message.Clear();
                    //br.Message.Add("编码不能为空!");
                    //br.Level = ErrorLevel.Warning;
                    //return br;
                }
                entity.SetValue("id", id);
                if (flag_hasxh)
                {
                    entity.SetValue("xh", xh);
                }
                else
                {
                    param.Clear();
                    param.Add("table_name", tableName);
                    param.Add("new_xh_max", xh);
                    DAL.UpdatePart(typeof(Ts_Number_Max), param);
                }
                entity.SetValue(setPropertyName, coding);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            br.Success = true;
            return(br);
        }
示例#3
0
        public override BaseResult SetCoding(object entity, Type type = null, string setPropertyName = "bm")
        {
            BaseResult br = new BaseResult();

            try
            {
                if (type == null)
                {
                    type = entity.GetType();
                }
                string    tableName = GetTableName(type);
                bool      flag_add  = true;
                int       id        = Convert.ToInt32(entity.GetValue("id"));
                int       xh        = 0;
                Hashtable param     = new Hashtable();
                param.Add("id", id);
                if (DAL.GetCount(type, param) > 0)
                {
                    flag_add = false;
                    xh       = Convert.ToInt32(entity.GetValue("xh"));
                }
                string coding   = entity.GetValue(setPropertyName).ToString().Trim();
                int    fatherId = Convert.ToInt32(entity.GetValue("fatherId"));
                string path     = string.Empty;
                param.Clear();
                param.Add("id", fatherId);
                object father = DAL.GetItem(type, param) ?? new { path = "/0" };
                path = father.GetValue("path") + "/" + id;
                param.Clear();
                param.Add("coding", tableName);
                param.Add("lx", "1");
                Ts_Codingrule codingrule = DAL.GetItem <Ts_Codingrule>(typeof(Ts_Codingrule), param);
                if (codingrule == null)
                {
                    br.Success = false;
                    br.Message.Clear();
                    br.Message.Add(string.Format("对象'{0}'没有编码规则!请联系管理员!", tableName));
                    br.Level = ErrorLevel.Warning;
                    return(br);
                }
                int curlevel = path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Length - 1;
                if (curlevel > codingrule.level)
                {
                    br.Success = false;
                    br.Message.Clear();
                    br.Message.Add(string.Format("编码规则限制为'{0}'级!请检查后再试!", codingrule.level));
                    br.Level = ErrorLevel.Warning;
                    return(br);
                }
                int codeLength = GetCodeLength(codingrule.prefix, codingrule.length.Value, curlevel);
                if (!string.IsNullOrEmpty(coding))
                {
                    string fatherBm = (father.GetValue(setPropertyName) ?? "").ToString();
                    if (String.IsNullOrEmpty(fatherBm))
                    {
                        fatherBm = codingrule.prefix;
                    }
                    if (flag_add)
                    {
                        coding = fatherBm + coding;
                    }
                    if (coding.Length != codeLength)
                    {
                        br.Success = false;
                        br.Message.Clear();
                        br.Message.Add(string.Format("本级的编码长度为 '{0}' 位,当前编码 '{1}' 不满足系统定义!请检查后再试!", codeLength, coding));
                        br.Level = ErrorLevel.Warning;
                        return(br);
                    }
                    param.Clear();
                    if (!flag_add)
                    {
                        param.Add("not_id", id);
                    }
                    object id_gys = entity.GetValue("id_gys");
                    if (id_gys != null)
                    {
                        param.Add("id_gys", entity.GetValue("id_gys"));
                    }
                    param.Add(setPropertyName, coding);
                    if (DAL.GetCount(type, param) >= 1)
                    {
                        br.Success = false;
                        br.Message.Clear();
                        br.Message.Add(string.Format("编码[{0}]已存在,请使用其他编码!", coding));
                        br.Level = ErrorLevel.Warning;
                        return(br);
                    }
                }
                else if (flag_add)
                {
                    xh  = DAL.GetNextXh(type, param) - 1;
                    xh += codingrule.step.Value;
                    string fatherBm = (father.GetValue(setPropertyName) ?? "").ToString();
                    if (String.IsNullOrEmpty(fatherBm))
                    {
                        fatherBm = codingrule.prefix;
                    }
                    string format = this.GetFormat(fatherBm, codeLength);
                    param.Clear();
                    object id_gys = entity.GetValue("id_gys");
                    if (id_gys != null)
                    {
                        param.Add("id_gys", entity.GetValue("id_gys"));
                    }
                    while (true)
                    {
                        coding = String.Format(format, xh);
                        if (coding.Length != codeLength)
                        {
                            br.Success = false;
                            br.Message.Clear();
                            br.Message.Add("系统的编码资源已用完, 请检查编码规则或手工录入编码");
                            br.Level = ErrorLevel.Warning;
                            return(br);
                        }
                        param[setPropertyName] = coding;
                        if (DAL.GetCount(type, param) < 1)
                        {
                            break;
                        }
                        xh += codingrule.step.Value;
                    }
                }
                else
                {
                    //br.Success = false;
                    //br.Message.Clear();
                    //br.Message.Add("编码不能为空!");
                    //br.Level = ErrorLevel.Warning;
                    //return br;
                }
                if (entity.GetValue("xh") is Nullable <long> )
                {
                    entity.SetValue("xh", (long?)xh);
                }
                else if (entity.GetValue("xh") is Nullable <int> )
                {
                    entity.SetValue("xh", (int?)xh);
                }
                else if (entity.GetValue("xh") is long)
                {
                    entity.SetValue("xh", (long)xh);
                }
                else
                {
                    entity.SetValue("xh", xh);
                }
                entity.SetValue(setPropertyName, coding);
                entity.SetValue("path", path);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            br.Success = true;
            return(br);
        }
示例#4
0
        public ActionResult Add(string obj)
        {
            BaseResult br = new BaseResult();

            try
            {
                GoodsData model = JSON.Deserialize <GoodsData>(obj);

                if (string.IsNullOrEmpty(model.mc))
                {
                    br.Success = false;
                    br.Data    = "sp_mc";
                    br.Message.Add("商品名称不能为空");
                    return(Json(br));
                }

                if (model.id_spfl == 0)
                {
                    br.Success = false;
                    br.Data    = "id_spfl";
                    br.Message.Add("商品类别不能为空");
                    return(Json(br));
                }

                if (string.IsNullOrEmpty(model.unit))
                {
                    br.Success = false;
                    br.Data    = "unit";
                    br.Message.Add("商品单位不能为空");
                    return(Json(br));
                }

                if (model.sku == null || model.sku.Count.Equals(0))
                {
                    br.Success = false;
                    br.Data    = "sku";
                    br.Message.Add("必须至少有一条商品数据.");
                    return(Json(br));
                }

                if (!string.IsNullOrWhiteSpace(model.description) && model.description.Length > 2000)
                {
                    br.Success = false;
                    br.Data    = "sku";
                    br.Message.Add("商品介绍应在2000字以内.");
                    return(Json(br));
                }

                var param  = new Hashtable();
                var id_gys = GetLoginInfo <long>("id_supplier");

                param.Clear();
                param.Add("id_gys", GetLoginInfo <long>("id_supplier"));
                br = BusinessFactory.CustomerType.GetAll(param);
                if (!br.Success || br.Data == null)
                {
                    br.Success = false;
                    br.Data    = "cgs_level";
                    br.Message.Add("没有设置客户级别.");
                    return(Json(br));
                }
                var cgs_level = (List <Tb_Cgs_Level>)br.Data;
                if (cgs_level.Count < 1)
                {
                    br.Success = false;
                    br.Data    = "cgs_level";
                    br.Message.Add("没有设置客户级别.");
                    return(Json(br));
                }
                var default_level = new Tb_Cgs_Level()
                {
                    flag_sys = YesNoFlag.Yes, agio = decimal.Parse("100"), id_gys = id_gys
                };
                default_level = cgs_level.Find(m => m.flag_sys.Equals(YesNoFlag.Yes));
                if (default_level == null)
                {
                    default_level = cgs_level[0];
                }


                // 生成编码规则
                param.Clear();
                param.Add("coding", typeof(Tb_Sp_Sku).Name.ToLower());
                br = BusinessFactory.CodingRule.Get(param);
                Ts_Codingrule Codingrule = br.Data as Ts_Codingrule;

                List <string> bmlist = new List <string>();
                foreach (var item in model.sku)
                {
                    if (bmlist.Contains(item.bm_Interface))
                    {
                        br.Success = false;
                        br.Data    = "bm";
                        br.Message.Add("商品编码不能重复也不能为空");
                        return(Json(br));
                    }
                    if (string.IsNullOrEmpty(item.bm))
                    {
                        long xh_max = BusinessFactory.Utilety.GetNextXh(typeof(Tb_Sp_Sku));
                        if (xh_max.ToString().Length < Codingrule.length - Codingrule.prefix.Length)
                        {
                            item.bm = Codingrule.prefix + xh_max.ToString().PadLeft(Codingrule.length.Value - Codingrule.prefix.Length, '0');
                        }
                        else
                        {
                            br.Success = false;
                            br.Message.Add("商品编码已超过有效范围!请联系管理员!");
                            return(Json(br));
                        }
                    }
                    if (string.IsNullOrEmpty(item.bm_Interface))
                    {
                        item.bm_Interface = item.bm;
                    }
                    bmlist.Add(item.bm_Interface);

                    foreach (var p in item.sp_dj)
                    {
                        if (!p.id_cgs_level.HasValue || p.id_cgs_level.Value < 1)
                        {
                            p.id_cgs_level = default_level.id;
                        }
                    }
                    foreach (var p in cgs_level)
                    {
                        if (!item.sp_dj.Exists(m => m.id_cgs_level.Equals(p.id)))
                        {
                            item.sp_dj.Add(new Tb_Sp_Dj()
                            {
                                id_cgs_level = p.id, sl_dh_min = 0, dj_dh = (p.agio * item.dj_base / 100).Digit(DigitConfig.dj)
                            });
                        }
                    }
                }

                if (!model.id.HasValue || model.id.Value.Equals(0))
                {
                    model.id = BusinessFactory.Utilety.GetNextKey(typeof(Tb_Sp));
                }

                model.rq_create     = DateTime.Now;
                model.rq_edit       = DateTime.Now;
                model.id_gys_create = GetLoginInfo <long>("id_supplier");
                model.id_edit       = GetLoginInfo <long>("id_user");
                model.id_create     = GetLoginInfo <long>("id_user");


                if (!model.id_gys_create.HasValue || model.id_gys_create.Value < 1)
                {
                    br.Success = false;
                    br.Level   = ErrorLevel.Warning;
                    br.Message.Add("该用户没有分配供应商角色!");
                    return(Json(br));
                }
                br = BusinessFactory.Goods.Add(model);
            }
            catch (CySoftException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(Json(br));
        }