Ejemplo n.º 1
0
        public ActionResult CancelSalesOrder(string data)
        {
            var dbConn = new OrmliteConnection().openConn();
            if (userAsset.ContainsKey("Insert") && userAsset["Insert"])
            {
                try
                {
                    string[] separators = { "@@" };
                    var listdata = data.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var item in listdata)
                    {
                        if (dbConn.Select<SOHeader>("Select * from SOHeader where Status <> N'Mới' AND SONumber = '"+item+"'").Count() > 0)
                        {
                            return Json(new { success = false, message = "Chỉ hủy được các mẫu tin có trạng thái Mới" });
                        }

                        dbConn.Update<SOHeader>(set: "Status = N'Hủy'", where: "SONumber = '" + item + "'");
                    }
                }
                catch (Exception e)
                {
                    return Json(new { success = false, message = e.Message });
                }
                return Json(new{success = true});
            }
            else{
                return Json(new { success = false, message = "Bạn không có quyền hủy." });
            }
        }
        public ActionResult Create([DataSourceRequest]DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<Models.Master_Calendar> lst)
        {
            IDbConnection dbConn = new OrmliteConnection().openConn();

            try
            {
                foreach (var item in lst)
                {
                    if (userAsset.ContainsKey("Update") && userAsset["Update"] && dbConn.GetByIdOrDefault<Master_Calendar>(item.Date) != null)
                    {
                        if (string.IsNullOrEmpty(item.Holiday))
                        {
                            item.Holiday = "";
                        }
                        item.RowUpdatedAt = DateTime.Now;
                        item.RowUpdatedBy = currentUser.UserID;
                        dbConn.Update<Master_Calendar>(item);
                    }
                    else
                        return Json(new { success = false, message = "You don't have permission" });
                }
                return Json(new { success = true });
            }
            catch (Exception ex)
            {
                log.Error("AdminMasterHoliday - Create - " + ex.Message);
                return Json(new { success = false, message = ex.Message });
            }
            finally
            {
                dbConn.Close();
            }
        }
Ejemplo n.º 3
0
 public ActionResult Create(DC_LG_Discountion item)
 {
     IDbConnection db = new OrmliteConnection().openConn();
     try
     {
         if (!string.IsNullOrEmpty(item.DiscountionID) &&
             !string.IsNullOrEmpty(item.DiscountionName)
             )
         {
             var isExist = db.SingleOrDefault<DC_LG_Discountion>("DiscountionID={0}", item.DiscountionID);
             item.FromDate = item.FromDate != null ? item.FromDate : DateTime.Now;
             item.EndDate = item.EndDate != null ? item.EndDate : DateTime.Now;
             item.EndDate = item.EndDate != null ? item.EndDate : DateTime.Now;
             if (item.FromDate > item.EndDate)
             {
                 return Json(new { success = false, message = "Ngày kết thúc không thể lớn hơn " + item.FromDate });
             }
             item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note : "";
             item.DiscountionType = !string.IsNullOrEmpty(item.DiscountionType) ? item.DiscountionType : "";
             if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
             {
                 if (isExist != null)
                     return Json(new { success = false, message = "Mã chương trình chiết khấu đã tồn tại" });
                 item.DiscountionName = !string.IsNullOrEmpty(item.DiscountionName) ? item.DiscountionName : "";
                 item.CreatedAt = DateTime.Now;
                 item.UpdatedAt = DateTime.Now;
                 item.CreatedBy = currentUser.UserID;
                 db.Insert(item);
                 return Json(new { success = true, DiscountionID = item.DiscountionID, CreatedBy = item.CreatedBy, CreatedAt = item.CreatedAt });
             }
             else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
             {
                 item.DiscountionName = !string.IsNullOrEmpty(item.DiscountionName) ? item.DiscountionName : "";
                 item.CreatedAt = item.CreatedAt;
                 item.UpdatedAt = DateTime.Now;
                 item.CreatedBy = currentUser.UserID;
                 db.Update(item);
                 return Json(new { success = true });
             }
             else
                 return Json(new { success = false, message = "Bạn không có quyền" });
         }
         else
         {
             return Json(new { success = false, message = "Chưa nhập đủ giá trị" });
         }
     }
     catch (Exception e)
     {
         log.Error("DeliveryDiscountion - Create - " + e.Message);
         return Json(new { success = false, message = e.Message });
     }
     finally { db.Close(); }
 }
Ejemplo n.º 4
0
        public ActionResult CompletePicking(string data)
        {
            var dbConn = new OrmliteConnection().openConn();
            if (userAsset.ContainsKey("Update") && userAsset["Update"])
            {
                try
                {
                    string[] separators = { "@@" };
                    var listdata = data.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var item in listdata)
                    {
                        if (dbConn.Select<DC_AD_Picking_Header>(s => s.Status == "Hoàn thành" && s.PickingNumber == item).Count() > 0)
                        {
                            return Json(new { success = false, message = item + " đã được hoàn thành trước đó." });
                        }

                        if (dbConn.Select<DC_AD_Picking_Header>(s =>s.Status != "Đang giao hàng" && s.PickingNumber==item).Count() > 0)
                        {
                            return Json(new { success = false, message = item + " vui lòng nhập kho trước khi hoàn thành." });
                        }

                        dbConn.Update<DC_AD_Picking_Header>(set: "Status = N'Hoàn thành', UpdatedBy ='" + currentUser.UserID + "', UpdatedAt= '"+DateTime.Now+"'", where: "PickingNumber = '" + item + "'");
                        foreach (var so in dbConn.Select<DC_AD_Picking_Detail>(s => s.PickingNumber == item).ToList())
                        {
                            dbConn.Update<SOHeader>(set: "Status = N'Hoàn thành'", where: "SONumber = '" + so.SONumber + "'");
                        }
                        //dbConn.Update<DC_AD_SO_Header>(set: "Status = N'Hoàn thành'", where: "SONumber = '" + item + "'");
                    }
                }
                catch (Exception e)
                {
                    return Json(new { success = false, message = e.Message });
                }
                return Json(new { success = true });
            }
            else
            {
                return Json(new { success = false, message = "Bạn không có quyền hủy." });
            }
        }
Ejemplo n.º 5
0
 //
 // GET: /DeliveryManage/Create
 public ActionResult Create(DC_LG_Transporter item)
 {
     IDbConnection db = new OrmliteConnection().openConn();
     try
     {
         if (//!string.IsNullOrEmpty(item.TransporterID) &&
             !string.IsNullOrEmpty(item.TransporterName)
             )
         {
             int n;
             var isExist = db.SingleOrDefault<DC_LG_Transporter>("TransporterID={0}",item.TransporterID);
             item.Weight = int.TryParse(item.Weight.ToString(),out n) ? item.Weight : 0;
             item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note : "";
             if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
             {
                 if(isExist != null)
                     return Json(new { success = false, message = "Mã đơn vị vận chuyển đã tồn tại!" });
                 item.TransporterName = !string.IsNullOrEmpty(item.TransporterName) ? item.TransporterName : "";
                 item.CreatedAt = DateTime.Now;
                 item.UpdatedAt = DateTime.Now;
                 item.CreatedBy = currentUser.UserID;
                 item.UpdatedBy = currentUser.UserID;
                 db.Insert(item);
                 return Json(new { success = true, TransporterID = item.TransporterID, CreatedBy = item.CreatedBy, CreatedAt = item.CreatedAt });
             }
             else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
             {
                 item.TransporterName = !string.IsNullOrEmpty(item.TransporterName) ? item.TransporterName : "";
                 item.CreatedAt = item.CreatedAt;
                 item.UpdatedAt = DateTime.Now;
                 item.CreatedBy = currentUser.UserID;
                 item.UpdatedBy = currentUser.UserID;
                 db.Update(item);
                 return Json(new { success = true });
             }
             else
                 return Json(new { success = false, message = "Bạn không có quyền" });
         }
         else
         {
             return Json(new { success = false, message = "Chưa nhập giá trị" });
         }
     }
     catch (Exception e)
     {
         log.Error("Transporter - Create - " + e.Message);
         return Json(new { success = false, message = e.Message });
     }
     finally { db.Close(); }
 }
Ejemplo n.º 6
0
 //
 // GET: /DeliveryManage/Create
 public ActionResult Create(DC_Reason item)
 {
     IDbConnection db = new OrmliteConnection().openConn();
     try
     {
         if (!string.IsNullOrEmpty(item.ReasonID) && item.ReasonType!="None")
         {
             var isExist = db.GetByIdOrDefault<DC_Reason>(item.ReasonID);
             item.Description = !string.IsNullOrEmpty(item.Description) ? item.Description : "";
             if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.RowCreatedAt == null && item.RowCreatedBy == null)
             {
                 if (isExist != null)
                     return Json(new { success = false, message = "Mã lý do đã tồn tại!" });
                 item.ReasonType = !string.IsNullOrEmpty(item.ReasonType) ? item.ReasonType : "";
                 item.RowCreatedAt = DateTime.Now;
                 item.RowUpdatedAt = DateTime.Now;
                 item.RowCreatedBy = currentUser.UserID;
                 db.Insert<DC_Reason>(item);
                 return Json(new { success = true, ReasonID = item.ReasonID, RowCreatedBy = item.RowCreatedBy, RowCreatedAt = item.RowCreatedAt });
             }
             else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
             {
                 item.ReasonType = !string.IsNullOrEmpty(item.ReasonType) ? item.ReasonType : "";
                 item.RowCreatedAt = item.RowCreatedAt;
                 item.RowUpdatedAt = DateTime.Now;
                 item.RowCreatedBy = currentUser.UserID;
                 db.Update<DC_Reason>(item);
                 return Json(new { success = true });
             }
             else
                 return Json(new { success = false, message = "Bạn không có quyền" });
         }
         else
         {
             return Json(new { success = false, message = "Chưa nhập giá trị" });
         }
     }
     catch (Exception e)
     {
         log.Error("DeliveryUOMManage - Create - " + e.Message);
         return Json(new { success = false, message = e.Message });
     }
     finally { db.Close(); }
 }
