Beispiel #1
0
func (this *SupplierController) UiAdd() {
	item := s.Supplier
	oItemDef, _ := itemDef.EntityDefMap[item]
	oItemDef.FillEnum(s.Category, getCategoryEnumList())
	this.Data["Service"] = "/item/add/" + item
	this.Data["Form"] = ui.BuildAddForm(oItemDef, u.TUId())
	this.Data["Onload"] = ui.BuildAddOnLoadJs(oItemDef)
	this.TplNames = "item/add.tpl"
}
Beispiel #2
0
func (this *ProductController) UiAdd() {
	item := s.Product
	oItemDef, _ := itemDef.EntityDefMap[item]
	this.Data["Service"] = "/item/add/" + oItemDef.Name
	this.FillFormElement(ui.BuildFormElement(oItemDef, t.Params{s.Sn: u.TUId()}, map[string]string{}))
	_, categorys := svc.GetAll(s.Category)
	this.Data["CategoryOptions"] = ui.BuildSelectOptions(categorys, "", s.Key, s.Name, s.Flag)
	this.TplNames = "product/add.tpl"
}
Beispiel #3
0
func Add(entity string, params t.Params) (string, string) {

	Q := "'"
	oEntityDef, ok := itemDef.EntityDefMap[entity]
	beego.Error(oEntityDef.Fields)
	if !ok {
		return stat.ItemNotDefine, ""
	}
	sn := u.TUId()
	fields := make([]string, 0)
	marks := make([]string, 0)
	values := make([]interface{}, 0)
	for _, field := range oEntityDef.Fields {
		if strings.EqualFold(field.Model, s.Upload) {
			continue
		}
		fields = append(fields, field.Name)
		marks = append(marks, "?")
		value, ok := params[field.Name]
		if ok {
			values = append(values, value)
			continue
		}
		if field.Model == s.Sn {
			values = append(values, sn)
			continue
		}
		if field.Model == s.CurTime {
			values = append(values, time.Now().Unix())
			continue
		}
		values = append(values, field.Default)
	}

	sep := fmt.Sprintf("%s, %s", Q, Q)
	qmarks := strings.Join(marks, ", ")
	columns := strings.Join(fields, sep)

	query := fmt.Sprintf("INSERT INTO %s%s%s (%s%s%s) VALUES (%s)", Q, entity, Q, Q, columns, Q, qmarks)
	beego.Debug("Add Item", query, values)
	o := orm.NewOrm()
	if res, err := o.Raw(query, values...).Exec(); err == nil {
		//		b, c := res.LastInsertId()
		//		fmt.Println("e", b, c)
		if i, e := res.LastInsertId(); e == nil && i > 0 {
			return stat.Success, sn
		} else {
			beego.Error(e, i)
			return ParseSqlError(err, oEntityDef)
		}
	} else {
		beego.Error("Add error", err)
		return ParseSqlError(err, oEntityDef)
	}
	return stat.UnKnownFailed, ""
}
Beispiel #4
0
func (this *AccountController) UiAdd() {
	if this.GetCurRole() == s.RoleUser {
		this.Ctx.WriteString("没有权限")
		return
	}
	item := s.Account
	oItemDef, _ := itemDef.EntityDefMap[item]
	oldValueMap := map[string]interface{}{
		s.Sn:        u.TUId(),
		s.PayerName: this.GetCurUserName(),
		s.Payer:     this.GetCurUserSn(),
	}
	this.Data["Form"] = ui.BuildUpdatedFormWithStatus(extendUserField(oItemDef, s.Payer), oldValueMap, make(map[string]string))
	this.Data["Service"] = "/item/add/" + item
	this.Data["Onload"] = ui.BuildAddOnLoadJs(oItemDef)
	this.TplNames = "item/add.tpl"
}
Beispiel #5
0
func (this *ProductController) Add() {
	item := s.Product
	oItemDef, _ := itemDef.EntityDefMap[item]
	svcParams, exParams := this.GetExFormValues(oItemDef)
	beego.Debug("ProductController.Add:", svcParams)
	suppliers, ok := exParams["supplierlist"]
	if !ok {
		this.JsonError(stat.Failed, "添加至少一个供应商!")
		return
	}
	sn := u.TUId()
	supplierMgr.AddSupplierRels(sn, suppliers.([]string))
	svcParams[s.Sn] = sn
	status, reason := svc.Add(item, svcParams)
	this.Data["json"] = &JsonResult{status, reason}
	this.ServeJson()
}
Beispiel #6
0
func (this *UiController) Add() {
	item, ok := this.Ctx.Input.Params[":hi"]
	if !ok {
		beego.Error(stat.ParamItemError)
		this.Ctx.WriteString(stat.ParamItemError)
		return
	}
	oItemDef, ok := itemDef.EntityDefMap[item]
	if !ok {
		beego.Error(fmt.Sprintf("Item %s not define", item))
		this.Ctx.WriteString(stat.ItemNotDefine)
		return
	}
	this.Data["Service"] = "/item/add/" + item
	this.Data["Form"] = ui.BuildAddForm(oItemDef, u.TUId())
	this.Data["Onload"] = ui.BuildAddOnLoadJs(oItemDef)
	this.TplNames = "item/add.tpl"
}