public HttpResponseMessage SaveBasItemCategoryForm(t_item_category obj)
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                DBHelper <t_item_category> dbhelp = new DBHelper <t_item_category>();
                DateTime dt = DateTime.Now;

                //事务
                var result       = 0;
                var ItemCategory = db.t_item_category.Where(w => w.Code == obj.Code && w.CorpID == userInfo.CorpID);
                try
                {
                    if (obj.ItemCategoryID == 0)
                    {
                        string Code = "";
                        result         = AutoIncrement.AutoIncrementResult("ItemCategory", out Code);
                        obj.CreateTime = dt;
                        obj.CreateUser = (int)userInfo.UserID;
                        obj.UPdateTime = dt;
                        obj.UpdateUser = (int)userInfo.UserID;
                        obj.CorpID     = userInfo.CorpID;
                        obj.Code       = Code;

                        if (ItemCategory.ToList().Count() > 0)
                        {
                            throw new Exception("编码重复!");
                        }
                    }
                    else
                    {
                        obj.UPdateTime = dt;
                        obj.UpdateUser = (int)userInfo.UserID;

                        if (ItemCategory.ToList().Count() > 1)
                        {
                            throw new Exception("编码重复!");
                        }
                    }

                    result = result + (obj.ItemCategoryID == 0 ? dbhelp.Add(obj) : dbhelp.Update(obj));


                    //提交事务
                    transaction.Complete();
                    return(Json(true, "保存成功!"));
                }
                catch (Exception ex)
                {
                    return(Json(false, "保存失败!" + ex.Message));
                }
            }
        }
Esempio n. 2
0
        private dynamic SaveForm(t_purchaseOrder obj)
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                DateTime dt = DateTime.Now;

                t_purchase_order objItem = new t_purchase_order()
                {
                    POID            = obj.POID,
                    PostDate        = obj.PostDate,
                    PurchaserID     = obj.PurchaserID,
                    Remark          = obj.Remark,
                    Status          = obj.Status,
                    SupplierID      = obj.SupplierID,
                    TruckID         = obj.TruckID,
                    UpdateTime      = obj.UpdateTime,
                    UpdateUserID    = obj.UpdateUserID,
                    BillDate        = obj.BillDate,
                    BillType        = obj.BillType,
                    Code            = obj.Code,
                    ConfirmTime     = obj.ConfirmTime,
                    ConfirmUserID   = obj.ConfirmUserID,
                    CorpID          = obj.CorpID,
                    CreateTime      = obj.CreateTime,
                    CreateUserID    = obj.CreateUserID,
                    DriverID        = obj.DriverID,
                    IsStockFinished = obj.IsStockFinished
                };

                DBHelper <t_purchase_order> dbhelp_purOrder = new DBHelper <t_purchase_order>();


                //事务
                var result = 0;
                var Item   = db.t_purchase_order.Where(w => w.Code == objItem.Code && w.CorpID == userInfo.CorpID);
                try
                {
                    if (objItem.POID == 0)
                    {
                        string Code = objItem.Code;
                        if (Code == "" || Code == null)
                        {
                            result = AutoIncrement.AutoIncrementResult("PurchaseOrder", out Code);
                        }

                        objItem.CreateTime   = dt;
                        objItem.BillDate     = dt;
                        objItem.CreateUserID = (int)userInfo.UserID;
                        objItem.CorpID       = userInfo.CorpID;
                        objItem.Code         = Code;
                        objItem.Status       = 1;
                        if (Item.ToList().Count() > 0)
                        {
                            throw new Exception("账号重复!");
                        }
                        result = result + dbhelp_purOrder.Add(objItem);
                    }
                    else
                    {
                        objItem.CorpID       = userInfo.CorpID;
                        objItem.UpdateTime   = dt;
                        objItem.UpdateUserID = (int)userInfo.UserID;
                        if (Item.ToList().Count() > 1)
                        {
                            throw new Exception("账号重复!");
                        }
                        result = result + dbhelp_purOrder.Update(objItem);
                    }

                    //删除并保存明细
                    DBHelper <t_purchase_order_detail> dbhelp_purOderDetail = new DBHelper <t_purchase_order_detail>();
                    List <int>         ItemList      = new List <int>();
                    List <int>         UomList       = new List <int>();
                    List <t_itemprice> itempriceList = new List <t_itemprice>();
                    foreach (var item in obj.OrderDetail)
                    {
                        item.CorpID       = userInfo.CorpID;
                        item.POID         = objItem.POID;
                        item.UpdateTime   = dt;
                        item.UpdateUserID = (int)userInfo.UserID;
                        ItemList.Add(item.ItemID);
                        UomList.Add(item.UomID);
                        itempriceList.Add(new t_itemprice
                        {
                            CorpID     = userInfo.CorpID,
                            SuppCustID = objItem.SupplierID,
                            ItemID     = item.ItemID,
                            UomID      = item.UomID,
                            LastPrice  = item.UnitAmount,
                            UpdateTime = dt,
                            TargetType = 1
                        });
                    }
                    //删除明细
                    result = result + dbhelp_purOderDetail.RemoveList(w => w.POID == objItem.POID);
                    //添加明细
                    result = result + dbhelp_purOderDetail.AddList(obj.OrderDetail);

                    //删除最后价格
                    DBHelper <t_itemprice> dbhelp_itemprice = new DBHelper <t_itemprice>();
                    result = result + dbhelp_itemprice.RemoveList(w => w.TargetType == 1 && w.CorpID == userInfo.CorpID && ItemList.Contains(w.ItemID) && UomList.Contains(w.UomID) && w.SuppCustID == objItem.SupplierID);
                    //添加最后价格
                    result = result + dbhelp_itemprice.AddList(itempriceList.ToArray());

                    //提交事务
                    transaction.Complete();
                    return(new { result = true, message = "保存成功!", data = new { POID = objItem.POID } });
                }
                catch (Exception ex)
                {
                    throw new DomainException("保存失败!");
                }
            }
        }
