public static int InsertKhoNhapXuatDetailReturnID(DataObject.KhoNhapXuatDetail obj) { SqlConnection conn = Common.Connection.SqlConnect(); int check = 0; String select = "Select count(*) FROM KhoNhapXuatDetail where ID = " + obj.ID; SqlCommand cmd = new SqlCommand(select); cmd.CommandType = CommandType.Text; cmd.Connection = conn; conn.Open(); object count = cmd.ExecuteScalar(); conn.Close(); check = Convert.ToInt16(count); if (check > 0) { String insert = "Update KhoNhapXuatDetail SET Product_Code = @Product_Code,Product_Name = @Product_Name ,SoLuong = @SoLuong ,DonVi = @DonVi ,HanSuDung = @HanSuDung ,Gia = @Gia,Kho = @Kho where ID = @ID"; SqlCommand cmdInsert = new SqlCommand(insert); cmdInsert.CommandType = CommandType.Text; cmdInsert.Connection = conn; cmdInsert.Parameters.AddWithValue("@Product_Code", obj.Product_Code); cmdInsert.Parameters.AddWithValue("@Product_Name", obj.Product_Name); cmdInsert.Parameters.AddWithValue("@SoLuong", obj.SoLuong); cmdInsert.Parameters.AddWithValue("@DonVi", obj.DonVi); cmdInsert.Parameters.AddWithValue("@HanSuDung", obj.HanSuDung); cmdInsert.Parameters.AddWithValue("@Gia", obj.Gia); cmdInsert.Parameters.AddWithValue("@Kho", obj.Kho); cmdInsert.Parameters.AddWithValue("@ID", obj.ID); conn.Open(); cmdInsert.ExecuteNonQuery(); conn.Close(); return(obj.ID); } else { String insert = ""; if (obj.Type == 0) { insert = "Insert into KhoNhapXuatDetail (Type,NhapKhoId,Product_Code,Product_Name,SoLuong,DonVi,HanSuDung,Gia,Kho) Values(@Type,@NhapKhoId,@Product_Code,@Product_Name,@SoLuong,@DonVi,@HanSuDung,@Gia,@Kho);Select @@IDENTITY as newId"; } else if (obj.Type == 1) { insert = "Insert into KhoNhapXuatDetail (Type,XuatKhoId,Product_Code,Product_Name,SoLuong,DonVi,HanSuDung,Gia,Kho) Values(@Type,@XuatKhoId,@Product_Code,@Product_Name,@SoLuong,@DonVi,@HanSuDung,@Gia,@Kho);Select @@IDENTITY as newId"; } else if (obj.Type == 2) { insert = "Insert into KhoNhapXuatDetail (Type,NhapKhoId,Product_Code,Product_Name,SoLuong,DonVi,HanSuDung,Gia,Kho) Values(@Type,@NhapKhoId,@Product_Code,@Product_Name,@SoLuong,@DonVi,@HanSuDung,@Gia,@Kho);Select @@IDENTITY as newId"; } SqlCommand cmdInsert = new SqlCommand(insert); cmdInsert.CommandType = CommandType.Text; cmdInsert.Connection = conn; cmdInsert.Parameters.AddWithValue("@Type", obj.Type); if (obj.Type == 0) { cmdInsert.Parameters.AddWithValue("@NhapKhoId", obj.NhapKhoId); } else if (obj.Type == 1) { cmdInsert.Parameters.AddWithValue("@XuatKhoId", obj.XuatKhoId); } else if (obj.Type == 2) { cmdInsert.Parameters.AddWithValue("@NhapKhoId", obj.NhapKhoId); } cmdInsert.Parameters.AddWithValue("@Product_Code", obj.Product_Code); cmdInsert.Parameters.AddWithValue("@Product_Name", obj.Product_Name); cmdInsert.Parameters.AddWithValue("@SoLuong", obj.SoLuong); cmdInsert.Parameters.AddWithValue("@DonVi", obj.DonVi); cmdInsert.Parameters.AddWithValue("@HanSuDung", obj.HanSuDung); cmdInsert.Parameters.AddWithValue("@Gia", obj.Gia); cmdInsert.Parameters.AddWithValue("@Kho", obj.Kho); conn.Open(); object Id = cmdInsert.ExecuteScalar(); conn.Close(); return(Convert.ToInt16(Id)); } }
public void ProcessRequest(HttpContext context) { String type = context.Request.Form["type"].ToString(); //String jsonData = context.Request.Form["data"].ToString(); if (type == "viewK001P1") { try { String Ngay = context.Request.Form["Ngay"].ToString(); String thu = context.Request.Form["thu"].ToString(); List <DataObject.Kho001> result = Servies.KhoServices.viewK001P1(Ngay, thu); context.Response.ContentType = "application/json"; context.Response.Write(JsonConvert.SerializeObject(result)); } catch (Exception e) { context.Response.ContentType = "text/plain"; context.Response.Write("Error"); } } else if (type == "viewSPCL") { try { String Ngay = context.Request.Form["Ngay"].ToString(); String thu = context.Request.Form["thu"].ToString(); List <DataObject.Kho001> result = Servies.KhoServices.viewSPCL(Ngay, thu); context.Response.ContentType = "application/json"; context.Response.Write(JsonConvert.SerializeObject(result)); } catch (Exception e) { context.Response.ContentType = "text/plain"; context.Response.Write("Error"); } } else if (type == "insertOrUpdateViewK001") { try { //String Ngay, String ID,String productName,String ProductId,String productUnit,String productUnit_DK,String productUnit_CL String jsonData = context.Request.Form["data"].ToString(); dynamic data = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonData); for (int i = 0; i < data.Count; i++) { String Ngay = data[i].Ngay; String ID = data[i].ID; String productName = data[i].productName; String ProductId = data[i].ProductId; String productUnit = data[i].productUnit; String productUnit_DK = data[i].productUnit_DK; String productUnit_CL = data[i].productUnit_CL; Servies.KhoServices.insertOrUpdateViewK001(Ngay, ID, productName, ProductId, productUnit, productUnit_DK, productUnit_CL); } context.Response.ContentType = "text/plain"; context.Response.Write("1"); } catch (Exception e) { context.Response.ContentType = "text/plain"; context.Response.Write("Error"); } } else if (type == "viewK001P2") { try { // Case ID > 0 -> Result = 1 record // Case ID = 0; -> Result = All Record getUserInGroup(String MaHD,String TenKH,String TenSP) String Ngay = context.Request.Form["Ngay"].ToString(); DataTable lst = Servies.KhoServices.viewK001P2(Ngay); context.Response.ContentType = "application/json"; context.Response.Write(JsonConvert.SerializeObject(lst)); } catch (Exception e) { context.Response.ContentType = "text/plain"; context.Response.Write("Error"); } } else if (type == "viewK002") { try { String TuNgay = context.Request.Form["TuNgay"].ToString(); String DenNgay = context.Request.Form["DenNgay"].ToString(); List <DataObject.Kho002> lst = Servies.KhoServices.viewK002(TuNgay, DenNgay); context.Response.ContentType = "application/json"; context.Response.Write(JsonConvert.SerializeObject(lst)); } catch (Exception e) { context.Response.ContentType = "text/plain"; context.Response.Write("Error"); } } else if (type == "InsertKho003ReturnID") { try { String jsonData = context.Request.Form["data"].ToString(); dynamic data = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonData); DataObject.Kho003 obj = new DataObject.Kho003(); dynamic dataPX = data.PX; obj.ID = Convert.ToInt16(dataPX.ID); obj.NhaCungCap = (String)dataPX.NhaCungCap; obj.Ten = (String)dataPX.Ten; obj.SoDT = (String)dataPX.SoDT; obj.DiaChi = (String)dataPX.DiaChi; obj.Ngay = DateTime.ParseExact((String)dataPX.Ngay, "dd/MM/yyyy", CultureInfo.InvariantCulture); obj.Kho = Convert.ToInt16(dataPX.Kho); obj.GhiChu = (String)dataPX.GhiChu; obj.NgayTao = DateTime.ParseExact(DateTime.Now.ToString("dd/MM/yyyy"), "dd/MM/yyyy", CultureInfo.InvariantCulture); obj.NguoiTao = HttpContext.Current.Session["UserName"].ToString(); obj.MaPhieuNhap = "PN-" + DateTime.Now.ToString("ddMMyy") + DateTime.Now.ToString("tt") + DateTime.Now.ToString("hh"); obj.MaPhieuXuat = "PX-" + DateTime.Now.ToString("ddMMyy") + DateTime.Now.ToString("tt") + DateTime.Now.ToString("hh"); obj.Type = Convert.ToInt16(dataPX.Type); int result = Servies.KhoServices.InsertKho003ReturnID(obj); dynamic dataDetail = data.Detail; for (int i = 0; i < dataDetail.Count; i++) { DataObject.KhoNhapXuatDetail detail = new DataObject.KhoNhapXuatDetail(); detail.Type = Convert.ToInt16(dataDetail[i].Type); detail.ID = Convert.ToInt16(dataDetail[i].ID); if (detail.Type == 0) { detail.NhapKhoId = result; } else if (detail.Type == 1) { detail.XuatKhoId = result; } else if (detail.Type == 2) { detail.NhapKhoId = result; } detail.Product_Code = (String)dataDetail[i].Product_Code; detail.Product_Name = (String)dataDetail[i].Product_Name; detail.SoLuong = Convert.ToInt16(dataDetail[i].SoLuong); detail.DonVi = (String)dataDetail[i].DonVi; detail.HanSuDung = DateTime.ParseExact((String)dataDetail[i].HanSuDung, "dd/MM/yyyy", CultureInfo.InvariantCulture); detail.Gia = (String)dataDetail[i].Gia; detail.Kho = Convert.ToInt16(dataDetail[i].Kho); Servies.KhoServices.InsertKhoNhapXuatDetailReturnID(detail); } context.Response.ContentType = "text/plain"; if (obj.Type == 0) { context.Response.Write(obj.MaPhieuNhap); } else if (obj.Type == 1) { context.Response.Write(obj.MaPhieuXuat); } else if (obj.Type == 2) { context.Response.Write(obj.MaPhieuNhap); } } catch (Exception e) { context.Response.ContentType = "text/plain"; context.Response.Write("Error"); } } else if (type == "viewDetailNhapXuatKho") { try { String Type = context.Request.Form["TypeXNK"].ToString(); String IdNhapXuat = context.Request.Form["IdNhapXuat"].ToString(); List <DataTable> lst = Servies.KhoServices.viewDetailNhapXuatKho(Convert.ToInt16(Type), Convert.ToInt16(IdNhapXuat)); context.Response.ContentType = "application/json"; context.Response.Write(JsonConvert.SerializeObject(lst)); } catch (Exception e) { context.Response.ContentType = "text/plain"; context.Response.Write("Error"); } } else if (type == "viewNhapXuatKho") { try { String Type = context.Request.Form["TypeXNK"].ToString(); String Ma = context.Request.Form["Ma"].ToString(); String KhoId = context.Request.Form["KhoId"].ToString(); String Ngay = context.Request.Form["Ngay"].ToString(); DataTable lst = Servies.KhoServices.viewNhapXuatKho(Convert.ToInt16(Type), Ma, Convert.ToInt16(KhoId), Ngay); context.Response.ContentType = "application/json"; context.Response.Write(JsonConvert.SerializeObject(lst)); } catch (Exception e) { context.Response.ContentType = "text/plain"; context.Response.Write("Error"); } } else if (type == "insertOrUpdateNhaCungCap") { String jsonData = context.Request.Form["data"].ToString(); dynamic data = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonData); DataObject.NhaCungCap obj = new DataObject.NhaCungCap(); obj.ID = Convert.ToInt16(data.ID); obj.MaNCC = (String)data.MaNCC; obj.TenNCC = (String)data.TenNCC; obj.SoDT = (String)data.SoDT; obj.Tinh = (String)data.Tinh; obj.DiaChi = (String)data.DiaChi; obj.LoaiDichVu = (String)data.LoaiDichVu; obj.GhiChu = (String)data.GhiChu; obj.NgayTao = DateTime.ParseExact(DateTime.Now.ToString("dd/MM/yyyy"), "dd/MM/yyyy", CultureInfo.InvariantCulture); obj.NguoiTao = HttpContext.Current.Session["UserName"].ToString(); int kq = Servies.KhoServices.insertOrUpdateNhaCungCap(obj); context.Response.ContentType = "text/plain"; context.Response.Write(kq); } else if (type == "DeleteNhaCungCap") { int ID = Convert.ToInt16(context.Request.Form["ID"].ToString()); Servies.KhoServices.DeleteNhaCungCap(ID); context.Response.ContentType = "text/plain"; context.Response.Write("1"); } else if (type == "viewNhaCungCap") { //viewNhaCungCap(String MaNCC, String TenNCC, String SoDT, String Tinh, String LoaiDichVu) String MaNCC = context.Request.Form["MaNCC"].ToString(); String TenNCC = context.Request.Form["TenNCC"].ToString(); String SoDT = context.Request.Form["SoDT"].ToString(); String Tinh = context.Request.Form["Tinh"].ToString(); String LoaiDichVu = context.Request.Form["LoaiDichVu"].ToString(); DataTable dt = Servies.KhoServices.viewNhaCungCap(MaNCC, TenNCC, SoDT, Tinh, LoaiDichVu); context.Response.ContentType = "application/json"; context.Response.Write(JsonConvert.SerializeObject(dt)); } else { context.Response.ContentType = "text/plain"; context.Response.Write("1"); } }
public String InsertKho003ReturnID(String type, String data) { try { dynamic dataDynamic = Newtonsoft.Json.JsonConvert.DeserializeObject(data); DataObject.Kho003 obj = new DataObject.Kho003(); dynamic dataPX = dataDynamic.PX; obj.ID = Convert.ToInt16(dataPX.ID); obj.NhaCungCap = (String)dataPX.NhaCungCap; obj.Ten = (String)dataPX.Ten; obj.SoDT = (String)dataPX.SoDT; obj.DiaChi = (String)dataPX.DiaChi; obj.Ngay = DateTime.ParseExact((String)dataPX.Ngay, "dd/MM/yyyy", CultureInfo.InvariantCulture); obj.Kho = Convert.ToInt16(dataPX.Kho); obj.GhiChu = (String)dataPX.GhiChu; obj.NgayTao = DateTime.ParseExact(DateTime.Now.ToString("dd/MM/yyyy"), "dd/MM/yyyy", CultureInfo.InvariantCulture); obj.NguoiTao = this.Session["UserName"].ToString(); obj.MaPhieuNhap = "PN-" + DateTime.Now.ToString("ddMMyy") + DateTime.Now.ToString("tt") + DateTime.Now.ToString("hh"); obj.MaPhieuXuat = "PX-" + DateTime.Now.ToString("ddMMyy") + DateTime.Now.ToString("tt") + DateTime.Now.ToString("hh"); obj.Type = Convert.ToInt16(dataPX.Type); int result = Servies.KhoServices.InsertKho003ReturnID(obj); dynamic dataDetail = dataDynamic.Detail; for (int i = 0; i < dataDetail.Count; i++) { DataObject.KhoNhapXuatDetail detail = new DataObject.KhoNhapXuatDetail(); detail.Type = Convert.ToInt16(dataDetail[i].Type); detail.ID = Convert.ToInt16(dataDetail[i].ID); if (detail.Type == 0) { detail.NhapKhoId = result; } else if (detail.Type == 1) { detail.XuatKhoId = result; } else if (detail.Type == 2) { detail.NhapKhoId = result; } detail.Product_Code = (String)dataDetail[i].Product_Code; detail.Product_Name = (String)dataDetail[i].Product_Name; detail.SoLuong = Convert.ToInt16(dataDetail[i].SoLuong); detail.DonVi = (String)dataDetail[i].DonVi; detail.HanSuDung = DateTime.ParseExact((String)dataDetail[i].HanSuDung, "dd/MM/yyyy", CultureInfo.InvariantCulture); detail.Gia = (String)dataDetail[i].Gia; detail.Kho = Convert.ToInt16(dataDetail[i].Kho); Servies.KhoServices.InsertKhoNhapXuatDetailReturnID(detail); } if (obj.Type == 0) { return(obj.MaPhieuNhap.ToString()); } else if (obj.Type == 1) { return(obj.MaPhieuXuat.ToString()); } else if (obj.Type == 2) { return(obj.MaPhieuNhap.ToString()); } return(""); } catch (Exception e) { e.ToString(); return(""); } }