Ejemplo n.º 7
0
        public ActionResult CreatePO(string data, string printer, string delivery)
        {
            var dbConn = new OrmliteConnection().openConn();
            if (userAsset.ContainsKey("Insert") && userAsset["Insert"])
            {
                try
                {
                    string[] separators = { "@@" };
                    var listdata = data.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                    string PONumber = "";
                    string datetimeSO = DateTime.Now.ToString("yyMMdd");
                    var existSO = dbConn.SingleOrDefault<DC_AD_PO_Header>("SELECT id, PONumber FROM DC_AD_PO_Header ORDER BY Id DESC");
                    if (existSO != null)
                    {
                        var nextNo = Int32.Parse(existSO.PONumber.Substring(8, 5)) + 1;
                        PONumber = "PO" + datetimeSO + String.Format("{0:00000}", nextNo);
                    }
                    else
                    {
                        PONumber = "PO" + datetimeSO + "00001";
                    }
                    if (!string.IsNullOrEmpty(delivery))
                    {
                        DateTime fromDateValue;
                        if (!DateTime.TryParseExact(delivery, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out fromDateValue))
                        {
                            return Json(new { message = "Ngày tạo không đúng." });
                        }
                    }
                    var detail = new DC_AD_PO_Detail();
                    foreach (var item in listdata)
                    {
                        if (dbConn.Select<SOHeader>(s => s.Status != "Mới" && s.SONumber == item).Count() > 0)
                        {
                            return Json(new { success = false, message = "Không thể đặt hàng." });
                        }
                        foreach (var dtSO in dbConn.Select<SODetail>(s => s.SONumber == item).ToList())
                        {
                            if (dbConn.Select<DC_AD_PO_Detail>(s => s.PONumber == PONumber && s.ItemCode == dtSO.ItemCode).Count() > 0)
                            {
                                var success = dbConn.Execute(@"UPDATE DC_AD_PO_Detail Set Qty = @Qty, TotalAmt =@TotalAmt ,UpdatedAt = @UpdatedAt, UpdatedBy =  @UpdatedBy, Price = @Price
                                    WHERE PONumber = '" + PONumber + "' AND ItemCode = '" + dtSO.ItemCode + "'", new
                                    {
                                        Qty = dbConn.Select<DC_AD_PO_Detail>(s => s.PONumber == PONumber && s.ItemCode == dtSO.ItemCode).Sum(s => s.Qty) + dtSO.Qty,
                                        TotalAmt = dbConn.Select<DC_AD_PO_Detail>(s => s.PONumber == PONumber && s.ItemCode == dtSO.ItemCode).Sum(s => s.TotalAmt)+dtSO.TotalAmt,
                                        Price = dtSO.Price,
                                        UpdatedBy = currentUser.UserID,
                                        UpdatedAt = DateTime.Now,
                                    }) == 1;
                                if (!success)
                                {
                                    return Json(new { success = false, message = "Không thể lưu" });
                                }
                            }
                            else
                            {
                                detail.PONumber = PONumber;
                                detail.ItemCode = !string.IsNullOrEmpty(dtSO.ItemCode) ? dtSO.ItemCode : "";
                                detail.ItemName = !string.IsNullOrEmpty(dtSO.ItemName) ? dtSO.ItemName : "";
                                detail.Price = dtSO.Price;
                                detail.Qty = dtSO.Qty;
                                detail.TotalAmt = dtSO.TotalAmt;
                                detail.UnitID = !string.IsNullOrEmpty(dtSO.UnitID) ? dtSO.UnitID : "";
                                detail.UnitName = !string.IsNullOrEmpty(dtSO.UnitName) ? dtSO.UnitName : "";
                                detail.Note = "";
                                detail.Status = "Mới";
                                detail.CreatedBy = currentUser.UserID;
                                detail.CreatedAt = DateTime.Now;
                                detail.UpdatedBy = "";
                                detail.UpdatedAt = DateTime.Parse("1900-01-01");
                                dbConn.Insert<DC_AD_PO_Detail>(detail);
                            }
                        }
                        dbConn.Update<SOHeader>(set: "Status = N'Đã đặt hàng'", where: "SONumber = '" + item + "'");
                    }
                    var header = new DC_AD_PO_Header();
                    header.PONumber = PONumber;
                    header.PODate = DateTime.Now;
                    header.DeliveryDate = !string.IsNullOrEmpty(delivery) ? DateTime.Parse(DateTime.ParseExact(delivery, "dd/MM/yyyy", CultureInfo.InvariantCulture).ToString("yyyy-MM-dd")) : DateTime.Now;
                    header.PrinterID = printer;
                    header.PrinterName = dbConn.Select<DC_AD_Printer>(s => s.PrinterID == printer).FirstOrDefault().PrinterName;
                    header.TotalQty = dbConn.Select<DC_AD_PO_Detail>(s => s.PONumber == PONumber).Sum(s => s.Qty);
                    header.TotalAmt = dbConn.Select<DC_AD_PO_Detail>(s => s.PONumber == PONumber).Sum(s => s.TotalAmt);
                    header.Note = "";
                    header.Status = "Nhà in đang xử lý";
                    header.CreatedBy = currentUser.UserID;
                    header.CreatedAt = DateTime.Now;
                    header.UpdatedBy = "";
                    header.UpdatedAt = DateTime.Parse("1900-01-01");
                    dbConn.Insert<DC_AD_PO_Header>(header);

                }
                catch (Exception ex)
                {
                    return Json(new { success = false, message = ex.Message });
                }
                return Json(new { success = true });
            }
            else
            {
                return Json(new { success = false, message = "Không có quyền tạo." });
            }
        }
Ejemplo n.º 8
0
        public ActionResult Create(FormCollection form)
        {
            IDbConnection db = new OrmliteConnection().openConn();
            try
            {
                if (!string.IsNullOrEmpty(form["RoleName"]))
                {
                    var item = new Auth_Role();
                    item.RoleName = form["RoleName"];
                    item.IsActive = form["IsActive"] != null ? Convert.ToBoolean(form["IsActive"]) : false;
                    item.Note = !string.IsNullOrEmpty(form["Note"]) ? form["Note"] : "";
                    if (userAsset.ContainsKey("Insert") && userAsset["Insert"] &&
                        string.IsNullOrEmpty(form["RoleID"]))    // Tạo mới
                    {
                        item.RowCreatedAt = DateTime.Now;
                        item.RowCreatedBy = currentUser.UserID;
                        db.Insert<Auth_Role>(item);
                        long lastID = db.GetLastInsertId();
                        if (lastID > 0)
                        {
                            // Thêm Role vào Auth_Action
                            db.ExecuteSql("EXEC p_Auth_Role_GenerateAction_By_RoleID " + lastID + "," + currentUser.UserID);
                        }
                        return Json(new { success = true, insert = true, RoleID = lastID, createdat = item.RowCreatedAt, createdby = item.RowCreatedBy });
                    }
                    else if (userAsset.ContainsKey("Insert") && userAsset["Insert"] &&
                            Convert.ToInt32(form["RoleID"]) > 0 &&
                            Convert.ToInt32(form["IsCopy"]) == 1)  // Sao chép
                    {
                        item.RoleID = Convert.ToInt32(form["RoleID"]);
                        item.RowCreatedAt = DateTime.Now;
                        item.RowCreatedBy = currentUser.UserID;
                        db.Insert<Auth_Role>(item);
                        long lastID = db.GetLastInsertId();
                        if (lastID > 0)
                        {
                            // Sao chép Action RoleID đã chọn vào RoleID vừa tạo
                            db.ExecuteSql("p_Auth_Role_CopyAction_By_RoleID " + item.RoleID + "," + lastID + "," + currentUser.UserID);
                        }
                        return Json(new { success = true, insert = true, RoleID = lastID, createdat = item.RowCreatedAt, createdby = item.RowCreatedBy });
                    }
                    else if (userAsset.ContainsKey("Update") && userAsset["Update"] &&
                            Convert.ToInt32(form["RoleID"]) > 0)    // Cập nhật
                    {
                        item.RoleID = Convert.ToInt32(form["RoleID"]);
                        item.RowCreatedAt = DateTime.Parse(form["RowCreatedAt"]);
                        item.RowCreatedBy = form["RowCreatedBy"];
                        item.RowUpdatedAt = DateTime.Now;
                        item.RowUpdatedBy = currentUser.UserID;
                        if (item.RowCreatedBy != "system")
                        {
                            db.Update<Auth_Role>(item);
                        }

                        return Json(new { success = true, RoleID = item.RoleID });
                    }
                    else
                        return Json(new { success = false, message = "Bạn không có quyền" });
                }
                else
                {
                    return Json(new { success = false, message = "Chưa nhập giá trị" });
                }
            }
            catch (Exception e)
            {
                log.Error("HOAdminAuthRole - Create - " + e.Message);
                return Json(new { success = false, message = e.Message });
            }
            finally { db.Close(); }
        }