Esempio n. 3
0
        public HttpResponseMessage SaveBasSupplierForm(t_supplier obj)
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                DBHelper <t_supplier> dbhelp = new DBHelper <t_supplier>();
                DateTime dt = DateTime.Now;

                //事务
                var result   = 0;
                var Supplier = db.t_supplier.Where(w => w.Code == obj.Code && w.CorpID == userInfo.CorpID);
                try
                {
                    if (obj.SupplierID == 0)
                    {
                        string Code = "";
                        result           = AutoIncrement.AutoIncrementResult("Supplier", out Code);
                        obj.CreateTime   = dt;
                        obj.CreateUserID = (int)userInfo.UserID;
                        obj.UpdateTime   = dt;
                        obj.UpdateUserID = (int)userInfo.UserID;
                        obj.CorpID       = userInfo.CorpID;
                        obj.Code         = Code;

                        if (Supplier.ToList().Count() > 0)
                        {
                            throw new Exception("编码重复!");
                        }
                        else
                        {
                            if (obj.IsValid == 0)//判断是否修改关闭状态,如果是需要写关闭人
                            {
                                obj.CloseTime   = dt;
                                obj.CloseUserID = (int)userInfo.UserID;
                            }
                        }
                    }
                    else
                    {
                        obj.UpdateTime   = dt;
                        obj.UpdateUserID = (int)userInfo.UserID;

                        if (Supplier.ToList().Count() > 1)
                        {
                            throw new Exception("编码重复!");
                        }
                        else
                        {
                            if (obj.IsValid == 0 && Supplier.Select(s => s.IsValid).FirstOrDefault() != 0)//判断是否修改关闭状态,如果是需要写关闭人
                            {
                                obj.CloseTime    = dt;
                                obj.UpdateUserID = (int)userInfo.UserID;
                            }

                            if (obj.IsValid != 0 && Supplier.Select(s => s.IsValid).FirstOrDefault() == 0)//如果再次打开清空时间和操作员
                            {
                                obj.CloseTime    = null;
                                obj.UpdateUserID = null;
                            }
                        }
                    }

                    result = result + (obj.SupplierID == 0 ? dbhelp.Add(obj) : dbhelp.Update(obj));

                    //提交事务
                    transaction.Complete();
                    return(Json(true, "保存成功!"));
                }
                catch (Exception ex)
                {
                    return(Json(false, "保存失败!" + ex.Message));
                }
            }
        }
