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(); } }
// // 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(); } }
public ActionResult GetDiscountionCode(string DiscountionID) { IDbConnection dbConn = new OrmliteConnection().openConn(); try { var data = dbConn.SingleOrDefault<DC_LG_Discountion>("DiscountionID={0}", DiscountionID); return Json(new { success = true, data = data }); } catch (Exception e) { return Json(new { success = false, message = e.Message }); } finally { dbConn.Close(); } }
protected override void Initialize(System.Web.Routing.RequestContext requestContext) { base.Initialize(requestContext); if (this.User.Identity.IsAuthenticated) { IDbConnection dbConn = new OrmliteConnection().openConn(); lstAssetDefault = InitAssetDefault(); currentUser = dbConn.GetByIdOrDefault<Auth_User>(User.Identity.Name); currentUserRole = dbConn.SqlList<Auth_Role>("EXEC p_Auth_UserInRole_Select_By_UserID @UserID", new { UserID = User.Identity.Name }); string controllerName = this.GetType().Name; controllerName = controllerName.Substring(0, controllerName.IndexOf("Controller")); var lstAsset = new List<Auth_Action>(); // Get MenuID from controller name string menuID = dbConn.SingleOrDefault<Auth_Menu>("ControllerName = {0}", controllerName).MenuID; foreach (var g in currentUserRole) { // Get List Asset var temp = dbConn.Select<Auth_Action>(p => p.RoleID == g.RoleID && p.MenuID == menuID); if (temp.Count > 0) lstAsset.AddRange(temp); } if(lstAsset.Count == 0) { var item = new Auth_Action(); item.MenuID = menuID; item.Note = ""; item.RowCreatedAt = DateTime.Now; item.RowCreatedBy = "System"; if (currentUser.UserID == ConfigurationManager.AppSettings["superadmin"]) { item.RoleID = 1; item.IsAllowed = true; foreach(var asset in lstAssetDefault) { item.Action = asset; dbConn.Insert<Auth_Action>(item); } } else { item.RoleID = currentUserRole.FirstOrDefault().RoleID; item.IsAllowed = false; foreach (var asset in lstAssetDefault) { item.Action = asset; dbConn.Insert<Auth_Action>(item); } } } else { foreach (var g in currentUserRole) { // Asset var lst = lstAsset.Where(p => p.RoleID == g.RoleID).ToList(); foreach(var item in lst) { if (!userAsset.ContainsKey(item.Action)) userAsset.Add(item.Action, item.IsAllowed); else if(item.IsAllowed) { userAsset.Remove(item.Action); userAsset.Add(item.Action, item.IsAllowed); } } } } // Get Asset View Menu foreach (var g in currentUserRole) { var lstView = dbConn.Select<Auth_Action>(p => p.RoleID == g.RoleID && p.Action == "View"); //var lstView = new Auth_Menu().GetMenuByRoleID(g.RoleID); foreach (var i in lstView) { if (!dictView.ContainsKey("menu_" + i.MenuID)) { if(i.IsAllowed) { dictView.Add("menu_" + i.MenuID, true); } } } } ViewData["menuView"] = dictView; dbConn.Close(); } }
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)); } }
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(); } }
public ActionResult GetDeliveryByCode(string TransporterID) { IDbConnection dbConn = new OrmliteConnection().openConn(); try { var data = dbConn.SingleOrDefault<DC_LG_Transporter>("TransporterID={0}", TransporterID); return Json(new { success = true, data = data }); } catch (Exception e) { return Json(new { success = false, message = e.Message }); } finally { dbConn.Close(); } }
//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 }); } }
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(); } }
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 }); } }
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(); } }
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(); } }
public ActionResult GetPrinterbycode(string PrinterID) { IDbConnection dbConn = new OrmliteConnection().openConn(); try { var data = dbConn.SingleOrDefault<DC_AD_Printer>("PrinterID={0}", PrinterID); return Json(new { success = true, data = data }); } catch (Exception e) { return Json(new { success = false, message = e.Message }); } finally { dbConn.Close(); } }
protected override void Initialize(System.Web.Routing.RequestContext requestContext) { base.Initialize(requestContext); if (this.User.Identity.IsAuthenticated) { IDbConnection dbConn = new OrmliteConnection().openConn(); lstAssetDefault = InitAssetDefault(); currentUser = dbConn.GetByIdOrDefault <Auth_User>(User.Identity.Name); currentUserRole = dbConn.SqlList <Auth_Role>("EXEC p_Auth_UserInRole_Select_By_UserID @UserID", new { UserID = User.Identity.Name }); string controllerName = this.GetType().Name; controllerName = controllerName.Substring(0, controllerName.IndexOf("Controller")); var lstAsset = new List <Auth_Action>(); // Get MenuID from controller name string menuID = dbConn.SingleOrDefault <Auth_Menu>("ControllerName = {0}", controllerName).MenuID; foreach (var g in currentUserRole) { // Get List Asset var temp = dbConn.Select <Auth_Action>(p => p.RoleID == g.RoleID && p.MenuID == menuID); if (temp.Count > 0) { lstAsset.AddRange(temp); } } if (lstAsset.Count == 0) { var item = new Auth_Action(); item.MenuID = menuID; item.Note = ""; item.RowCreatedAt = DateTime.Now; item.RowCreatedBy = "System"; if (currentUser.UserID == ConfigurationManager.AppSettings["superadmin"]) { item.RoleID = 1; item.IsAllowed = true; foreach (var asset in lstAssetDefault) { item.Action = asset; dbConn.Insert <Auth_Action>(item); } } else { item.RoleID = currentUserRole.FirstOrDefault().RoleID; item.IsAllowed = false; foreach (var asset in lstAssetDefault) { item.Action = asset; dbConn.Insert <Auth_Action>(item); } } } else { foreach (var g in currentUserRole) { // Asset var lst = lstAsset.Where(p => p.RoleID == g.RoleID).ToList(); foreach (var item in lst) { if (!userAsset.ContainsKey(item.Action)) { userAsset.Add(item.Action, item.IsAllowed); } else if (item.IsAllowed) { userAsset.Remove(item.Action); userAsset.Add(item.Action, item.IsAllowed); } } } } // Get Asset View Menu foreach (var g in currentUserRole) { var lstView = dbConn.Select <Auth_Action>(p => p.RoleID == g.RoleID && p.Action == "View"); //var lstView = new Auth_Menu().GetMenuByRoleID(g.RoleID); foreach (var i in lstView) { if (!dictView.ContainsKey("menu_" + i.MenuID)) { if (i.IsAllowed) { dictView.Add("menu_" + i.MenuID, true); } } } } ViewData["menuView"] = dictView; dbConn.Close(); } }
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(); } }
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 }); }
public ActionResult CreateHeader(SOHeader item) { var dbConn = new OrmliteConnection().openConn(); if (userAsset.ContainsKey("Insert") && userAsset["Insert"]) { try { string SONumber = Request["SONumber"]; var header = new SOHeader(); var detail = new SODetail(); if (string.IsNullOrEmpty(SONumber)) { string datetimeSO = DateTime.Now.ToString("yyMMdd"); var existSO = dbConn.SingleOrDefault<SOHeader>("SELECT id, SONumber FROM SOHeader ORDER BY Id DESC"); if (existSO != null) { var nextNo = Int32.Parse(existSO.SONumber.Substring(8, 5)) + 1; SONumber = "SO" + datetimeSO + String.Format("{0:00000}", nextNo); } else { SONumber = "SO" + datetimeSO + "00001"; } } if (string.IsNullOrEmpty(Request["VendorID"])) { return Json(new { message = "Nhà cung cấp không tồn tai." }); } if (!string.IsNullOrEmpty(Request["SODate"])) { DateTime fromDateValue; if (!DateTime.TryParseExact(Request["SODate"], "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out fromDateValue)) { return Json(new { message = "Ngày tạo không đúng." }); } } header.SONumber = SONumber; header.SODate = !string.IsNullOrEmpty(Request["SODate"]) ? DateTime.Parse(DateTime.ParseExact(Request["SODate"], "dd/MM/yyyy", CultureInfo.InvariantCulture).ToString("yyyy-MM-dd")) : DateTime.Now; header.VendorID = !string.IsNullOrEmpty(Request["VendorID"]) ? Request["VendorID"] : ""; header.Note = !string.IsNullOrEmpty(Request["Note"]) ? Request["Note"] : ""; header.TotalQty = 0; header.WHID = ""; header.Status = "Mới"; header.WHLID = ""; header.TotalAmt = 0; header.CreatedBy = currentUser.UserID; header.CreatedAt = DateTime.Now; header.UpdatedBy = ""; header.UpdatedAt = DateTime.Now; //header.UpdatedAt = DateTime.Parse("1900-01-01"); dbConn.Insert<SOHeader>(header); dbConn.Close(); return Json(new { success = true, SONumber = SONumber }); } catch (Exception e) { return Json(new { success = false, message = e.Message }); } } else { dbConn.Close(); return Json(new { success = false, message = "Không có quyền tạo." }); } }
public ActionResult GetFormulaByID(string FormulaID) { IDbConnection dbConn = new OrmliteConnection().openConn(); try { var data = dbConn.SingleOrDefault<DC_Formula>("FormulaID={0}", FormulaID); return Json(new { success = true, data = data }); } catch (Exception e) { return Json(new { success = false, message = e.Message }); } finally { dbConn.Close(); } }
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(); } }
public ActionResult CreateUnit(DC_AD_Unit item) { IDbConnection db = new OrmliteConnection().openConn(); try { var isExist = db.SingleOrDefault<DC_AD_Unit>("SELECT UnitID, Id FROM dbo.DC_AD_Unit Where UnitID ='" + item.UnitID + "'"); if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy ==null) { if (isExist != null) { return Json(new { success = false, message = "Đơn vị tính đã tồn tại." }); } string id = ""; var checkID = db.SingleOrDefault<DC_AD_Unit>("SELECT UnitID, Id FROM dbo.DC_AD_Unit ORDER BY Id DESC"); if (checkID != null) { var nextNo = int.Parse(checkID.UnitID.Substring(3, checkID.UnitID.Length - 3)) + 1; id = "UIT" + String.Format("{0:00000000}", nextNo); } else { id = "UIT00000001"; } item.UnitID = id; item.UnitName = !string.IsNullOrEmpty(item.UnitName) ? item.UnitName.Trim() : ""; item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note.Trim() : ""; item.CreatedAt = DateTime.Now; item.CreatedBy = currentUser.UserID; item.UpdatedAt = DateTime.Parse("1900-01-01"); item.UpdatedBy = ""; item.Status = item.Status; db.Insert<DC_AD_Unit>(item); return Json(new { success = true, Code = item.UnitID, createdate = item.CreatedAt, createdby = item.CreatedBy }); } else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null) { var success = db.Execute(@"UPDATE DC_AD_Unit SET Status = @Status, Note = @Note, UpdatedAt = @UpdatedAt, UpdatedBy = @UpdatedBy, UnitName = @UnitName WHERE UnitID = '" + item.UnitID + "'", new { Status = item.Status, //WHName = !string.IsNullOrEmpty(item.WHName) ? item.WHName.Trim() : "", Note = !string.IsNullOrEmpty(item.Note) ? item.Note.Trim() : "", UpdatedAt = DateTime.Now, UpdatedBy = currentUser.UserID, UnitName = !string.IsNullOrEmpty(item.UnitName) ? item.UnitName.Trim() : "", }) == 1; if (!success) { return Json(new { success = false, message = "Cập nhật không thành công." }); } return Json(new { success = true }); } else return Json(new { success = false, message = "Bạn không có quyền" }); } catch (Exception e) { log.Error(" ListPublication - Create - " + e.Message); return Json(new { success = false, message = e.Message }); } finally { db.Close(); } }
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)); } }
public ActionResult CreateWH(WareHouse item) { IDbConnection db = new OrmliteConnection().openConn(); try { var isExist = db.SingleOrDefault<WareHouse>("SELECT WHID, Id FROM dbo.WareHouse Where WHID ='" + item.WHID + "'"); if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null) { if (isExist != null) { return Json(new { success = false, message = "Kho đã tồn tại." }); } string id = ""; var checkID = db.SingleOrDefault<WareHouse>("SELECT WHID, Id FROM dbo.WareHouse 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"; } item.WHID = id; item.WHName = !string.IsNullOrEmpty(item.WHName) ? item.WHName.Trim() : ""; item.Address = !string.IsNullOrEmpty(item.Address) ? item.Address.Trim() : ""; item.WHKeeper = !string.IsNullOrEmpty(item.WHKeeper) ? item.WHKeeper.Trim() : ""; item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note.Trim() : ""; item.CreatedAt = DateTime.Now; item.CreatedBy = currentUser.UserID; item.UpdatedAt = DateTime.Parse("1900-01-01"); item.UpdatedBy = ""; item.Status = item.Status; db.Insert<WareHouse>(item); return Json(new { success = true, Code = item.WHID, createdate = item.CreatedAt, createdby = item.CreatedBy }); } else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null) { var success = db.Execute(@"UPDATE WareHouse SET Status = @Status, Address=@Address,WHKeeper=@WHKeeper, Note = @Note, UpdatedAt = @UpdatedAt, UpdatedBy = @UpdatedBy, WHName=@WHName WHERE WHID = '" + item.WHID + "'", new { Status = item.Status, //WHName = !string.IsNullOrEmpty(item.WHName) ? item.WHName.Trim() : "", Address = !string.IsNullOrEmpty(item.Address) ? item.Address.Trim() : "", WHKeeper = !string.IsNullOrEmpty(item.WHKeeper) ? item.WHKeeper.Trim() : "", Note = !string.IsNullOrEmpty(item.Note) ? item.Note.Trim() : "", UpdatedAt = DateTime.Now, UpdatedBy = currentUser.UserID, WHName = !string.IsNullOrEmpty(item.WHName) ? item.WHName.Trim() : "", }) == 1; if (!success) { return Json(new { success = false, message = "Cập nhật không thành công." }); } return Json(new { success = true }); } else return Json(new { success = false, message = "Bạn không có quyền" }); } catch (Exception e) { log.Error(" WareHouse - Create - " + e.Message); return Json(new { success = false, message = e.Message }); } finally { db.Close(); } }
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." }); } }
public ActionResult CreateSONew() { var dbConn = new OrmliteConnection().openConn(); try { string SONumber = String.Empty; string datetimeSO = DateTime.Now.ToString("yyMMdd"); var existSO = dbConn.SingleOrDefault<SOHeader>("SELECT id, SONumber FROM SOHeader ORDER BY Id DESC"); if (existSO != null) { var nextNo = Int32.Parse(existSO.SONumber.Substring(8, 5)) + 1; SONumber = "SO" + datetimeSO + String.Format("{0:00000}", nextNo); } else { SONumber = "SO" + datetimeSO + "00001"; } return Json(new { success = true, SONumber = SONumber }); } catch (Exception e) { return Json(new { success = false, message = e.Message}); } }
public ActionResult ConfirmCreate() { var dbConn = new OrmliteConnection().openConn(); if (userAsset.ContainsKey("Insert") && userAsset["Insert"]) { try { string SONumber = Request["SONumber"]; var header = new SOHeader(); var detail = new SODetail(); if (string.IsNullOrEmpty(SONumber)) { string datetimeSO = DateTime.Now.ToString("yyMMdd"); var existSO = dbConn.SingleOrDefault<SOHeader>("SELECT id, SONumber FROM SOHeader ORDER BY Id DESC"); if (existSO != null) { var nextNo = Int32.Parse(existSO.SONumber.Substring(8, 5)) + 1; SONumber = "SO" + datetimeSO + String.Format("{0:00000}", nextNo); } else { SONumber = "SO" + datetimeSO + "00001"; } } if (!string.IsNullOrEmpty(Request["SODate"])) { DateTime fromDateValue; if (!DateTime.TryParseExact(Request["SODate"], "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out fromDateValue)) { return Json(new { message = "Ngày tạo không đúng." }); } } if (dbConn.Select<DC_OCM_Merchant>(p => p.MerchantID == Request["MerchantID"]).Count() <= 0) { return Json(new { success = false, message = "Nhà cung cấp không tồn tại." }); } if (dbConn.Select<SODetail>(p => p.SONumber == SONumber).Count() > 0) { if (!string.IsNullOrEmpty(Request["ItemCode"])) { if (dbConn.Select<Products>(p => p.Code == Request["ItemCode"]).Count() <= 0) { return Json(new { success = false, message = "Ấn phẩm không tồn tại." }); } var itemcode = dbConn.Select<Products>(s => s.Code == Request["ItemCode"]).FirstOrDefault(); var itemunit = dbConn.Select<Products>(s => s.UnitID == itemcode.Unit).FirstOrDefault(); if (dbConn.Select<SODetail>(p => p.ItemCode == Request["ItemCode"] && p.SONumber == SONumber).Count() > 0) { var success = dbConn.Execute(@"UPDATE SODetail Set Qty = @Qty, TotalAmt =@TotalAmt ,UpdatedAt = @UpdatedAt, UpdatedBy = @UpdatedBy, Price = @Price WHERE SONumber = '" + SONumber + "' AND ItemCode = '" + Request["ItemCode"] + "'", new { Qty = dbConn.Select<SODetail>(s => s.ItemCode == Request["ItemCode"] && s.SONumber == SONumber).Sum(s => s.Qty) + int.Parse(Request["Qty"]), TotalAmt = itemcode != null ? itemcode.VATPrice * (dbConn.Select<SODetail>(s => s.ItemCode == Request["ItemCode"] && s.SONumber == SONumber).Sum(s => s.Qty) + int.Parse(Request["Qty"])) : 0, Price = itemcode.VATPrice, UpdatedBy = currentUser.UserID, UpdatedAt = DateTime.Now, }) == 1; if (!success) { return Json(new { success = false, message = "Không thể lưu" }); } } else { detail.SONumber = SONumber; detail.ItemCode = !string.IsNullOrEmpty(Request["ItemCode"]) ? Request["ItemCode"] : ""; detail.ItemName = !string.IsNullOrEmpty(itemcode.Name) ? itemcode.Name : ""; detail.Price = itemcode != null ? itemcode.VATPrice : 0; detail.Qty = int.Parse(Request["Qty"]); detail.TotalAmt = itemcode.VATPrice * int.Parse(Request["Qty"]); detail.UnitID = !string.IsNullOrEmpty(itemunit.UnitID) ? itemunit.UnitID : ""; detail.UnitName = !string.IsNullOrEmpty(itemunit.UnitName) ? itemunit.UnitName : ""; detail.Note = ""; detail.Status = ""; detail.CreatedBy = currentUser.UserID; detail.CreatedAt = DateTime.Now; detail.UpdatedBy = ""; detail.UpdatedAt = DateTime.Parse("1900-01-01"); dbConn.Insert<SODetail>(detail); } } } else { if (string.IsNullOrEmpty(Request["ItemCode"]) || dbConn.Select<Products>(p => p.Code == Request["ItemCode"]).Count() <= 0) { return Json(new { success = false, message = "Ấn phẩm không tồn tại." }); } var itemcode = dbConn.Select<Products>(s => s.Code == Request["ItemCode"]).FirstOrDefault(); var itemunit = dbConn.Select<Products>(s => s.UnitID == itemcode.Unit).FirstOrDefault(); detail.SONumber = SONumber; detail.ItemCode = !string.IsNullOrEmpty(Request["ItemCode"]) ? Request["ItemCode"] : ""; detail.ItemName = !string.IsNullOrEmpty(itemcode.Name) ? itemcode.Name : ""; detail.Price = itemcode != null ? itemcode.VATPrice :0 ; detail.Qty = int.Parse(Request["Qty"]); detail.TotalAmt = itemcode.VATPrice * int.Parse(Request["Qty"]); detail.UnitID = !string.IsNullOrEmpty(itemunit.UnitID) ? itemunit.UnitID : ""; detail.UnitName = !string.IsNullOrEmpty(itemunit.UnitName) ? itemunit.UnitName : ""; detail.Note = ""; detail.Status = ""; detail.CreatedBy = currentUser.UserID; detail.CreatedAt = DateTime.Now; detail.UpdatedBy = ""; detail.UpdatedAt = DateTime.Parse("1900-01-01"); dbConn.Insert<SODetail>(detail); } if (dbConn.Select<SOHeader>(p => p.SONumber == SONumber).Count() > 0) { var success = dbConn.Execute(@"UPDATE SOHeader Set TotalQty = @TotalQty, TotalAmt =@TotalAmt ,UpdatedAt = @UpdatedAt, UpdatedBy = @UpdatedBy, MerchantID = @MerchantID, SODate = @SODate , WHLID =@WHLID, WHID =@WHID WHERE SONumber = '" + SONumber + "'", new { TotalQty = dbConn.Select<SODetail>(s =>s.SONumber == SONumber).Sum(s => s.Qty), TotalAmt = dbConn.Select<SODetail>(s => s.SONumber == SONumber).Sum(s => s.TotalAmt), SODate = !string.IsNullOrEmpty(Request["SODate"]) ? DateTime.Parse(DateTime.ParseExact(Request["SODate"], "dd/MM/yyyy", CultureInfo.InvariantCulture).ToString("yyyy-MM-dd")) : DateTime.Now, WHID = !string.IsNullOrEmpty(Request["WHID"]) ? Request["WHID"] : "", WHLID = !string.IsNullOrEmpty(Request["WHLID"]) ? Request["WHLID"] : "", MerchantID = !string.IsNullOrEmpty(Request["MerchantID"]) ? Request["MerchantID"] : "", UpdatedBy = currentUser.UserID, UpdatedAt = DateTime.Now, }) == 1; if (!success) { return Json(new { success = false, message = "Không thể lưu" }); } } else { header.SONumber = SONumber; header.SODate = !string.IsNullOrEmpty(Request["SODate"]) ? DateTime.Parse(DateTime.ParseExact(Request["SODate"], "dd/MM/yyyy", CultureInfo.InvariantCulture).ToString("yyyy-MM-dd")) : DateTime.Now; header.VendorID = !string.IsNullOrEmpty(Request["MerchantID"]) ? Request["MerchantID"] : ""; header.Note = !string.IsNullOrEmpty(Request["Note"]) ? Request["Note"] : ""; header.TotalQty = dbConn.Select<SODetail>(s =>s.SONumber == SONumber).Sum(s => s.Qty); header.WHID = Request["WHID"]; header.Status = "Mới"; header.WHLID = !string.IsNullOrEmpty(Request["WHLID"]) ? Request["WHLID"] : ""; header.TotalAmt = dbConn.Select<SODetail>(s => s.SONumber == SONumber).Sum(s => s.TotalAmt); header.CreatedBy = currentUser.UserID; header.CreatedAt = DateTime.Now; header.UpdatedBy = ""; header.UpdatedAt = DateTime.Parse("1900-01-01"); dbConn.Insert<SOHeader>(header); } return Json(new { success = true, SONumber = SONumber }); } catch (Exception e) { return Json(new { success = false, message = e.Message }); } } else { return Json(new { success = false, message = "Không có quyền tạo." }); } }
public ActionResult Create(Products item) { IDbConnection db = new OrmliteConnection().openConn(); try { var isExist = db.SingleOrDefault<Products>("SELECT Code, Id FROM dbo.Products Where Code ='"+item.Code+"'"); if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null) { if (isExist != null) { return Json(new { success = false, message = "Ấn phẩm đã tồn tại." }); } string id = ""; var checkID = db.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"; } item.Code = id; item.Name = !string.IsNullOrEmpty(item.Name) ? item.Name.Trim() : ""; item.Price = item.VATPrice / 1.1; item.VATPrice = item.VATPrice; item.Size = !string.IsNullOrEmpty(item.Size) ? item.Size.Trim() : ""; ; item.Unit = !string.IsNullOrEmpty(item.Unit) ? item.Unit.Trim() : ""; ; item.Type = !string.IsNullOrEmpty(item.Type) ? item.Type.Trim() : ""; ; item.WHID = !string.IsNullOrEmpty(item.WHID) ? item.WHID : ""; item.WHLID = !string.IsNullOrEmpty(item.WHLID) ? item.WHLID : ""; item.Desc = !string.IsNullOrEmpty(item.Desc) ? item.Desc.Trim() : ""; item.ShapeTemplate = !string.IsNullOrEmpty(item.ShapeTemplate) ? item.ShapeTemplate.Trim() : ""; item.CreatedAt = DateTime.Now; item.CreatedBy = currentUser.UserID; item.UpdatedAt = DateTime.Parse("1900-01-01"); item.UpdatedBy = ""; item.Status = item.Status; db.Insert<Products>(item); return Json(new { success = true, Code = item.Code, createdat = item.CreatedAt, createdby = item.CreatedBy }); } else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null) { var success = db.Execute(@"UPDATE Products SET Status = @Status, VATPrice = @VATPrice, Size= @Size, Unit=@Unit,Type=@Type, WHID=@WHID, WHLID=@WHLID, ShapeTemplate = @ShapeTemplate, UpdatedAt = @UpdatedAt,UpdatedBy =@UpdatedBy, Price=@Price,[Desc]=@Desc, Name = @Name WHERE Code = '" + item.Code + "'", new { Status = item.Status, Price = item.VATPrice / 1.1, VATPrice = item.VATPrice, Size = !string.IsNullOrEmpty(item.Size) ? item.Size.Trim() : "", Unit = !string.IsNullOrEmpty(item.Unit) ? item.Unit.Trim() : "", Type = !string.IsNullOrEmpty(item.Type) ? item.Type.Trim() : "", WHID = !string.IsNullOrEmpty(item.WHID) ? item.WHID : "", WHLID = !string.IsNullOrEmpty(item.WHLID) ? item.WHLID : "", ShapeTemplate = !string.IsNullOrEmpty(item.ShapeTemplate) ? item.ShapeTemplate.Trim() : "", UpdatedAt = DateTime.Now, UpdatedBy = currentUser.UserID, Desc = !string.IsNullOrEmpty(item.Desc) ? item.Desc.Trim() : "", Name = !string.IsNullOrEmpty(item.Name) ? item.Name.Trim() : "", }) == 1; if (!success) { return Json(new { success = false, message = "Cập nhật không thành công." }); } //item.Price = item.VATPrice / 1.1; //item.VATPrice = item.VATPrice; //item.Size = !string.IsNullOrEmpty(item.Size) ? item.Size.Trim() : ""; ; //item.Unit = !string.IsNullOrEmpty(item.Unit) ? item.Unit.Trim() : ""; ; //item.Type = !string.IsNullOrEmpty(item.Type) ? item.Type.Trim() : ""; ; //item.WHID = !string.IsNullOrEmpty(item.WHID) ? item.WHID : ""; //item.WHLID = !string.IsNullOrEmpty(item.WHLID) ? item.WHLID : ""; //item.Desc = !string.IsNullOrEmpty(item.Desc) ? item.Desc.Trim() : ""; //item.ShapeTemplate = !string.IsNullOrEmpty(item.ShapeTemplate) ? item.ShapeTemplate.Trim() : ""; //item.UpdatedAt = DateTime.Now; //item.UpdatedBy = currentUser.UserID; //item.Status = item.Status; //db.Update<Products>(item); return Json(new { success = true }); } else return Json(new { success = false, message = "Bạn không có quyền" }); } catch (Exception e) { log.Error(" ListPublication - Create - " + e.Message); return Json(new { success = false, message = e.Message }); } finally { db.Close(); } }
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(); } }