Ejemplo n.º 9
0
        //public ActionResult ReadDetail([DataSourceRequest] DataSourceRequest request, string SONumber)
        //{
        //    log4net.Config.XmlConfigurator.Configure();
        //    string whereCondition = "";
        //    if (request.Filters.Count > 0)
        //    {
        //        whereCondition = " AND " + new KendoApplyFilter().ApplyFilter(request.Filters[0]);
        //    }
        //    var data = new DC_AD_SO_Detail().GetPage(request, whereCondition, SONumber);
        //    return Json(data);
        //}
        public ActionResult Update([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")] IEnumerable<Products> list, string SONumber)
        {
            var dbConn = new OrmliteConnection().openConn();
            try
            {
                if (list != null && ModelState.IsValid)
                {
                    foreach (var item in list)
                    {
                        if (item.Qty > 0)
                        {
                            //string SONumber = Request["SONumber"];
                            var header = new SOHeader();
                            var detail = new SODetail();

                            if (dbConn.Select<SODetail>(s => s.SONumber == SONumber && s.ItemCode == item.Code).Count() > 0)
                            {
                                dbConn.Update<SODetail>(set: "Qty = '" + item.Qty + "', TotalAmt = '" + item.Qty * item.Price + "'", where: "SONumber = '" + SONumber + "'");
                            }
                            else
                            {
                                var data = new SODetail();
                                data.ItemName = item.Name;
                                data.ItemCode = item.Code;
                                data.Note = "";
                                data.Price = item.VATPrice;
                                data.Qty = item.Qty;
                                data.SONumber = SONumber;
                                data.UnitID = item.Unit;
                                data.UnitName = dbConn.Select<INUnit>(s => s.UnitID == item.Unit).FirstOrDefault().UnitName;
                                data.TotalAmt = item.Qty * item.VATPrice;
                                data.Status = "";
                                data.CreatedAt = DateTime.Now;
                                data.CreatedBy = currentUser.UserID;
                                //data.UpdatedAt = DateTime.Parse("1900-01-01");
                                data.UpdatedAt = DateTime.Now;
                                data.UpdatedBy = "";
                                dbConn.Insert<SODetail>(data);
                            }
                            dbConn.Update<SOHeader>(set: "TotalQty ='" + dbConn.Select<SODetail>(s => s.SONumber == SONumber).Sum(s => s.Qty) + "', TotalAmt = '" + +dbConn.Select<SODetail>(s => s.SONumber == SONumber).Sum(s => s.TotalAmt) + "'", where: "SONumber ='" + SONumber + "'");

                        }
                        else
                        {
                            dbConn.Delete<SOHeader>(s => s.SONumber == SONumber);
                            ModelState.AddModelError("error", "Đơn hàng được tạo khi số lượng > 0");
                            return Json(list.ToDataSourceResult(request, ModelState));
                        }
                    }
                }
                dbConn.Close();
            }
            catch (Exception e)
            {
                dbConn.Close();
                ModelState.AddModelError("error", e.Message);
                return Json(list.ToDataSourceResult(request, ModelState));
            }
            return Json(new { sussess = true });
        }
Ejemplo n.º 10
0
        public ActionResult Create(DC_Formula item)
        {
            IDbConnection db = new OrmliteConnection().openConn();
            try
            {
                if (!string.IsNullOrEmpty(item.FormulaName) && !string.IsNullOrEmpty(item.Formula))
                {
                    var isExist = db.SingleOrDefault<DC_Formula>("FormulaID={0}", item.FormulaID);
                    item.FormulaName = !string.IsNullOrEmpty(item.FormulaName) ? item.FormulaName : "";
                    item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note : "";
                    item.Formula = !string.IsNullOrEmpty(item.Formula) ? item.Formula : "";

                    if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
                    {
                        if (isExist != null)
                            return Json(new { success = false, message = "Mã công thức đã tồn tại!" });

                        string id = "";
                        var checkID = db.SingleOrDefault<DC_Formula>("SELECT FormulaID,ID FROM DC_Formula ORDER BY ID DESC");
                        if (checkID != null)
                        {
                            var nextNo = int.Parse(checkID.FormulaID.Substring(2, checkID.FormulaID.Length - 2)) + 1;
                            id = "FM" + String.Format("{0:000000}", nextNo);
                        }
                        else
                        {
                            id = "FM000001";
                        }
                        item.FormulaID = id;
                        item.FormulaName = !string.IsNullOrEmpty(item.FormulaName) ? item.FormulaName : "";
                        item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note : "";
                        item.Formula = !string.IsNullOrEmpty(item.Formula) ? item.Formula : "";
                        item.CreatedAt = DateTime.Now;
                        item.CreatedBy = currentUser.UserID;
                        item.UpdatedAt = DateTime.Parse("1900-01-01");
                        item.UpdatedBy = "";
                        db.Insert(item);
                        return Json(new { success = true, FormulaID = item.FormulaID, CreatedBy = item.CreatedBy, CreatedAt = item.CreatedAt });
                    }
                    else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
                    {
                        item.FormulaName = !string.IsNullOrEmpty(item.FormulaName) ? item.FormulaName : "";
                        item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note : "";
                        item.Formula = !string.IsNullOrEmpty(item.Formula) ? item.Formula : "";
                        item.Status = item.Status;
                        item.CreatedAt = item.CreatedAt;
                        item.CreatedBy = currentUser.UserID;
                        item.UpdatedAt = DateTime.Now;
                        item.UpdatedBy = currentUser.UserID;
                        db.Update(item);
                        return Json(new { success = true });
                    }
                    else
                        return Json(new { success = false, message = "Bạn không có quyền" });
                }
                else
                {
                    return Json(new { success = false, message = "Chưa nhập đủ giá trị" });
                }
            }
            catch (Exception e)
            {
                log.Error("Formula" + item.FormulaID + " - Create - " + e.Message);
                return Json(new { success = false, message = e.Message });
            }
            finally { db.Close(); }
        }
Ejemplo n.º 11
0
        public ActionResult Create(Master_Announcement item)
        {
            //if (form.AllKeys.Contains("TextContent"))
            //{
            //    item.TextContent = form.Get("TextContent");
            //}

            //CHECK IS NULL VALUE
            if (string.IsNullOrEmpty(item.TextContent))
            {
                item.TextContent = "";
            }
            if (string.IsNullOrEmpty(item.HTMLContent))
            {
                item.HTMLContent = "";
            }
            if (string.IsNullOrEmpty(item.Title))
            {
                item.Title = "";
            }

            IDbConnection dbConn = new OrmliteConnection().openConn();

            try
            {
                    var isExist = dbConn.GetByIdOrDefault<Master_Announcement>(item.AnnouncementID);

                    if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
                    {
                        if (isExist != null)
                        {
                            return Json(new { success = false, message = "Đối tượng này đã tồn tại." });
                        }
                        item.CreatedAt = DateTime.Now;
                        item.CreatedBy = currentUser.UserID;

                        dbConn.Insert<Master_Announcement>(item);
                        long lastInsertId = dbConn.GetLastInsertId();
                        dbConn.Close();
                        return Json(new { success = true, AnnouncementID = lastInsertId, createdat = item.CreatedAt, createdby = item.CreatedBy });
                    }
                    else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
                    {
                        item.UpdatedAt = DateTime.Now;
                        item.CreatedBy = currentUser.UserID;
                        dbConn.Update<Master_Announcement>(item);
                        dbConn.Close();
                        return Json(new { success = true });
                    }
                    else
                        return Json(new { success = false, message = "You don't have permission" });
            }
            catch (Exception ex)
            {
                log.Error("AD_Announcement - Create - " + ex.Message);
                return Json(new { success = false, message = ex.Message });
            }
            finally
            {
                dbConn.Close();
            }
        }
Ejemplo n.º 12
0
        public ActionResult Create(Auth_User item)
        {
            IDbConnection db = new OrmliteConnection().openConn();
            try
            {
                if (!string.IsNullOrEmpty(item.UserID) &&
                    !string.IsNullOrEmpty(item.DisplayName) &&
                    !string.IsNullOrEmpty(item.FullName))
                {
                    var isExist = db.GetByIdOrDefault<Auth_User>(item.UserID);
                    item.Phone = !string.IsNullOrEmpty(item.Phone) ? item.Phone : "";
                    item.Email = !string.IsNullOrEmpty(item.Email) ? item.Email : "";
                    item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note : "";
                    if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.RowCreatedAt == null && item.RowCreatedBy == null)
                    {
                        if(isExist != null)
                            return Json(new { success = false, message = "Người dùng đã tồn tại." });
                        item.Password = SqlHelper.GetMd5Hash("123456");
                        item.RowCreatedAt = DateTime.Now;
                        item.RowCreatedBy = currentUser.UserID;
                        db.Insert<Auth_User>(item);
                        return Json(new { success = true, UserID = item.UserID, RowCreatedAt = item.RowCreatedAt, RowCreatedBy = item.RowCreatedBy });
                    }
                    else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
                    {
                        item.Password = isExist.Password;
                        item.RowUpdatedAt = DateTime.Now;
                        item.RowUpdatedBy = currentUser.UserID;

                        if (isExist.RowCreatedBy != "system")
                        {
                            db.Update<Auth_User>(item);
                        }
                        else
                        {
                            return Json(new { success = false, message = "Dữ liệu này không cho chỉnh sửa liên hệ admin để biết thêm chi tiết" });
                        }
                        return Json(new { success = true });
                    }
                    else
                        return Json(new { success = false, message = "Bạn không có quyền" });
                }
                else
                {
                    return Json(new { success = false, message = "Chưa nhập giá trị" });
                }
            }
            catch (Exception e)
            {
                log.Error("AD_User - Create - " + e.Message);
                return Json(new { success = false, message = e.Message });
            }
            finally { db.Close(); }
        }
Ejemplo n.º 13
0
        public ActionResult UpdateDetail([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")] IEnumerable<DC_AD_Picking_Detail> list)
        {
            var dbConn = new OrmliteConnection().openConn();
            try
            {
                if (list != null && ModelState.IsValid)
                {
                    foreach (var item in list)
                    {
                        if (string.IsNullOrEmpty(item.PickingNumber))
                        {
                            ModelState.AddModelError("", "Số picking không tồn tại");
                            return Json(list.ToDataSourceResult(request, ModelState));
                        }
                        if (item.Qty <= 0)
                        {
                            ModelState.AddModelError("", "Số lượng phải lớn hơn 0.");
                            return Json(list.ToDataSourceResult(request, ModelState));
                        }
                        dbConn.Update<DC_AD_Picking_Detail>(set: "Qty = '" + item.Qty + "', TotalAmt = '" + item.Price * item.Qty + "'", where: "ID = '" + item.Id + "'");
                        var success = dbConn.Execute(@"UPDATE DC_AD_Picking_Header Set TotalQty = @TotalQty, TotalAmt =@TotalAmt
                            WHERE PickingNumber = '" + item.PickingNumber +"'", new
                            {
                                TotalQty = dbConn.Select<DC_AD_Picking_Detail>(s => s.PickingNumber == item.PickingNumber).Sum(s => s.Qty),
                                TotalAmt = dbConn.Select<DC_AD_Picking_Detail>(s => s.PickingNumber == item.PickingNumber).Sum(s => s.TotalAmt),
                            }) == 1;
                        if (!success)
                        {
                            return Json(new { success = false, message = "Không thể lưu" });
                        }
                    }

                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("error", e.Message);
                return Json(list.ToDataSourceResult(request, ModelState));
            }
            return Json(new { sussess = true });
        }
Ejemplo n.º 14
0
 public ActionResult PickingOut(string data, string WHID, string WHLID)
 {
     var dbConn = new OrmliteConnection().openConn();
     try
     {
         string[] separators = { "@@" };
         var listdata = data.Split(separators, StringSplitOptions.RemoveEmptyEntries);
         string TransactionID = "";
         string datetimeSO = DateTime.Now.ToString("yyMMdd");
         var existSO = dbConn.SingleOrDefault<DC_AD_Transaction>("SELECT id, TransactionID FROM DC_AD_Transaction ORDER BY Id DESC");
         var detail = new DC_AD_Transaction();
         if (existSO != null)
         {
             var nextNo = Int32.Parse(existSO.TransactionID.Substring(8, 5)) + 1;
             TransactionID = "TS" + datetimeSO + String.Format("{0:00000}", nextNo);
         }
         else
         {
             TransactionID = "TS" + datetimeSO + "00001";
         }
         foreach (var item in listdata)
         {
             if (dbConn.Select<DC_AD_Picking_Header>(s => s.Status != "Mới" && s.PickingNumber == item).Count() > 0)
             {
                 return Json(new { success = false, message = item + " đã được nhập kho rồi." });
             }
             foreach (var po in dbConn.Select<DC_AD_Picking_Detail>(s => s.PickingNumber == item).ToList())
             {
                 detail.TransactionID = TransactionID;
                 detail.TransactionType = "Out";
                 detail.TransactionDate = DateTime.Now;
                 detail.RefID = item;
                 detail.ItemCode = !string.IsNullOrEmpty(po.ItemCode) ? po.ItemCode : "";
                 detail.ItemName = !string.IsNullOrEmpty(po.ItemName) ? po.ItemName : "";
                 detail.UnitID = !string.IsNullOrEmpty(po.UnitID) ? po.UnitID : "";
                 detail.UnitName = !string.IsNullOrEmpty(po.UnitName) ? po.UnitName : "";
                 detail.Qty = po.Qty != null ? po.Qty : 0;
                 detail.Price = po.Price != null ? po.Price : 0;
                 detail.TotalAmt = po.TotalAmt != null ? po.TotalAmt : 0;
                 detail.WHID = !string.IsNullOrEmpty(WHID) ? WHID : "";
                 detail.WHLID = !string.IsNullOrEmpty(WHLID) ? WHLID : "";
                 detail.Note = !string.IsNullOrEmpty(po.Note) ? po.Note : "";
                 detail.Status = "Đang giao hàng";
                 detail.CreatedBy = currentUser.UserID;
                 detail.CreatedAt = DateTime.Now;
                 detail.UpdatedBy = "";
                 detail.UpdatedAt = DateTime.Parse("1900-01-01");
                 detail.PrinterID = dbConn.Select<DC_AD_Picking_Header>(s => s.PickingNumber == item).FirstOrDefault().PrinterID;
                 detail.PrinterName = dbConn.Select<DC_AD_Picking_Header>(s => s.PickingNumber == item).FirstOrDefault().PrinterName;
                 dbConn.Insert<DC_AD_Transaction>(detail);
                 dbConn.Update<SOHeader>(set: "Status = N'Đang giao hàng'", where: "SONumber = '" + po.SONumber + "'");
             }
             dbConn.Update<DC_AD_Picking_Header>(set: "Status = N'Đang giao hàng'", where: "PickingNumber = '" + item + "'");
         }
     }
     catch (Exception e)
     {
         return Json(new { success = false, message = e.Message });
     }
     return Json(new { success = true });
 }
Ejemplo n.º 15
0
        public ActionResult UpdateDetail([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")] IEnumerable<SODetail> list)
        {
            var dbConn = new OrmliteConnection().openConn();
            if (userAsset.ContainsKey("Update") && userAsset["Update"])
            {

                if (list != null)//&& ModelState.IsValid)
                {
                    foreach (var item in list)
                    {
                        if (dbConn.Select<SOHeader>(s => s.SONumber == item.SONumber && s.Status != "Mới").Count() > 0)
                        {
                            return Json(new { success = false, message = "Đơn hàng đã xác nhận nên không được xóa." });
                        }
                        else if (item.Qty > 0)
                        {
                            var isExist = dbConn.SingleOrDefault<SODetail>("SONumber = {0} AND ItemCode = {1}", item.SONumber, item.ItemCode);
                            if (isExist != null)
                            {
                                try
                                {
                                    isExist.Qty = item.Qty;
                                    isExist.TotalAmt = item.Qty * item.Price;
                                    isExist.UpdatedAt = DateTime.Now;
                                    isExist.UpdatedBy = currentUser.UserID;
                                    dbConn.Update<SODetail>(isExist);
                                    //dbConn.Update<SODetail>(set: "Qty = '" + item.Qty + "', TotalAmt = '" + item.Qty * item.Price + "',UpdatedAt = '" + DateTime.Now + "', UpdatedBy ='" + currentUser.UserID + "'", where: "SONumber = '" + item.SONumber + "' AND ItemCode ='" + item.ItemCode + "'");
                                    dbConn.Update<SOHeader>(set: "UpdatedBy='" + currentUser.UserID + "',TotalQty ='" + dbConn.Select<SODetail>(s => s.SONumber == item.SONumber).Sum(s => s.Qty) + "', TotalAmt = '" + dbConn.Select<SODetail>(s => s.SONumber == item.SONumber).Sum(s => s.TotalAmt) + "'", where: "SONumber ='" + item.SONumber + "'");
                                    var success = dbConn.Execute(@"UPDATE SOHeader Set UpdatedAt = @UpdatedAt WHERE SONumber = '" + item.SONumber + "'",
                                                        new
                                                        {
                                                            UpdatedAt = DateTime.Now,
                                                        }) == 1;
                                }
                                catch (Exception ex)
                                {
                                    ModelState.AddModelError("error", ex.Message);
                                    return Json(list.ToDataSourceResult(request, ModelState));
                                }
                            }
                        }
                        else
                        {
                            ModelState.AddModelError("error", "Đơn hàng được tạo khi số lượng > 0");
                            return Json(list.ToDataSourceResult(request, ModelState));
                        }
                    }
                }
                dbConn.Close();
                return Json(new { sussess = true });
            }
            else
            {
                dbConn.Close();
                ModelState.AddModelError("error", "Bạn không có quyền cập nhật.");
                return Json(list.ToDataSourceResult(request, ModelState));
            }
        }
Ejemplo n.º 16
0
 public ActionResult Create(Customer item)
 {
     IDbConnection db = new OrmliteConnection().openConn();
     try
     {
         if (!string.IsNullOrEmpty(item.CustomerName)
             )
         {
             var isExist = db.SingleOrDefault<Customer>("CustomerID={0}", item.CustomerID);
             item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note : "";
             item.Shoptype = !string.IsNullOrEmpty(item.Shoptype) ? item.Shoptype : "";
             item.Phone = !string.IsNullOrEmpty(item.Phone) ? item.Phone : "";
             item.Email = !string.IsNullOrEmpty(item.Email) ? item.Email : "";
             item.Address = !string.IsNullOrEmpty(item.Address) ? item.Address : "";
             item.Fax = !string.IsNullOrEmpty(item.Fax) ? item.Fax : "";
             item.Agent = !string.IsNullOrEmpty(item.Agent) ? item.Agent : "";
             item.Birthday = !string.IsNullOrEmpty(item.Birthday) ? item.Birthday : "";
             item.Gender = !string.IsNullOrEmpty(item.Gender) ? item.Gender : "";
             item.LevelHirerachy1 = !string.IsNullOrEmpty(item.LevelHirerachy1) ? item.LevelHirerachy1 : "";
             item.LevelHirerachy2 = !string.IsNullOrEmpty(item.LevelHirerachy2) ? item.LevelHirerachy2 : "";
             item.LevelHirerachy3 = !string.IsNullOrEmpty(item.LevelHirerachy3) ? item.LevelHirerachy3 : "";
             item.LevelHirerachy4 = !string.IsNullOrEmpty(item.LevelHirerachy4) ? item.LevelHirerachy4 : "";
             item.Desc = !string.IsNullOrEmpty(item.Desc) ? item.Desc : "";
             item.ProvinceID = !string.IsNullOrEmpty(item.ProvinceID) ? item.ProvinceID : "";
             item.DistrictID = !string.IsNullOrEmpty(item.DistrictID) ? item.DistrictID : "";
             if (item.ProvinceID=="")
                 item.DistrictID = "";
             if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
             {
                 if (isExist != null)
                     return Json(new { success = false, message = "Mã khách hàng đã tồn tại" });
                 string id = "";
                 var checkID = db.SingleOrDefault<Customer>("SELECT CustomerID, Id FROM dbo.Customer ORDER BY Id DESC");
                 if (checkID != null)
                 {
                     var nextNo = int.Parse(checkID.CustomerID.Substring(2, checkID.CustomerID.Length - 2)) + 1;
                     id = "C" + String.Format("{0:00000000}", nextNo);
                 }
                 else
                 {
                     id = "C00000001";
                 }
                 item.CustomerID = id;
                 item.CustomerName = !string.IsNullOrEmpty(item.CustomerName) ? item.CustomerName : "";
                 item.CreatedAt = DateTime.Now;
                 item.UpdatedBy = "";
                 item.UpdatedAt = DateTime.Parse("1900-01-01");
                 item.CreatedBy = currentUser.UserID;
                 db.Insert(item);
                 return Json(new { success = true, CustomerID = item.CustomerID, CreatedBy = item.CreatedBy, CreatedAt = item.CreatedAt });
             }
             else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
             {
                 item.CustomerName = !string.IsNullOrEmpty(item.CustomerName) ? item.CustomerName : "";
                 item.CreatedAt = item.CreatedAt;
                 item.UpdatedAt = DateTime.Now;
                 item.CreatedBy = isExist.CreatedBy;
                 item.UpdatedBy = currentUser.UserID;
                 db.Update(item);
                 return Json(new { success = true });
             }
             else
                 return Json(new { success = false, message = "Bạn không có quyền" });
         }
         else
         {
             return Json(new { success = false, message = "Chưa nhập đủ giá trị" });
         }
     }
     catch (Exception e)
     {
         log.Error("Customerion - Create - " + e.Message);
         return Json(new { success = false, message = e.Message });
     }
     finally { db.Close(); }
 }
Ejemplo n.º 17
0
        public ActionResult Create(SalesPerson item)
        {
            IDbConnection db = new OrmliteConnection().openConn();
            try
            {
                if (!string.IsNullOrEmpty(item.SalesPersonID) &&
                    !string.IsNullOrEmpty(item.SalesPersonName)
                    )
                {
                    var isExist = db.SingleOrDefault<SalesPerson>("SalesPersonID={0}", item.SalesPersonID);

                    if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
                    {
                        if (isExist != null)
                            return Json(new { success = false, message = "Mã nhân viên đã tồn tại" });
                        item.SalesPersonName = !string.IsNullOrEmpty(item.SalesPersonName) ? item.SalesPersonName : "";
                        item.CompanyID = !string.IsNullOrEmpty(item.CompanyID) ? item.CompanyID : "";
                        //item.Gender = item.Gender;
                        item.Description = !string.IsNullOrEmpty(item.Description) ? item.Description : "";
                        item.Phone = !string.IsNullOrEmpty(item.Phone) ? item.Phone : "";
                        //item.DateOfBirth = !string.IsNullOrEmpty(item.MobilePhone) ? item.MobilePhone : "";
                        item.Email = !string.IsNullOrEmpty(item.Email) ? item.Email : "";
                        item.CreatedAt = DateTime.Now;
                        item.UpdatedAt = DateTime.Now;
                        item.CreatedBy = currentUser.UserID;
                        item.UpdatedBy = currentUser.UserID;
                        db.Insert<SalesPerson>(item);

                        return Json(new { success = true, SalesPersonID = item.SalesPersonID, CreatedBy = item.CreatedBy, CreatedAt = item.CreatedAt, });
                    }
                    else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
                    {
                        item.SalesPersonName = !string.IsNullOrEmpty(item.SalesPersonName) ? item.SalesPersonName : "";
                        item.CompanyID = !string.IsNullOrEmpty(item.CompanyID) ? item.CompanyID : "";
                        //item.Gender = item.Gender;
                        item.Description = !string.IsNullOrEmpty(item.Description) ? item.Description : "";
                        item.Phone = !string.IsNullOrEmpty(item.Phone) ? item.Phone : "";
                        //item.DateOfBirth = !string.IsNullOrEmpty(item.MobilePhone) ? item.MobilePhone : "";
                        item.Email = !string.IsNullOrEmpty(item.Email) ? item.Email : "";
                        item.CreatedBy = isExist.CreatedBy;
                        item.CreatedAt = isExist.CreatedAt;
                        item.UpdatedAt = DateTime.Now;
                        item.UpdatedBy = currentUser.UserID;
                        db.Update<SalesPerson>(item);

                        return Json(new { success = true });
                    }
                    else
                        return Json(new { success = false, message = "Bạn không có quyền" });
                }
                else
                {
                    return Json(new { success = false, message = "Chưa nhập đủ giá trị" });
                }
            }
            catch (Exception e)
            {
                log.Error("SalesPerson - Create - " + e.Message);
                return Json(new { success = false, message = e.Message });
            }
            finally { db.Close(); }
        }
Ejemplo n.º 18
0
 public ActionResult Create(DC_AD_Printer item)
 {
     IDbConnection db = new OrmliteConnection().openConn();
     try
     {
         if (!string.IsNullOrEmpty(item.PrinterName)
             )
         {
             var isExist = db.SingleOrDefault<DC_AD_Printer>("PrinterID={0}", item.PrinterID);
             item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note : "";
             item.DfltAddress = !string.IsNullOrEmpty(item.DfltAddress) ? item.DfltAddress : "";
             item.Phone = !string.IsNullOrEmpty(item.Phone) ? item.Phone : "";
             item.Email = !string.IsNullOrEmpty(item.Email) ? item.Email : "";
             item.WHAddress = !string.IsNullOrEmpty(item.WHAddress) ? item.WHAddress : "";
             item.ShippingAddress = !string.IsNullOrEmpty(item.ShippingAddress) ? item.ShippingAddress : "";
             item.ContactPhone = !string.IsNullOrEmpty(item.ContactPhone) ? item.ContactPhone : "";
             item.ContactName = !string.IsNullOrEmpty(item.ContactName) ? item.ContactName : "";
             if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
             {
                 if (isExist != null)
                     return Json(new { success = false, message = "Mã máy in đã tồn tại" });
                 string id = "";
                 var checkID = db.SingleOrDefault<DC_AD_Printer>("SELECT PrinterID, Id FROM dbo.DC_AD_Printer ORDER BY Id DESC");
                 if (checkID != null)
                 {
                     var nextNo = int.Parse(checkID.PrinterID.Substring(2, checkID.PrinterID.Length - 2)) + 1;
                     id = "PR" + String.Format("{0:00000000}", nextNo);
                 }
                 else
                 {
                     id = "PR00000001";
                 }
                 item.PrinterID = id;
                 item.PrinterName = !string.IsNullOrEmpty(item.PrinterName) ? item.PrinterName : "";
                 item.CreatedAt = DateTime.Now;
                 item.UpdatedAt = DateTime.Now;
                 item.CreatedBy = currentUser.UserID;
                 item.UpdatedBy = currentUser.UserID;
                 db.Insert(item);
                 return Json(new { success = true, PrinterID = item.PrinterID, CreatedBy = item.CreatedBy, CreatedAt = item.CreatedAt });
             }
             else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
             {
                 item.PrinterName = !string.IsNullOrEmpty(item.PrinterName) ? item.PrinterName : "";
                 item.CreatedAt = item.CreatedAt;
                 item.UpdatedAt = DateTime.Now;
                 item.CreatedBy = currentUser.UserID;
                 item.UpdatedBy = currentUser.UserID;
                 db.Update(item);
                 return Json(new { success = true });
             }
             else
                 return Json(new { success = false, message = "Bạn không có quyền" });
         }
         else
         {
             return Json(new { success = false, message = "Chưa nhập đủ giá trị" });
         }
     }
     catch (Exception e)
     {
         log.Error("Printer - Create - " + e.Message);
         return Json(new { success = false, message = e.Message });
     }
     finally { db.Close(); }
 }
Ejemplo n.º 19
0
 public ActionResult Create(DC_LG_Contract item)
 {
     IDbConnection db = new OrmliteConnection().openConn();
     try
     {
         if (!string.IsNullOrEmpty(item.ContractID) &&
             !string.IsNullOrEmpty(item.ContractName)
             )
         {
             var isExist = db.SingleOrDefault<DC_LG_Contract>("ContractID={0}", item.ContractID);
             var data = Request["TransporterID"];
             //string data = !string.IsNullOrEmpty(item.TransporterID) ? item.TransporterID : "";
             double n;
             item.StartDate = item.StartDate != null ? item.StartDate : DateTime.Now;
             item.EndDate = item.EndDate != null ? item.EndDate : DateTime.Now;
             item.DiscountPercent = double.TryParse(item.DiscountPercent.ToString(),out n) ? item.DiscountPercent/100 : 0;
             if(item.StartDate>item.EndDate)
             {
                 return Json(new { success = false, message = "Ngày kết thúc không thể lớn hơn " + item.StartDate });
             }
             item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note : "";
             item.DiscountPercent = !string.IsNullOrEmpty(item.DiscountPercent.ToString()) ? item.DiscountPercent : 0;
             if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
             {
                 if (isExist != null)
                     return Json(new { success = false, message = "Mã hợp đồng đã tồn tại" });
                 item.ContractName = !string.IsNullOrEmpty(item.ContractName) ? item.ContractName : "";
                 item.CreatedAt = DateTime.Now;
                 item.UpdatedAt = DateTime.Parse("1900-01-01");
                 item.CreatedBy = currentUser.UserID;
                 db.Insert(item);
                 db.Delete<DC_LG_Contract_Transporter>(p => p.ContractID ==item.ContractID);
                 if (!string.IsNullOrEmpty(data))
                 {
                     string[] arr = data.Split(',');
                     foreach (string ite in arr)
                     {
                         var detail = new DC_LG_Contract_Transporter();
                         detail.ContractID = item.ContractID;
                         detail.TransporterID = int.Parse(ite);
                         detail.Note = "";
                         detail.UpdatedAt = DateTime.Now;
                         detail.CreatedAt = DateTime.Now;
                         detail.CreatedBy = currentUser.UserID;
                         detail.UpdatedBy = currentUser.UserID;
                         db.Insert<DC_LG_Contract_Transporter>(detail);
                     }
                 }
                 return Json(new { success = true, ContractID = item.ContractID, CreatedBy = item.CreatedBy, CreatedAt = item.CreatedAt, });
             }
             else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
             {
                 item.ContractName = !string.IsNullOrEmpty(item.ContractName) ? item.ContractName : "";
                 item.CreatedBy = isExist.CreatedBy;
                 item.CreatedAt = isExist.CreatedAt;
                 item.UpdatedAt = DateTime.Now;
                 item.UpdatedBy = currentUser.UserID;
                 db.Update(item);
                 db.Delete<DC_LG_Contract_Transporter>(p => p.ContractID == item.ContractID);
                 if (!string.IsNullOrEmpty(data))
                 {
                     string[] arr = data.Split(',');
                     foreach (string ite in arr)
                     {
                         var detail = new DC_LG_Contract_Transporter();
                         detail.ContractID = item.ContractID;
                         detail.TransporterID = int.Parse(ite);
                         detail.Note = "";
                         detail.UpdatedAt = DateTime.Now;
                         detail.CreatedAt = DateTime.Now;
                         detail.CreatedBy = currentUser.UserID;
                         detail.UpdatedBy = currentUser.UserID;
                         db.Insert<DC_LG_Contract_Transporter>(detail);
                     }
                 }
                 return Json(new { success = true });
             }
             else
                 return Json(new { success = false, message = "Bạn không có quyền" });
         }
         else
         {
             return Json(new { success = false, message = "Chưa nhập đủ giá trị" });
         }
     }
     catch (Exception e)
     {
         log.Error("Contract - Create - " + e.Message);
         return Json(new { success = false, message = e.Message });
     }
     finally { db.Close(); }
 }
Ejemplo n.º 20
0
        public ActionResult Create(Company item)
        {
            IDbConnection db = new OrmliteConnection().openConn();
            try
            {
                if (!string.IsNullOrEmpty(item.CompanyID) &&
                    !string.IsNullOrEmpty(item.CompanyName)
                    )
                {
                    var isExist = db.SingleOrDefault<Company>("CompanyID={0}", item.CompanyID);

                    if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
                    {
                        if (isExist != null)
                            return Json(new { success = false, message = "Mã công ty đã tồn tại" });
                        item.CompanyName = !string.IsNullOrEmpty(item.CompanyName) ? item.CompanyName : "";
                        item.ShortName = !string.IsNullOrEmpty(item.ShortName) ? item.ShortName : "";
                        item.EnglishName = !string.IsNullOrEmpty(item.EnglishName) ? item.EnglishName : "";
                        item.SubDomain = !string.IsNullOrEmpty(item.SubDomain) ? item.SubDomain : "";
                        item.Phone = !string.IsNullOrEmpty(item.Phone) ? item.Phone : "";
                        item.MobilePhone = !string.IsNullOrEmpty(item.MobilePhone) ? item.MobilePhone : "";
                        item.Fax = !string.IsNullOrEmpty(item.Fax) ? item.Fax : "";
                        item.Email = !string.IsNullOrEmpty(item.Email) ? item.Email : "";
                        item.PersonalEmail = !string.IsNullOrEmpty(item.PersonalEmail) ? item.PersonalEmail : "";
                        item.Address = !string.IsNullOrEmpty(item.Address) ? item.Address : "";
                        item.Website = !string.IsNullOrEmpty(item.Website) ? item.Website : "";
                        item.Descr = !string.IsNullOrEmpty(item.Descr) ? item.Descr : "";
                        item.CreatedAt = DateTime.Now;
                        item.UpdatedAt = DateTime.Now;
                        item.CreatedBy = currentUser.UserID;
                        item.UpdatedBy = currentUser.UserID;
                        db.Insert<Company>(item);

                        return Json(new { success = true, CompanyID = item.CompanyID, CreatedBy = item.CreatedBy, CreatedAt = item.CreatedAt, });
                    }
                    else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
                    {
                        item.CompanyName = !string.IsNullOrEmpty(item.CompanyName) ? item.CompanyName : "";
                        item.ShortName = !string.IsNullOrEmpty(item.ShortName) ? item.ShortName : "";
                        item.EnglishName = !string.IsNullOrEmpty(item.EnglishName) ? item.EnglishName : "";
                        item.SubDomain = !string.IsNullOrEmpty(item.SubDomain) ? item.SubDomain : "";
                        item.Phone = !string.IsNullOrEmpty(item.Phone) ? item.Phone : "";
                        item.MobilePhone = !string.IsNullOrEmpty(item.MobilePhone) ? item.MobilePhone : "";
                        item.Fax = !string.IsNullOrEmpty(item.Fax) ? item.Fax : "";
                        item.Email = !string.IsNullOrEmpty(item.Email) ? item.Email : "";
                        item.PersonalEmail = !string.IsNullOrEmpty(item.PersonalEmail) ? item.PersonalEmail : "";
                        item.Address = !string.IsNullOrEmpty(item.Address) ? item.Address : "";
                        item.Website = !string.IsNullOrEmpty(item.Website) ? item.Website : "";
                        item.Descr = !string.IsNullOrEmpty(item.Descr) ? item.Descr : "";
                        item.CreatedBy = isExist.CreatedBy;
                        item.CreatedAt = isExist.CreatedAt;
                        item.UpdatedAt = DateTime.Now;
                        item.UpdatedBy = currentUser.UserID;
                        db.Update(item);

                        return Json(new { success = true });
                    }
                    else
                        return Json(new { success = false, message = "Bạn không có quyền" });
                }
                else
                {
                    return Json(new { success = false, message = "Chưa nhập đủ giá trị" });
                }
            }
            catch (Exception e)
            {
                log.Error("Company - Create - " + e.Message);
                return Json(new { success = false, message = e.Message });
            }
            finally { db.Close(); }
        }
Ejemplo n.º 21
0
        public ActionResult ImportWH()
        {
            IDbConnection dbConn = new OrmliteConnection().openConn();
            try
            {
                if (Request.Files["FileUpload"] != null && Request.Files["FileUpload"].ContentLength > 0)
                {
                    string fileExtension =
                        System.IO.Path.GetExtension(Request.Files["FileUpload"].FileName);

                    if (fileExtension == ".xlsx" || fileExtension == ".xls")
                    {

                        string datetime = DateTime.Now.ToString("yyyyMMddHHmmss");
                        string fileLocation = string.Format("{0}/{1}", Server.MapPath("~/ExcelImport"), "[" + currentUser.UserID + "-" + datetime + Request.Files["FileUpload"].FileName);
                        string errorFileLocation = string.Format("{0}/{1}", Server.MapPath("~/ExcelImport"), "[" + currentUser.UserID + "-" + datetime + "-Error]" + Request.Files["FileUpload"].FileName);
                        string linkerror = "[" + currentUser.UserID + "-" + datetime + "-Error]" + Request.Files["FileUpload"].FileName;

                        if (System.IO.File.Exists(fileLocation))
                            System.IO.File.Delete(fileLocation);

                        Request.Files["FileUpload"].SaveAs(fileLocation);

                        var rownumber = 2;
                        var total = 0;
                        FileInfo fileInfo = new FileInfo(fileLocation);
                        var excelPkg = new ExcelPackage(fileInfo);
                        //FileInfo template = new FileInfo(Server.MapPath(errorFileLocation));
                        //template.CopyTo(errorFileLocation);
                        //FileInfo _fileInfo = new FileInfo(errorFileLocation);
                        //var _excelPkg = new ExcelPackage(_fileInfo);
                        ExcelWorksheet oSheet = excelPkg.Workbook.Worksheets["Data"];
                        //ExcelWorksheet eSheet = _excelPkg.Workbook.Worksheets["Data"];
                        ExcelPackage pck = new ExcelPackage(new FileInfo(errorFileLocation));
                        ExcelWorksheet ws = pck.Workbook.Worksheets["Data"];
                        int totalRows = oSheet.Dimension.End.Row;
                        for (int i = 2; i <= totalRows; i++)
                        {
                            string ID = oSheet.Cells[i, 1].Value != null ? oSheet.Cells[i, 1].Value.ToString() : "";
                            string Name = oSheet.Cells[i, 2].Value != null ? oSheet.Cells[i, 2].Value.ToString() : "";
                            string Address = oSheet.Cells[i, 3].Value != null ? oSheet.Cells[i, 3].Value.ToString() : "";
                            string Keeper = oSheet.Cells[i, 4].Value != null ? oSheet.Cells[i, 4].Value.ToString() : "";
                            string Note = oSheet.Cells[i, 5].Value != null ? oSheet.Cells[i, 5].Value.ToString() : "";
                            string Status = "false";
                            if (oSheet.Cells[i, 6].Value != null)
                            {
                                if (oSheet.Cells[i, 6].Value.ToString() == "Đang hoạt động")
                                {
                                    Status = "true";
                                }
                            }

                            try
                            {
                                if (string.IsNullOrEmpty(Name))
                                {
                                    ws.Cells["A" + 2].Value = Name;
                                    ws.Cells[rownumber, 14].Value = "Vui lòng nhập (*).";
                                    rownumber++;
                                }
                                else
                                {
                                    var checkexists = dbConn.SingleOrDefault<WareHouse>("SELECT * FROM DC_AD_WH WHERE WHID = '" + ID + "'");
                                    if (checkexists != null)
                                    {
                                        checkexists.WHID = ID;
                                        checkexists.WHName = Name;
                                        checkexists.Note = Note;
                                        checkexists.Address = !string.IsNullOrEmpty(Address) ? Address : "";
                                        checkexists.WHKeeper = Keeper;
                                        checkexists.Status = Boolean.Parse(Status);
                                        checkexists.UpdatedAt = DateTime.Now;
                                        checkexists.UpdatedBy = currentUser.UserID;
                                        dbConn.Update<WareHouse>(checkexists);
                                    }
                                    else
                                    {
                                        string id = "";
                                        var checkID = dbConn.SingleOrDefault<WareHouse>("SELECT WHID, Id FROM dbo.DC_AD_WH ORDER BY Id DESC");
                                        if (checkID != null)
                                        {
                                            var nextNo = int.Parse(checkID.WHID.Substring(2, checkID.WHID.Length - 2)) + 1;
                                            id = "WH" + String.Format("{0:00000000}", nextNo);
                                        }
                                        else
                                        {
                                            id = "WH00000001";
                                        }
                                        var item = new WareHouse();
                                        item.WHID = id;
                                        item.WHName = !string.IsNullOrEmpty(Name) ? Name.Trim() : "";
                                        item.Note = !string.IsNullOrEmpty(Note) ? Note.Trim() : "";
                                        item.Address = !string.IsNullOrEmpty(Address) ? Address : "";
                                        item.WHKeeper = Keeper;
                                        item.CreatedAt = DateTime.Now;
                                        item.CreatedBy = currentUser.UserID;
                                        item.UpdatedAt = DateTime.Parse("1900-01-01");
                                        item.UpdatedBy = "";
                                        item.Status = Boolean.Parse(Status);
                                        dbConn.Insert<WareHouse>(item);
                                    }
                                    total++;
                                }
                            }
                            catch (Exception e)
                            {
                                return Json(new { success = false, message = e.Message });
                            }
                        }
                        return Json(new { success = true, total = total, totalError = rownumber - 2, link = linkerror });
                    }

                    else
                    {
                        return Json(new { success = false, message = "Không phải là file Excel. *.xlsx" });
                    }
                }
                else
                {
                    return Json(new { success = false, message = "Không có file hoặc file không phải là Excel" });
                }
            }
            catch (Exception ex)
            {
                return Json(new { success = false, message = ex.Message });
            }
        }
Ejemplo n.º 22
0
 public ActionResult UpdateAction([DataSourceRequest]DataSourceRequest request, int roleid, string menuid, [Bind(Prefix = "models")]IEnumerable<Auth_Action> lst)
 {
     if (userAsset.ContainsKey("Update") && userAsset["Update"])
     {
         IDbConnection db = new OrmliteConnection().openConn();
         foreach (var item in lst)
         {
             if (item != null)
             {
                 if (string.IsNullOrEmpty(item.Action))
                 {
                     ModelState.AddModelError("er", "Xin nhập quyền");
                     return Json(lst.ToDataSourceResult(request, ModelState));
                 }
                 var isExist = db.SingleOrDefault<Auth_Action>("RoleID = {0} AND MenuID = {1} AND Action = {2}", roleid, menuid, item.Action);
                 if (isExist != null)
                 {
                     try
                     {
                         item.RoleID = roleid;
                         item.MenuID = menuid;
                         item.Note = "";
                         item.RowCreatedAt = isExist.RowCreatedAt;
                         item.RowCreatedBy = isExist.RowCreatedBy;
                         item.RowUpdatedAt = DateTime.Now;
                         item.RowUpdatedBy = currentUser.UserID;
                         db.Update<Auth_Action>(item, p => p.RoleID == roleid && p.MenuID == menuid && p.Action == item.Action);
                     }
                     catch (Exception ex)
                     {
                         ModelState.AddModelError("er", ex.Message);
                         return Json(lst.ToDataSourceResult(request, ModelState));
                     }
                 }
                 else
                 {
                     ModelState.AddModelError("er", "Quyền không tồn tại");
                     return Json(lst.ToDataSourceResult(request, ModelState));
                 }
             }
         }
         db.Close();
         return Json(lst.ToDataSourceResult(request));
     }
     else
     {
         ModelState.AddModelError("er", "Bạn không có quyền cập nhật");
         return Json(lst.ToDataSourceResult(request, ModelState));
     }
 }
Ejemplo n.º 23
0
        //public FileResult Export([DataSourceRequest]DataSourceRequest request)
        //{
        //    ExcelPackage pck = new ExcelPackage(new FileInfo(Server.MapPath("~/ExportTemplate/DanhMucAnPham.xlsx")));
        //    ExcelWorksheet ws = pck.Workbook.Worksheets["Data"];
        //    if (userAsset["Export"])
        //    {
        //        string whereCondition = "";
        //        if (request.Filters.Count > 0)
        //        {
        //            whereCondition = new KendoApplyFilter().ApplyFilter(request.Filters[0]);
        //        }
        //        IDbConnection db = new OrmliteConnection().openConn();
        //        var lstResult = db.Select<Products>(whereCondition).ToList();
        //        int rowNum = 2;
        //        foreach (var item in lstResult)
        //        {
        //            ws.Cells["A" + rowNum].Value = item.Code;
        //            ws.Cells["B" + rowNum].Value = item.Name;
        //            ws.Cells["C" + rowNum].Value = item.Size;
        //            ws.Cells["D" + rowNum].Value = item.VATPrice;
        //            ws.Cells["E" + rowNum].Value = item.Type;
        //            ws.Cells["F" + rowNum].Value = item.Unit;
        //            ws.Cells["G" + rowNum].Value = item.WHID;
        //            ws.Cells["H" + rowNum].Value = item.WHLID;
        //            ws.Cells["I" + rowNum].Value = item.ShapeTemplate;
        //            if (item.Status == true)
        //            {
        //                ws.Cells["J" + rowNum].Value = "Đang hoạt động";
        //            }
        //            else
        //            {
        //                ws.Cells["J" + rowNum].Value = "Ngưng hoạt động";
        //            }
        //            ws.Cells["K" + rowNum].Value = item.CreatedBy;
        //            ws.Cells["L" + rowNum].Value = item.CreatedAt;
        //            ws.Cells["M" + rowNum].Value = item.UpdatedBy;
        //            if (item.UpdatedAt != DateTime.Parse("1900-01-01"))
        //            {
        //                ws.Cells["N" + rowNum].Value = item.UpdatedAt;
        //            }
        //            else
        //            {
        //                ws.Cells["N" + rowNum].Value = "";
        //            }
        //            rowNum++;
        //        }
        //        db.Close();
        //    }
        //    else
        //    {
        //        ws.Cells["A2:E2"].Merge = true;
        //        ws.Cells["A2"].Value = "Bạn không có quyền";
        //    }
        //    MemoryStream output = new MemoryStream();
        //    pck.SaveAs(output);
        //    return File(output.ToArray(), //The binary data of the XLS file
        //                "application/vnd.ms-excel", //MIME type of Excel files
        //                "DanhMucAnPham_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".xlsx");     //Suggested file name in the "Save as" dialog which will be displayed to the end user
        //}
        public ActionResult ImportData()
        {
            try
            {
                if (Request.Files["FileUpload"] != null && Request.Files["FileUpload"].ContentLength > 0)
                {
                    string fileExtension =
                        System.IO.Path.GetExtension(Request.Files["FileUpload"].FileName);

                    if (fileExtension == ".xlsx" || fileExtension == ".xls")
                    {
                        IDbConnection dbConn = new OrmliteConnection().openConn();
                        using (var dbTrans = dbConn.OpenTransaction(IsolationLevel.ReadCommitted))
                        {
                            string datetime = DateTime.Now.ToString("yyyyMMddHHmmss");
                            string fileLocation = string.Format("{0}/{1}", Server.MapPath("~/ExcelImport"), "[" + currentUser.UserID + "-" + datetime + Request.Files["FileUpload"].FileName);
                            string errorFileLocation = string.Format("{0}/{1}", Server.MapPath("~/ExcelImport"), "[" + currentUser.UserID + "-" + datetime + "-Error]" + Request.Files["FileUpload"].FileName);
                            string linkerror = "[" + currentUser.UserID + "-" + datetime + "-Error]" + Request.Files["FileUpload"].FileName;

                            if (System.IO.File.Exists(fileLocation))
                                System.IO.File.Delete(fileLocation);

                            Request.Files["FileUpload"].SaveAs(fileLocation);

                            var rownumber = 2;
                            var total = 0;
                            FileInfo fileInfo = new FileInfo(fileLocation);
                            var excelPkg = new ExcelPackage(fileInfo);
                            //FileInfo template = new FileInfo(Server.MapPath(errorFileLocation));
                            //template.CopyTo(errorFileLocation);
                            //FileInfo _fileInfo = new FileInfo(errorFileLocation);
                            //var _excelPkg = new ExcelPackage(_fileInfo);
                            ExcelWorksheet oSheet = excelPkg.Workbook.Worksheets["Data"];
                            //ExcelWorksheet eSheet = _excelPkg.Workbook.Worksheets["Data"];
                            ExcelPackage pck = new ExcelPackage(new FileInfo(errorFileLocation));
                            ExcelWorksheet ws = pck.Workbook.Worksheets["Data"];
                            int totalRows = oSheet.Dimension.End.Row;
                            for (int i = 2; i <= totalRows; i++)
                            {
                                string ID = oSheet.Cells[i, 1].Value != null ? oSheet.Cells[i, 1].Value.ToString() : "";
                                string Name = oSheet.Cells[i, 2].Value != null ? oSheet.Cells[i, 2].Value.ToString() : "";
                                string Size = oSheet.Cells[i, 3].Value != null ? oSheet.Cells[i, 3].Value.ToString() : "";
                                string Priece = oSheet.Cells[i, 4].Value != null ? oSheet.Cells[i, 4].Value.ToString() : "0";
                                string Type = oSheet.Cells[i, 5].Value != null ? oSheet.Cells[i, 5].Value.ToString() : "";
                                string Unit = oSheet.Cells[i, 6].Value != null ? oSheet.Cells[i, 6].Value.ToString() : "";
                                string[] UnitID = Unit.Split('/');
                                string WH = oSheet.Cells[i, 7].Value != null ? oSheet.Cells[i, 7].Value.ToString() : "";
                                string[] WHID = WH.Split('/');
                                string WHL = oSheet.Cells[i, 8].Value != null ? oSheet.Cells[i, 8].Value.ToString() : "";
                                string[] WHLID = WHL.Split('/');
                                string Templete = oSheet.Cells[i, 9].Value != null ? oSheet.Cells[i, 9].Value.ToString() : "";
                                //string Status = oSheet.Cells[i, 9].Value != null ? oSheet.Cells[i, 9].Value.ToString() : "Ngưng hoạt động";
                                string Status = "false";
                                if (oSheet.Cells[i, 10].Value != null)
                                {
                                    if (oSheet.Cells[i, 10].Value.ToString() == "Đang hoạt động")
                                    {
                                        Status = "true";
                                    }
                                }
                                try
                                {
                                    if (string.IsNullOrEmpty(Name) || string.IsNullOrEmpty(Size) || string.IsNullOrEmpty(Priece))
                                    {
                                        ws.Cells["A" + 2].Value = Name;
                                        ws.Cells[rownumber, 14].Value = "Vui lòng nhập (*).";
                                        rownumber++;
                                    }
                                    else
                                    {
                                        var checkexists = dbConn.SingleOrDefault<Products>("SELECT * FROM Products WHERE Code = '" + ID + "'");
                                        if (checkexists != null)
                                        {
                                            checkexists.Code = ID;
                                            checkexists.Name = Name;
                                            checkexists.Size = Name;
                                            checkexists.Price = int.Parse(Priece)/1.1;
                                            checkexists.VATPrice = int.Parse(Priece);
                                            checkexists.Type = Type;
                                            checkexists.Unit = Unit != null ? UnitID[UnitID.Count() - 1] : "";
                                            checkexists.WHID = WH != null ? WHID[WHID.Count() - 1] : "";
                                            checkexists.WHLID = WHL != null ? WHLID[WHLID.Count() - 1] : "";
                                            checkexists.ShapeTemplate = Templete;
                                            checkexists.Status = Boolean.Parse(Status);
                                            checkexists.UpdatedAt = DateTime.Now;
                                            checkexists.UpdatedBy = currentUser.UserID;
                                            dbConn.Update<Products>(checkexists);
                                        }
                                        else
                                        {
                                            string id = "";
                                            var checkID = dbConn.SingleOrDefault<Products>("SELECT Code, Id FROM dbo.Products ORDER BY Id DESC");
                                            if (checkID != null)
                                            {
                                                var nextNo = int.Parse(checkID.Code.Substring(2, checkID.Code.Length - 2)) + 1;
                                                id = "AD" + String.Format("{0:00000000}", nextNo);
                                            }
                                            else
                                            {
                                                id = "AD00000001";
                                            }
                                            var item = new Products();
                                            item.Code = ID;
                                            item.Name = Name;
                                            item.Size = Name;
                                            item.Price = int.Parse(Priece) / 1.1;
                                            item.VATPrice = int.Parse(Priece);
                                            item.Type = Type;
                                            item.Unit = Unit != null ? UnitID[UnitID.Count() - 1] : "";
                                            item.WHID = WH != null ? WHID[WHID.Count() - 1] : "";
                                            item.WHLID = WHL != null ? WHLID[WHLID.Count() - 1] : "";
                                            item.ShapeTemplate = Templete;
                                            item.Status = Boolean.Parse(Status);
                                            item.CreatedAt = DateTime.Now;
                                            item.CreatedBy = currentUser.UserID;
                                            item.UpdatedAt = DateTime.Parse("1900-01-01");
                                            item.UpdatedBy = "";
                                            item.Status = Boolean.Parse(Status);
                                            dbConn.Insert<Products>(item);
                                        }
                                        total++;
                                    }
                                }
                                catch (Exception e)
                                {
                                    return Json(new { success = false, message = e.Message });
                                }
                            }
                            return Json(new { success = true, total = total, totalError = rownumber - 2, link = linkerror });
                        }
                    }
                    else
                    {
                        return Json(new { success = false, message = "Không phải là file Excel. *.xlsx" });
                    }
                }
                else
                {
                    return Json(new { success = false, message = "Không có file hoặc file không phải là Excel" });
                }
            }
            catch (Exception ex)
            {
                return Json(new { success = false, message = ex.Message });
            }
        }
Ejemplo n.º 24
0
        public ActionResult Create(Vendor item)
        {
            IDbConnection db = new OrmliteConnection().openConn();
            try
            {
                if (!string.IsNullOrEmpty(item.VendorName)
                    )
                {
                    DateTime signoff;
                    var signDate = Request["SignOffDate"];
                    if (DateTime.TryParseExact(signDate, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out signoff
                        ))
                    { }
                    else
                    {
                        return Json(new { success = false, message = "Định dạng ngày ký không đúng" });
                    }

                    var isExist = db.SingleOrDefault<Vendor>("VendorID={0}", item.VendorID);
                    item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note : "";
                    item.FullName = !string.IsNullOrEmpty(item.FullName) ? item.FullName : "";
                    item.Phone = !string.IsNullOrEmpty(item.Phone) ? item.Phone : "";
                    item.Email = !string.IsNullOrEmpty(item.Email) ? item.Email : "";
                    item.SignOffDate = signoff;
                    item.Address = !string.IsNullOrEmpty(item.Address) ? item.Address : "";
                    item.TaxCode = !string.IsNullOrEmpty(item.TaxCode) ? item.TaxCode : "";
                    item.Website = !string.IsNullOrEmpty(item.Website) ? item.Website : "";
                    item.Hotline = !string.IsNullOrEmpty(item.Hotline) ? item.Hotline : "";
                    item.Url = "";
                    item.Fax = !string.IsNullOrEmpty(item.Fax) ? item.Fax : "";
                    if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
                    {
                        if (isExist != null)
                            return Json(new { success = false, message = "Mã NCC đã tồn tại!" });
                        string id = "";
                        var checkID = db.SingleOrDefault<Vendor>("SELECT VendorID, Id FROM dbo.Vendor ORDER BY Id DESC");
                        if (checkID != null)
                        {
                            var nextNo = int.Parse(checkID.VendorID.Substring(2, checkID.VendorID.Length - 2)) + 1;
                            id = "VD" + String.Format("{0:00000000}", nextNo);
                        }
                        else
                        {
                            id = "VD00000001";
                        }
                        item.VendorID = id;
                        item.VendorName = !string.IsNullOrEmpty(item.VendorName) ? item.VendorName : "";
                        item.CreatedAt = DateTime.Now;
                        item.UpdatedAt = DateTime.Parse("1900-01-01");
                        item.CreatedBy = currentUser.UserID;
                        item.UpdatedBy = "";
                        db.Insert(item);
                        return Json(new { success = true, VendorID = item.VendorID, CreatedBy = item.CreatedBy, CreatedAt = item.CreatedAt });
                    }
                    else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
                    {
                        item.VendorName = !string.IsNullOrEmpty(item.VendorName) ? item.VendorName : "";
                        item.CreatedAt = isExist.CreatedAt;
                        item.UpdatedAt = DateTime.Now;
                        item.UpdatedBy = currentUser.UserID;
                        db.Update(item);
                        return Json(new { success = true });
                    }
                    else
                        return Json(new { success = false, message = "Bạn không có quyền" });
                }
                else
                {
                    return Json(new { success = false, message = "Chưa nhập đủ giá trị" });
                }
            }
            catch (Exception e)
            {
                log.Error("Vendor - Create - " + e.Message);
                return Json(new { success = false, message = e.Message });
            }
            finally { db.Close(); }
        }