Esempio n. 4
0
        public HttpResponseMessage SaveBasCustomerForm(t_customer obj)
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                DBHelper <t_customer> dbhelp = new DBHelper <t_customer>();
                DateTime dt = DateTime.Now;

                //事务
                var result   = 0;
                var Customer = db.t_customer.Where(w => w.Code == obj.Code && w.CorpID == userInfo.CorpID);
                try
                {
                    string base64Data = obj.Photo;
                    if (obj.CustID == 0)
                    {
                        string Code = obj.Code;
                        if (Code == "" || Code == null)
                        {
                            result = AutoIncrement.AutoIncrementResult("Customer", out Code);
                        }

                        obj.Photo        = "";
                        obj.CreateTime   = dt;
                        obj.CreateUserID = (int)userInfo.UserID;
                        obj.CorpID       = userInfo.CorpID;
                        obj.Code         = Code;
                        if (Customer.ToList().Count() > 0)
                        {
                            throw new Exception("账号重复!");
                        }
                        result = result + dbhelp.Add(obj);
                    }
                    else
                    {
                        obj.Photo        = "";
                        obj.UpdateTime   = dt;
                        obj.UpdateUserID = (int)userInfo.UserID;
                        if (Customer.ToList().Count() > 1)
                        {
                            throw new Exception("账号重复!");
                        }
                        result = result + dbhelp.Update(obj);
                    }

                    //保存图片并修改数据库图片名称
                    try
                    {
                        //获取文件储存路径
                        string suffix      = base64Data.Split(new char[] { ';' })[0].Substring(base64Data.IndexOf('/') + 1); //获取后缀名
                        string newFileName = "CUST_" + obj.CustID.ToString("000000000") + "." + suffix;
                        string strPath     = HttpContext.Current.Server.MapPath("~/" + UploadImgPath + "/" + newFileName);   //获取当前项目所在目录
                        //获取图片并保存
                        BaseToImg.Base64ToImg(base64Data.Split(',')[1]).Save(strPath);
                        obj.Photo = newFileName;
                    }
                    catch
                    {
                        obj.Photo = base64Data;
                    }
                    List <string> fileds = new List <string>();
                    fileds.Add("Photo");
                    result = result + dbhelp.UpdateEntityFields(obj, fileds);

                    //提交事务
                    transaction.Complete();
                    return(Json(true, "保存成功!"));
                }
                catch (Exception ex)
                {
                    return(Json(false, "保存失败!" + ex.Message));
                }
            }
        }
        public HttpResponseMessage SaveBasWarehouseForm(t_warehouse_user obj)
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                DBHelper <t_warehouse> dbhelp = new DBHelper <t_warehouse>();
                DateTime dt = DateTime.Now;

                //事务
                var result    = 0;
                var WareHouse = db.t_warehouse.Where(w => w.Code == obj.Code && w.CorpID == userInfo.CorpID);
                try
                {
                    if (obj.WarehouseID == 0)
                    {
                        string Code = "";
                        result           = AutoIncrement.AutoIncrementResult("Warehouse", out Code);
                        obj.CreateTime   = dt;
                        obj.CreateUserID = (int)userInfo.UserID;
                        obj.UpdateTime   = dt;
                        obj.UpdateUserID = (int)userInfo.UserID;
                        obj.CorpID       = userInfo.CorpID;
                        obj.Code         = Code;

                        if (WareHouse.ToList().Count() > 0)
                        {
                            throw new Exception("编码重复!");
                        }
                        else
                        {
                            if (obj.IsValid == 0)//判断是否修改关闭状态,如果是需要写关闭人
                            {
                                obj.CloseTime = dt;
                                obj.CloseUser = (int)userInfo.UserID;
                            }
                        }
                    }
                    else
                    {
                        obj.UpdateTime   = dt;
                        obj.UpdateUserID = (int)userInfo.UserID;

                        if (WareHouse.ToList().Count() > 1)
                        {
                            throw new Exception("编码重复!");
                        }
                        else
                        {
                            if (obj.IsValid == 0 && WareHouse.Select(s => s.IsValid).FirstOrDefault() != 0)//判断是否修改关闭状态,如果是需要写关闭人
                            {
                                obj.CloseTime = dt;
                                obj.CloseUser = (int)userInfo.UserID;
                            }

                            if (obj.IsValid != 0 && WareHouse.Select(s => s.IsValid).FirstOrDefault() == 0)//如果再次打开清空时间和操作员
                            {
                                obj.CloseTime = null;
                                obj.CloseUser = null;
                            }
                        }
                    }

                    t_warehouse tw = new t_warehouse()
                    {
                        WarehouseID       = obj.WarehouseID,
                        Code              = obj.Code,
                        Address           = obj.Address,
                        CorpID            = obj.CorpID,
                        Name              = obj.Name,
                        IsValid           = obj.IsValid,
                        Phone             = obj.Phone,
                        Tel               = obj.Tel,
                        IsBin             = obj.IsBin,
                        IsRequireReceive  = obj.IsRequireReceive,
                        IsRequireShipment = obj.IsRequireShipment,
                        Contact           = obj.Contact,
                        CreateTime        = obj.CreateTime,
                        CreateUserID      = obj.CreateUserID,
                        UpdateTime        = obj.UpdateTime,
                        UpdateUserID      = obj.UpdateUserID,
                        CloseTime         = obj.CloseTime,
                        CloseUser         = obj.CloseUser
                    };
                    result = result + (obj.WarehouseID == 0 ? dbhelp.Add(tw) : dbhelp.Update(tw));

                    //删除并新增仓库对应用户
                    foreach (var item in obj.userData)
                    {
                        item.WarehouseID = (int)tw.WarehouseID;
                    }
                    result = result + new DBHelper <t_user_warehouse>().RemoveList(w => w.WarehouseID == tw.WarehouseID);
                    result = result + new DBHelper <t_user_warehouse>().AddList(obj.userData);

                    //提交事务
                    transaction.Complete();
                    return(Json(true, "保存成功!"));
                }
                catch (Exception ex)
                {
                    return(Json(false, "保存失败!" + ex.Message));
                }
            }
        }
Esempio n. 6
0
        public HttpResponseMessage SaveBasItemForm(t_item_photo_uom obj)
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                DateTime dt = DateTime.Now;

                t_item objItem = new t_item()
                {
                    CorpID         = userInfo.CorpID,
                    Code           = obj.Code,
                    ItemID         = obj.ItemID,
                    ItemGroupID    = obj.ItemGroupID,
                    ItemCategoryID = obj.ItemCategoryID,
                    Name           = obj.Name,
                    HelperCode     = obj.HelperCode,
                    Barcode        = obj.Barcode,
                    BaseUOM        = obj.BaseUOM,
                    CrossWeigth    = obj.CrossWeigth,
                    Height         = obj.Height,
                    IsBatch        = obj.IsBatch,
                    IsForSale      = obj.IsForSale,
                    IsZeroValue    = obj.IsZeroValue,
                    LastCost       = obj.LastCost,
                    Length         = obj.Length,
                    Period         = obj.Period,
                    PurchasePrice  = obj.PurchasePrice,
                    PurchaseUOM    = obj.PurchaseUOM,
                    SalesPrice     = obj.SalesPrice,
                    SalesUOM       = obj.SalesUOM,
                    SaveInventory  = obj.SaveInventory,
                    ShortName      = obj.ShortName,
                    Size           = obj.Size,
                    IsValid        = obj.IsValid,
                    WarehouseID    = obj.WarehouseID,
                    Width          = obj.Width,
                    CloseTime      = obj.CloseTime,
                    CloseUserID    = obj.CloseUserID,
                    CreateTime     = obj.CreateTime,
                    CreateUserID   = obj.CreateUserID,
                    UpdateTime     = obj.UpdateTime,
                    UpdateUserID   = obj.UpdateUserID
                };

                DBHelper <t_item> dbhelp_item = new DBHelper <t_item>();


                //事务
                var result = 0;
                var Item   = db.t_item.Where(w => w.Code == objItem.Code && w.CorpID == userInfo.CorpID);
                try
                {
                    if (objItem.ItemID == 0)
                    {
                        string Code = objItem.Code;
                        if (Code == "" || Code == null)
                        {
                            result = AutoIncrement.AutoIncrementResult("Item", out Code);
                        }

                        objItem.CreateTime   = dt;
                        objItem.CreateUserID = (int)userInfo.UserID;
                        objItem.CorpID       = userInfo.CorpID;
                        objItem.Code         = Code;
                        if (Item.ToList().Count() > 0)
                        {
                            throw new Exception("账号重复!");
                        }
                        result = result + dbhelp_item.Add(objItem);
                    }
                    else
                    {
                        objItem.UpdateTime   = dt;
                        objItem.UpdateUserID = (int)userInfo.UserID;
                        if (Item.ToList().Count() > 1)
                        {
                            throw new Exception("账号重复!");
                        }
                        result = result + dbhelp_item.Update(objItem);
                    }


                    //保存图片并修改数据库图片名称
                    t_item_picture objItemPicture = new t_item_picture()
                    {
                        PicID        = obj.Photo.PicID,
                        CorpID       = userInfo.CorpID,
                        ItemID       = (int)objItem.ItemID,
                        Picture      = obj.Photo.Picture,
                        Type         = obj.Photo.Type,
                        IsTitle      = obj.Photo.IsTitle,
                        IsValid      = obj.Photo.IsValid,
                        CreateTime   = dt,
                        CreateUserID = (int)userInfo.UserID,
                    };
                    DBHelper <t_item_picture> dbhelp_picture = new DBHelper <t_item_picture>();
                    string base64Data = obj.Photo.Picture;
                    try
                    {
                        //获取文件储存路径
                        string suffix      = base64Data.Split(new char[] { ';' })[0].Substring(base64Data.IndexOf('/') + 1); //获取后缀名
                        string newFileName = "M_" + obj.ItemID.ToString("000000000") + "." + suffix;
                        string strPath     = HttpContext.Current.Server.MapPath("~/" + UploadImgPath + "/" + newFileName);   //获取当前项目所在目录
                        //获取图片并保存
                        BaseToImg.Base64ToImg(base64Data.Split(',')[1]).Save(strPath);
                        objItemPicture.Picture = newFileName;
                    }
                    catch
                    {
                        objItemPicture.Picture = base64Data;
                    }
                    //删除并保存图片
                    result = result + dbhelp_picture.RemoveList(w => w.ItemID == objItem.ItemID && w.Type == 0);
                    result = result + dbhelp_picture.Add(objItemPicture);

                    //删除并保存单位
                    DBHelper <t_item_uom> dbhelp_item_uom = new DBHelper <t_item_uom>();
                    foreach (var item in obj.Uom)
                    {
                        item.CorpID       = userInfo.CorpID;
                        item.ItemID       = (int)objItem.ItemID;
                        item.CreateTime   = dt;
                        item.CreateUserID = (int)userInfo.UserID;
                        item.UpdateTime   = dt;
                        item.UpdateUserID = (int)userInfo.UserID;
                    }
                    result = result + dbhelp_item_uom.RemoveList(w => w.ItemID == objItem.ItemID);
                    result = result + dbhelp_item_uom.AddList(obj.Uom);

                    //提交事务
                    transaction.Complete();
                    return(Json(true, "保存成功!"));
                }
                catch (Exception ex)
                {
                    return(Json(false, "保存失败!" + ex.Message));
                }
            }
        }