public static int InsertDataReturnId(DataObject.HoaDon obj)
        {
            String        Insert = "INSERT INTO HoaDon (IDKhachHang,IDNguon,TongTien,TongTienThuDuoc,TongTienConNo,ChietKhau,TrangThai,NgayTao,NguoiTao,TongSoNgay) VALUES (@IDKhachHang,@IDNguon,@TongTien,@TongTienThuDuoc,@TongTienConNo,@ChietKhau,@TrangThai,@NgayTao,@NguoiTao,@TongSoNgay);Select @@IDENTITY as newId";
            SqlConnection conn   = Common.Connection.SqlConnect();
            SqlCommand    cmd    = new SqlCommand(Insert);

            cmd.CommandType = CommandType.Text;
            cmd.Connection  = conn;
            cmd.Parameters.AddWithValue("@IDKhachHang", obj.IDKhachHang);
            cmd.Parameters.AddWithValue("@IDNguon", obj.IDNguon);
            cmd.Parameters.AddWithValue("@TongTien", obj.TongTien);
            cmd.Parameters.AddWithValue("@TongTienThuDuoc", obj.TongTienThuDuoc);
            cmd.Parameters.AddWithValue("@TongTienConNo", obj.TongTienConNo);
            cmd.Parameters.AddWithValue("@ChietKhau", obj.ChietKhau);
            cmd.Parameters.AddWithValue("@TrangThai", obj.TrangThai);
            cmd.Parameters.AddWithValue("@NgayTao", obj.NgayTao);
            cmd.Parameters.AddWithValue("@NguoiTao", obj.NguoiTao);
            cmd.Parameters.AddWithValue("@TongSoNgay", obj.TongSoNgay);
            conn.Open();
            object insertedID = cmd.ExecuteScalar();

            cmd.Connection.Close();
            conn.Close();
            return(Convert.ToInt32(insertedID));
        }
        public ContentResult updateStatusVHoaDonStep2(String type, String data, String ID)
        {
            try
            {
                // Case ID > 0 -> Result = 1 record
                // Case ID = 0; -> Result = All Record getvHoaDonStep1(
                //String MaHD, String tuNgay, String denNgay, String trangThai, String TenKH, String SoDT)
                dynamic           dataDynamic = Newtonsoft.Json.JsonConvert.DeserializeObject(data);
                dynamic           hoadon      = dataDynamic.HD;
                dynamic           lsthoadon   = dataDynamic.NHD;
                DataObject.HoaDon dtoHoaDon   = new DataObject.HoaDon();
                int    idHoadon      = (int)hoadon.id;
                String sotienthuduoc = (String)hoadon.sotienthu;
                dtoHoaDon.TongTienThuDuoc = Convert.ToDecimal(sotienthuduoc != "" ? sotienthuduoc : "0");
                String conNo = (String)hoadon.sotienconlai;
                dtoHoaDon.TongTienConNo = Convert.ToDecimal(conNo != "" ? conNo : "0");
                Servies.HoaDonServices.updateHoaDonStep2(idHoadon, dtoHoaDon);
                for (int i = 0; i < lsthoadon.Count; i++)
                {
                    DataObject.NgayHoaDon ngayhoadon = new DataObject.NgayHoaDon();
                    //ngayhoadon.Ngay = Convert.ToDateTime((String)lsthoadon[i].date);
                    if ((String)lsthoadon[i].date != "")
                    {
                        ngayhoadon.Ngay = DateTime.ParseExact((String)lsthoadon[i].date, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                    }

                    var ghichu = (String)lsthoadon[i].ghichu;
                    ngayhoadon.GhiChu    = ghichu != null ? ghichu : "";
                    ngayhoadon.TrangThai = (String)lsthoadon[i].status;
                    String tong         = (String)lsthoadon[i].money;
                    String sotiendathu  = (String)lsthoadon[i].sotiendathu;
                    String sotienconlai = (String)lsthoadon[i].sotienconlai;
                    ngayhoadon.TongTien     = Convert.ToDecimal(tong != "" ? tong : "0");
                    ngayhoadon.SoTienThu    = Convert.ToDecimal(sotiendathu != "" ? sotiendathu : "0");
                    ngayhoadon.SoTienConLai = Convert.ToDecimal(sotienconlai != "" ? sotienconlai : "0");
                    Servies.HoaDonServices.updateNgayHoaDonStep2((int)lsthoadon[i].IdNgayHD, ngayhoadon);
                }
                String    IDHD = Convert.ToString(idHoadon);
                DataTable lst  = Servies.HoaDonServices.getvHoaDonStep2(IDHD);
                var       list = JsonConvert.SerializeObject(lst,
                                                             Formatting.None,
                                                             new JsonSerializerSettings()
                {
                    ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
                });

                return(Content(list, "application/json"));
            }
            catch (Exception e)
            {
                e.ToString();
                return(null);
            }
        }
        public static void updateHoaDonStep2(int HoadonID, DataObject.HoaDon hoadon)
        {
            SqlConnection conn   = Common.Connection.SqlConnect();
            String        Update = "UPDATE HoaDon SET TongTienThuDuoc = @TongTienThuDuoc , TongTienConNo = @TongTienConNo Where ID = @ID";
            SqlCommand    cmd    = new SqlCommand(Update);

            cmd.CommandType = CommandType.Text;
            cmd.Connection  = conn;
            cmd.Parameters.AddWithValue("@TongTienThuDuoc", hoadon.TongTienThuDuoc);
            cmd.Parameters.AddWithValue("@TongTienConNo", hoadon.TongTienConNo);
            cmd.Parameters.AddWithValue("@ID", HoadonID);
            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();
        }
        public static int getTachBill(String idHD, String IdCTHD, String IdPCTHD, String IdNgayHD, String ThanhTien)
        {
            SqlCommand    cmd             = null;
            SqlCommand    cmdUpdateHoaDon = null;
            SqlCommand    cmdInsertPCTHD  = null;
            SqlCommand    cmdUpdatePCTHD  = null;
            int           IdHDNew         = -1;
            SqlConnection conn            = Common.Connection.SqlConnect();
            String        Select          = "Select * from HoaDon where ID = " + idHD;

            cmd             = new SqlCommand(Select);
            cmd.CommandType = CommandType.Text;
            cmd.Connection  = conn;
            conn.Open();
            using (SqlDataReader oReader = cmd.ExecuteReader())
            {
                while (oReader.Read())
                {
                    DataObject.HoaDon obj = new DataObject.HoaDon();
                    obj.IDKhachHang     = Int32.Parse(oReader["IDKhachHang"].ToString());
                    obj.IDNguon         = Int32.Parse(oReader["IDNguon"].ToString());
                    obj.TongTien        = Convert.ToDecimal(ThanhTien);
                    obj.TongTienThuDuoc = Convert.ToDecimal("0");
                    obj.TongTienConNo   = Convert.ToDecimal("0");
                    obj.ChietKhau       = Convert.ToDecimal(oReader["ChietKhau"].ToString());
                    obj.TrangThai       = oReader["TrangThai"].ToString();
                    if (oReader["NgayTao"].ToString() != "" && oReader["NgayTao"].ToString() != null)
                    {
                        String createDate = String.Format("{0:dd/MM/yyyy}", DateTime.Now.ToShortDateString());
                        obj.NgayTao = DateTime.Parse(createDate);
                    }
                    obj.NguoiTao   = oReader["NguoiTao"].ToString();
                    obj.TongSoNgay = Int32.Parse(oReader["TongSoNgay"].ToString());
                    Decimal TongTienHD = Convert.ToDecimal(oReader["TongTien"].ToString()) - Convert.ToDecimal(ThanhTien);
                    IdHDNew = InsertDataReturnId(obj);
                    conn.Close();
                    //Update Lai Tien HD

                    String updateHoaDon = "Update HoaDon set TongTien = @TongTien where ID =@ID";
                    cmdUpdateHoaDon             = new SqlCommand(updateHoaDon);
                    cmdUpdateHoaDon.CommandType = CommandType.Text;
                    cmdUpdateHoaDon.Connection  = conn;
                    cmdUpdateHoaDon.Parameters.AddWithValue("@TongTien", TongTienHD);
                    cmdUpdateHoaDon.Parameters.AddWithValue("@ID", Convert.ToInt32(idHD));
                    conn.Open();
                    cmdUpdateHoaDon.ExecuteNonQuery();
                    conn.Close();
                    break;
                }
            }



            String SelectChiTietHoaDon = "Select * from ChiTietHoaDon where ID = " + IdCTHD;

            cmdInsertPCTHD             = new SqlCommand(SelectChiTietHoaDon);
            cmdInsertPCTHD.CommandType = CommandType.Text;
            cmdInsertPCTHD.Connection  = conn;
            conn.Open();
            int IdPCTHDNew = -1;

            using (SqlDataReader oReader = cmdInsertPCTHD.ExecuteReader())
            {
                while (oReader.Read())
                {
                    DataObject.ChiTietHoaDon obj = new DataObject.ChiTietHoaDon();
                    obj.IDHoaDon    = IdHDNew;
                    obj.IdKhachHang = Int32.Parse(oReader["IdKhachHang"].ToString());
                    obj.IsMaster    = 1;
                    obj.tabIndex    = 1;
                    obj.TrangThai   = oReader["TrangThai"].ToString();
                    IdPCTHDNew      = InsertChiTietHoaDonReturnId(obj);
                    conn.Close();
                    String updatePCTHD = "Update PackageChiTietHoaDon set  IDChiTietHD = " + IdPCTHDNew + " where ID = " + IdPCTHD;
                    cmdUpdatePCTHD             = new SqlCommand(updatePCTHD);
                    cmdUpdatePCTHD.CommandType = CommandType.Text;
                    cmdUpdatePCTHD.Connection  = conn;
                    conn.Open();
                    cmdUpdatePCTHD.ExecuteNonQuery();
                    conn.Close();
                    break;
                }
            }

            return(IdHDNew);
        }
Exemple #5
0
        // private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        public void ProcessRequest(HttpContext context)
        {
            String type     = context.Request.Form["type"].ToString();
            String jsonData = context.Request.Form["data"].ToString();

            //DataObject.viewBillTemp obj = new JavaScriptSerializer().Deserialize<DataObject.viewBillTemp>(jsonData);
            if (type == "insert")
            {
                try
                {
                    String hoten         = "";
                    String maKH          = "";
                    String ngaySinh      = "";
                    String soDienThoai   = "";
                    String email         = "";
                    String diaChi        = "";
                    String maquan        = "";
                    String sourceName    = "";
                    String sourceId      = "";
                    String songayconlai  = "";
                    String tong          = "";
                    String sotienthuduoc = "";
                    String chietkhau     = "";
                    String conNo         = "";

                    dynamic data         = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonData);
                    dynamic inFoCustomer = data.inFoCustomer;
                    dynamic infoBill     = data.infoBill;
                    hoten         = inFoCustomer.hoTen;
                    maKH          = inFoCustomer.maKH;
                    ngaySinh      = inFoCustomer.ngaySinh;
                    soDienThoai   = inFoCustomer.soDienThoai;
                    email         = inFoCustomer.email;
                    diaChi        = inFoCustomer.diaChi;
                    maquan        = inFoCustomer.maquan;
                    sourceName    = data.sourceName;
                    sourceId      = data.sourceId;
                    songayconlai  = data.songayconlai;
                    tong          = data.tong;
                    sotienthuduoc = data.sotienthuduoc;
                    chietkhau     = data.chietkhau;
                    conNo         = data.conNo;
                    int isMasterTab = data.isMasterTab;

                    /*********************************
                    * Check and Insert Khách hàng nếu không tồn tại
                    * Nếu tồn tại getId Khách hàng
                    *
                    * *******************************/
                    int IdKhachHang = returnIdKH(soDienThoai, hoten, email, diaChi, maquan, ngaySinh);

                    /*********************************
                    * Insert Hóa đơn
                    *
                    * *******************************/
                    DataObject.HoaDon hoadon = new DataObject.HoaDon();
                    hoadon.IDKhachHang     = IdKhachHang;
                    hoadon.IDNguon         = Convert.ToInt32(sourceId);
                    hoadon.NgayTao         = DateTime.ParseExact(DateTime.Now.ToString("dd/MM/yyyy"), "dd/MM/yyyy", CultureInfo.InvariantCulture);
                    hoadon.NguoiTao        = "";
                    hoadon.TongSoNgay      = Convert.ToInt32(songayconlai);
                    hoadon.TongTien        = Convert.ToDecimal(tong != "" ? tong : "0");
                    hoadon.TongTienConNo   = Convert.ToDecimal(conNo != "" ? conNo : "0");
                    hoadon.TongTienThuDuoc = Convert.ToDecimal(sotienthuduoc != "" ? sotienthuduoc : "0");
                    hoadon.TrangThai       = "Chưa xử lý";
                    hoadon.ChietKhau       = Convert.ToDecimal(sotienthuduoc != "" ? chietkhau : "0");
                    int hoadonId = Servies.HoaDonServices.InsertDataReturnId(hoadon);

                    /*********************************
                    * Insert Chi tiết hóa đơn , hoa đơn package , hóa đơn ngày , sản phẩm
                    *
                    * *******************************/
                    for (int i = 0; i < infoBill.Count; i++)
                    {
                        bool checkMasterTab = false;
                        if (isMasterTab == i)
                        {
                            checkMasterTab = true;
                        }
                        int     IdChiTietHoaHD = InsertChiTietHoaDonReturnId(infoBill[i], hoadonId, IdKhachHang, checkMasterTab);
                        dynamic dataHD         = infoBill[i].data;
                        for (int k = 0; k < dataHD.Count; k++)
                        {
                            int     idPackageHD       = InsertPackageChiTietHoaDonReturnId(dataHD[k], IdChiTietHoaHD);
                            String  hinhthucthanhtoan = (String)dataHD[k].fLoaiThanhToanId;
                            dynamic detailMaster      = dataHD[k].detalMaster;
                            int     idNgayHDLe        = -1;
                            int     idNgayHD          = -1;
                            for (int j = 0; j < detailMaster.Count; j++)
                            {
                                if (dataHD[k].fLoaiHinhDonId == 1)
                                {
                                    if (detailMaster[j].deliveryDate != "")
                                    {
                                        idNgayHD = InsertNgayHoaDonReturnId(detailMaster[j], idPackageHD, hinhthucthanhtoan);
                                        InsertKhachHangNgay(idNgayHD, dataHD[k]);
                                    }
                                    else
                                    {
                                        InsertHoaDonSanPhamReturnId(detailMaster[j], idNgayHD);
                                    }
                                }
                                else
                                {
                                    if (j == 0)
                                    {
                                        idNgayHDLe = InsertNgayHoaDonLeReturnId(detailMaster[j], idPackageHD, (String)dataHD[k].ngayGiaoHangLe, hinhthucthanhtoan);
                                        InsertKhachHangNgay(idNgayHDLe, dataHD[k]);
                                        InsertHoaDonSanPhamReturnId(detailMaster[j], idNgayHDLe);
                                        //InsertNgayHoaDonLeReturnId(detailMaster[j], idPackageHD, dataHD[k].ngayGiaoHangLe);
                                    }
                                    else
                                    {
                                        InsertHoaDonSanPhamReturnId(detailMaster[j], idNgayHDLe);
                                    }
                                }
                            }
                        }
                    }
                    context.Response.ContentType = "text/plain";
                    context.Response.Write(hoadonId);
                }
                catch (Exception e)
                {
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("001");
                }
            }
            else if (type == "update")
            {
                try
                {
                    //Update(obj);
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("insert data success");
                }
                catch (Exception e)
                {
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("Error");
                }
            }
            else if (type == "delete")
            {
                try
                {
                    //DeleteData(obj.ID);
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("insert data success");
                }
                catch (Exception e)
                {
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("Error");
                }
            }
            else if (type == "getData")
            {
                try
                {
                    // Case ID > 0 -> Result = 1 record
                    // Case ID = 0; -> Result = All Record getDataViewHoaDon(String MaHD,String TenKH,String TenSP)
                    String    MaHD  = context.Request.Form["MaHD"].ToString();
                    String    TenKH = context.Request.Form["TenKH"].ToString();
                    String    TenSP = context.Request.Form["TenSP"].ToString();
                    DataTable lst   = Servies.HoaDonServices.getDataViewHoaDon(MaHD, TenKH, TenSP);
                    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 == "getvHoaDonStep1")
            {
                try
                {
                    // Case ID > 0 -> Result = 1 record
                    // Case ID = 0; -> Result = All Record getvHoaDonStep1(
                    //String MaHD, String tuNgay, String denNgay, String trangThai, String TenKH, String SoDT)
                    String    MaHD      = context.Request.Form["MaHD"].ToString();
                    String    tuNgay    = context.Request.Form["tuNgay"].ToString();
                    String    denNgay   = context.Request.Form["denNgay"].ToString();
                    String    trangThai = context.Request.Form["trangThai"].ToString();
                    String    TenKH     = context.Request.Form["TenKH"].ToString();
                    String    SoDT      = context.Request.Form["SoDT"].ToString();
                    DataTable lst       = Servies.HoaDonServices.getvHoaDonStep1(MaHD, tuNgay, denNgay, trangThai, TenKH, SoDT);
                    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 == "getvHoaDonStep2")
            {
                try
                {
                    // Case ID > 0 -> Result = 1 record
                    // Case ID = 0; -> Result = All Record getvHoaDonStep1(
                    //String MaHD, String tuNgay, String denNgay, String trangThai, String TenKH, String SoDT)
                    String    ID  = context.Request.Form["ID"].ToString();
                    DataTable lst = Servies.HoaDonServices.getvHoaDonStep2(ID);
                    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 == "updateStatusVHoaDonStep1")
            {
                try
                {
                    // Case ID > 0 -> Result = 1 record
                    // Case ID = 0; -> Result = All Record getvHoaDonStep1(
                    //String MaHD, String tuNgay, String denNgay, String trangThai, String TenKH, String SoDT)
                    dynamic data = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonData);
                    for (int i = 0; i < data.Count; i++)
                    {
                        Servies.HoaDonServices.updateStatusVHoaDonStep1((int)data[i].idHoaDon, (String)data[i].statusBill);
                    }
                    context.Response.ContentType = "text/plain";
                    context.Response.Write(JsonConvert.SerializeObject("1"));
                }
                catch (Exception e)
                {
                    context.Response.ContentType = "text/plain";
                    context.Response.Write(JsonConvert.SerializeObject("0"));
                }
            }
            else if (type == "updateStatusVHoaDonStep2")
            {
                try
                {
                    // Case ID > 0 -> Result = 1 record
                    // Case ID = 0; -> Result = All Record getvHoaDonStep1(
                    //String MaHD, String tuNgay, String denNgay, String trangThai, String TenKH, String SoDT)
                    dynamic           data      = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonData);
                    dynamic           hoadon    = data.HD;
                    dynamic           lsthoadon = data.NHD;
                    DataObject.HoaDon dtoHoaDon = new DataObject.HoaDon();
                    int    idHoadon             = (int)hoadon.id;
                    String sotienthuduoc        = (String)hoadon.sotienthu;
                    dtoHoaDon.TongTienThuDuoc = Convert.ToDecimal(sotienthuduoc != "" ? sotienthuduoc : "0");
                    String conNo = (String)hoadon.sotienconlai;
                    dtoHoaDon.TongTienConNo = Convert.ToDecimal(conNo != "" ? conNo : "0");
                    Servies.HoaDonServices.updateHoaDonStep2(idHoadon, dtoHoaDon);
                    for (int i = 0; i < lsthoadon.Count; i++)
                    {
                        DataObject.NgayHoaDon ngayhoadon = new DataObject.NgayHoaDon();
                        //ngayhoadon.Ngay = Convert.ToDateTime((String)lsthoadon[i].date);
                        ngayhoadon.Ngay = DateTime.ParseExact((String)lsthoadon[i].date, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                        var ghichu = (String)lsthoadon[i].ghichu;
                        ngayhoadon.GhiChu    = ghichu != null ? ghichu : "";
                        ngayhoadon.TrangThai = (String)lsthoadon[i].status;
                        String tong         = (String)lsthoadon[i].money;
                        String sotiendathu  = (String)lsthoadon[i].sotiendathu;
                        String sotienconlai = (String)lsthoadon[i].sotienconlai;
                        ngayhoadon.TongTien     = Convert.ToDecimal(tong != "" ? tong : "0");
                        ngayhoadon.SoTienThu    = Convert.ToDecimal(sotiendathu != "" ? sotiendathu : "0");
                        ngayhoadon.SoTienConLai = Convert.ToDecimal(sotienconlai != "" ? sotienconlai : "0");
                        Servies.HoaDonServices.updateNgayHoaDonStep2((int)lsthoadon[i].IdNgayHD, ngayhoadon);
                    }
                    String    ID  = Convert.ToString(idHoadon);
                    DataTable lst = Servies.HoaDonServices.getvHoaDonStep2(ID);
                    context.Response.ContentType = "application/json";
                    context.Response.Write(JsonConvert.SerializeObject(lst));
                }
                catch (Exception e)
                {
                    context.Response.ContentType = "text/plain";
                    context.Response.Write(JsonConvert.SerializeObject("0"));
                }
            }
            else if (type == "getvHoaDonStep3")
            {
                try
                {
                    // Case ID > 0 -> Result = 1 record
                    // Case ID = 0; -> Result = All Record getvHoaDonStep1(
                    //String MaHD, String tuNgay, String denNgay, String trangThai, String TenKH, String SoDT)
                    String    ngayhdId = context.Request.Form["ngayhdId"].ToString();
                    DataTable lst      = Servies.HoaDonServices.getvHoaDonStep3(ngayhdId);
                    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 == "getSoLanGiao")
            {
                try
                {
                    // Case ID > 0 -> Result = 1 record
                    // Case ID = 0; -> Result = All Record getvHoaDonStep1(
                    //String MaHD, String tuNgay, String denNgay, String trangThai, String TenKH, String SoDT)
                    String ngayhdId = context.Request.Form["ngayhdId"].ToString();
                    int    solan    = Servies.HoaDonServices.getSoLanGiao(ngayhdId);
                    context.Response.ContentType = "text/plain";
                    context.Response.Write(solan);
                }
                catch (Exception e)
                {
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("Error");
                }
            }
            else if (type == "getSoTienChuaXuLy")
            {
                try
                {
                    // Case ID > 0 -> Result = 1 record
                    // Case ID = 0; -> Result = All Record getvHoaDonStep1(
                    //String MaHD, String tuNgay, String denNgay, String trangThai, String TenKH, String SoDT)
                    String ngayhdId = context.Request.Form["ngayhdId"].ToString();
                    Int32  sotien   = Servies.HoaDonServices.getSoTienChuaXuLy(ngayhdId);
                    context.Response.ContentType = "text/plain";
                    context.Response.Write(sotien);
                }
                catch (Exception e)
                {
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("Error");
                }
            }
            else if (type == "updateStatusVHoaDonStep3")
            {
                try
                {
                    // Case ID > 0 -> Result = 1 record
                    // Case ID = 0; -> Result = All Record getvHoaDonStep1(
                    //String MaHD, String tuNgay, String denNgay, String trangThai, String TenKH, String SoDT)
                    dynamic data         = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonData);
                    dynamic infoKH       = data.infoKH;
                    dynamic infoGoi      = data.infoGoi;
                    dynamic infoSP       = data.infoSP;
                    dynamic infoIdDelete = data.infoDeleteIdSP;
                    /*** Update Khách hàng *****/
                    DataObject.SysCustomer sysCustomer = new DataObject.SysCustomer();
                    sysCustomer.Address = (String)infoKH.diaChi;
                    if (infoKH.ngaySinh != "")
                    {
                        sysCustomer.BirthDay = DateTime.ParseExact((String)infoKH.ngaySinh, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                    }
                    sysCustomer.CustomerName = (String)infoKH.hoTen;
                    sysCustomer.Email        = (String)infoKH.email;
                    sysCustomer.ID           = (int)infoKH.idKH;
                    sysCustomer.PhoneNumber  = (String)infoKH.soDienThoai;
                    sysCustomer.MaQuan       = (String)infoKH.maquan;
                    Servies.SysCustomerServices.UpdateDataTableKH(sysCustomer);
                    /*** Update Gói *****/
                    Servies.HoaDonServices.updateGóiStepV3((String)infoGoi.idngayHD, (String)infoGoi.GhiChu, (String)infoGoi.tienTangGiam);
                    /** Update, Delete , Insert Sản phẩm ******/
                    if (infoIdDelete.Count > 0)
                    {
                        for (int i = 0; i < infoIdDelete.Count; i++)
                        {
                            Servies.HoaDonServices.deleteHoaDonSP((String)infoIdDelete[i]);
                        }
                    }

                    for (int k = 0; k < infoSP.Count; k++)
                    {
                        if ((String)infoSP[k].idhdSp == "")
                        {
                            InsertDataStep3ReturnId(infoSP[k], Convert.ToInt32((String)infoSP[k].idngayHD));
                        }
                        else
                        {
                            UpdateHoaDonSP(infoSP[k], Convert.ToInt32((String)infoSP[k].idngayHD));
                        }
                    }

                    context.Response.ContentType = "text/plain";
                    context.Response.Write(JsonConvert.SerializeObject("1"));
                }
                catch (Exception e)
                {
                    context.Response.ContentType = "text/plain";
                    context.Response.Write(JsonConvert.SerializeObject("0"));
                }
            }
            else if (type == "getGoiHD")
            {
                try
                {
                    // Case ID > 0 -> Result = 1 record
                    // Case ID = 0; -> Result = All Record getvHoaDonStep1(
                    //String MaHD, String tuNgay, String denNgay, String trangThai, String TenKH, String SoDT)

                    DataTable dt = Servies.HoaDonServices.getGoiHD();
                    context.Response.ContentType = "application/json";
                    context.Response.Write(JsonConvert.SerializeObject(dt));
                }
                catch (Exception e)
                {
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("Error");
                }
            }
            else if (type == "uploadFile")
            {
                try
                {
                    // Case ID > 0 -> Result = 1 record
                    // Case ID = 0; -> Result = All Record getvHoaDonStep1(
                    //String MaHD, String tuNgay, String denNgay, String trangThai, String TenKH, String SoDT)
                    HttpPostedFile file = context.Request.Files[0];

                    if (file.ContentLength > 0)
                    {
                        IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(file.InputStream);
                        DataSet          result      = excelReader.AsDataSet();
                        excelReader.IsFirstRowAsColumnNames = true;
                        DataTable dt = result.Tables[0];

                        /*
                         * for (Int32 i = 1; i < dt.Rows.Count; i++)
                         * {
                         *  String x = "1";
                         * }*/
                        //do something
                        context.Response.ContentType = "application/json";
                        context.Response.Write(JsonConvert.SerializeObject(dt));
                    }
                    //DataTable dt = Servies.HoaDonServices.getGoiHD();
                    //context.Response.ContentType = "application/json";
                    //context.Response.Write(JsonConvert.SerializeObject(dt));
                    //context.Response.ContentType = "text/plain";
                    // context.Response.Write("Error");
                }
                catch (Exception e)
                {
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("Error");
                }
            }//tachbill
            else if (type == "tachbill")
            {
                try
                {
                    // Case ID > 0 -> Result = 1 record
                    // Case ID = 0; -> Result = All Record getDataViewHoaDon(String MaHD,String TenKH,String TenSP)
                    String idHD      = context.Request.Form["idHD"].ToString();
                    String IdCTHD    = context.Request.Form["IdCTHD"].ToString();
                    String IdPCTHD   = context.Request.Form["IdPCTHD"].ToString();
                    String IdNgayHD  = context.Request.Form["IdNgayHD"].ToString();
                    String ThanhTien = context.Request.Form["ThanhTien"].ToString();
                    Int32  IdHDNew   = Servies.HoaDonServices.getTachBill(idHD, IdCTHD, IdPCTHD, IdNgayHD, ThanhTien);
                    context.Response.ContentType = "text/plain";
                    context.Response.Write(IdHDNew);
                    //log.Info(maxId);
                }
                catch (Exception e)
                {
                    //log.Error("Error function getMaxIdHoaDon ",e);
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("Error");
                }
            }
            else if (type == "getLv2HD")
            {
                try
                {
                    // Case ID > 0 -> Result = 1 record
                    // Case ID = 0; -> Result = All Record getDataViewHoaDon(String MaHD,String TenKH,String TenSP)
                    String idHD = context.Request.Form["idHD"].ToString();

                    DataTable dt = Servies.HoaDonServices.getLv2HD(idHD);
                    context.Response.ContentType = "application/json";
                    context.Response.Write(JsonConvert.SerializeObject(dt));
                    //log.Info(maxId);
                }
                catch (Exception e)
                {
                    //log.Error("Error function getMaxIdHoaDon ",e);
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("Error");
                }
            }
            else if (type == "getLv3HD")
            {
                try
                {
                    // Case ID > 0 -> Result = 1 record
                    // Case ID = 0; -> Result = All Record getDataViewHoaDon(String MaHD,String TenKH,String TenSP)
                    String    idCTHD = context.Request.Form["idCTHD"].ToString();
                    DataTable dt     = Servies.HoaDonServices.getLv3HD(idCTHD);
                    context.Response.ContentType = "application/json";
                    context.Response.Write(JsonConvert.SerializeObject(dt));
                    //log.Info(maxId);
                }
                catch (Exception e)
                {
                    //log.Error("Error function getMaxIdHoaDon ",e);
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("Error");
                }
            }
            else if (type == "insertNgayDonHang")
            {
                try
                {
                    // Case ID > 0 -> Result = 1 record
                    // Case ID = 0; -> Result = All Record getDataViewHoaDon(String MaHD,String TenKH,String TenSP)
                    String idGoi    = context.Request.Form["idGoi"].ToString();
                    String ngayDH   = context.Request.Form["ngayDH"].ToString();
                    int    idNgayHD = InsertNgayHoaDonStep2ReturnId(Convert.ToInt32(idGoi), ngayDH);
                    Servies.HoaDonServices.insertKhachHangNgayByGoiHD(Convert.ToInt32(idGoi), idNgayHD);
                    dynamic data = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonData);
                    for (var i = 0; i < data.Count; i++)
                    {
                        InsertHoaDonSanPhamReturnId(data[i], idNgayHD);
                    }
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("1");
                    //log.Info(maxId);
                }
                catch (Exception e)
                {
                    //log.Error("Error function getMaxIdHoaDon ",e);
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("Error");
                }
            }
            else if (type == "loadInfoKHByHD")
            {
                try
                {
                    // Case ID > 0 -> Result = 1 record
                    // Case ID = 0; -> Result = All Record getDataViewHoaDon(String MaHD,String TenKH,String TenSP)
                    String    idHD = context.Request.Form["idHD"].ToString();
                    DataTable dt   = Servies.HoaDonServices.loadInfoKHByHD(idHD);
                    context.Response.ContentType = "application/json";
                    context.Response.Write(JsonConvert.SerializeObject(dt));
                    //log.Info(maxId);
                }
                catch (Exception e)
                {
                    //log.Error("Error function getMaxIdHoaDon ",e);
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("Error");
                }
            }
            else if (type == "insertGoiStepv2")
            {
                try
                {
                    String hoten          = "";
                    String maKH           = "";
                    String ngaySinh       = "";
                    String soDienThoai    = "";
                    String email          = "";
                    String diaChi         = "";
                    String maquan         = "";
                    String tong           = "";
                    String IdChiTietHoaHD = "";

                    dynamic data         = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonData);
                    dynamic inFoCustomer = data.infoKH;
                    dynamic infoBill     = data.infoBill;
                    hoten          = (String)inFoCustomer.hoTen;
                    maKH           = (String)inFoCustomer.maKH;
                    ngaySinh       = (String)inFoCustomer.ngaySinh;
                    soDienThoai    = (String)inFoCustomer.soDienThoai;
                    email          = (String)inFoCustomer.email;
                    diaChi         = (String)inFoCustomer.diaChi;
                    maquan         = (String)inFoCustomer.maquan;
                    tong           = (String)data.fThanhTien;
                    IdChiTietHoaHD = (String)data.idCTHD;
                    dynamic dataHD = data.Data;

                    /*********************************
                    * Check and Insert Khách hàng nếu không tồn tại
                    * Nếu tồn tại getId Khách hàng
                    *
                    * *******************************/
                    int IdKhachHang = returnIdKH(soDienThoai, hoten, email, diaChi, maquan, ngaySinh);

                    /*********************************
                    * Insert Hóa đơn
                    *
                    * *******************************/

                    /*********************************
                    * Insert Chi tiết hóa đơn , hoa đơn package , hóa đơn ngày , sản phẩm
                    *
                    * *******************************/
                    int idPackageHD = InsertPackageChiTietHoaDonReturnId(data, Convert.ToInt32(IdChiTietHoaHD));
                    Servies.HoaDonServices.updateTienHD(IdChiTietHoaHD, idPackageHD);
                    if ((String)data.NgayHD != "")
                    {
                        int idNgayHDLe = InsertNgayHoaDonLeReturnId(data, idPackageHD, (String)data.NgayHD, (String)data.fLoaiThanhToanId);
                        InsertKhachHangNgay(idNgayHDLe, data);
                        for (int j = 0; j < dataHD.Count; j++)
                        {
                            InsertHoaDonSanPhamReturnId(dataHD[j], idNgayHDLe);
                        }
                    }
                    else
                    {
                        for (int j = 0; j < dataHD.Count; j++)
                        {
                            int idNgayHD = -1;
                            if (dataHD[j].deliveryDate != "")
                            {
                                idNgayHD = InsertNgayHoaDonReturnId(dataHD[j], idPackageHD, (String)data.fLoaiThanhToanId);
                                InsertKhachHangNgay(idNgayHD, data);
                            }
                            else
                            {
                                InsertHoaDonSanPhamReturnId(dataHD[j], idNgayHD);
                            }
                        }
                    }
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("1");
                }
                catch (Exception e)
                {
                    //log.Error("Error function getMaxIdHoaDon ",e);
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("Error");
                }
            }
            else if (type == "getMaxIdHoaDon")
            {
                try
                {
                    // Case ID > 0 -> Result = 1 record
                    // Case ID = 0; -> Result = All Record getDataViewHoaDon(String MaHD,String TenKH,String TenSP)

                    Int32 maxId = Servies.HoaDonServices.getMaxIdHoaDon();
                    context.Response.ContentType = "text/plain";
                    context.Response.Write(maxId);
                    //log.Info(maxId);
                }
                catch (Exception e)
                {
                    //log.Error("Error function getMaxIdHoaDon ",e);
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("Error");
                }
            }
            else if (type == "UpdateTrangThaiNgayHoaDon")
            {
                try
                {
                    // Case ID > 0 -> Result = 1 record
                    // Case ID = 0; -> Result = All Record getDataViewHoaDon(String MaHD,String TenKH,String TenSP)

                    String ID        = context.Request.Form["IdPCTHD"].ToString();
                    String IDHD      = context.Request.Form["idHD"].ToString();
                    String TrangThai = "Hủy Đơn";
                    Servies.HoaDonServices.UpdateTrangThaiNgayHoaDon(ID, TrangThai, IDHD);
                    context.Response.ContentType = "text/plain";
                    context.Response.Write(1);
                    //log.Info(maxId);
                }
                catch (Exception e)
                {
                    //log.Error("Error function getMaxIdHoaDon ",e);
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("Error");
                }
            }//UpdateTrangThaiNgayHoaDon
            else
            {
                context.Response.ContentType = "text/plain";
                context.Response.Write("Hello");
            }
        }
        public String insert(String type, String data)
        {
            try
            {
                String hoten         = "";
                String maKH          = "";
                String ngaySinh      = "";
                String soDienThoai   = "";
                String email         = "";
                String diaChi        = "";
                String maquan        = "";
                String sourceName    = "";
                String sourceId      = "";
                String songayconlai  = "";
                String tong          = "";
                String sotienthuduoc = "";
                String chietkhau     = "";
                String conNo         = "";

                dynamic dataDynamic  = Newtonsoft.Json.JsonConvert.DeserializeObject(data);
                dynamic inFoCustomer = dataDynamic.inFoCustomer;
                dynamic infoBill     = dataDynamic.infoBill;
                hoten         = inFoCustomer.hoTen;
                maKH          = inFoCustomer.maKH;
                ngaySinh      = inFoCustomer.ngaySinh;
                soDienThoai   = inFoCustomer.soDienThoai;
                email         = inFoCustomer.email;
                diaChi        = inFoCustomer.diaChi;
                maquan        = inFoCustomer.maquan;
                sourceName    = dataDynamic.sourceName;
                sourceId      = dataDynamic.sourceId;
                songayconlai  = dataDynamic.songayconlai;
                tong          = dataDynamic.tong;
                sotienthuduoc = dataDynamic.sotienthuduoc;
                chietkhau     = dataDynamic.chietkhau;
                conNo         = dataDynamic.conNo;

                /*********************************
                * Check and Insert Khách hàng nếu không tồn tại
                * Nếu tồn tại getId Khách hàng
                *
                * *******************************/
                int IdKhachHang = returnIdKH(soDienThoai, hoten, email, diaChi, maquan, ngaySinh);

                /*********************************
                * Insert Hóa đơn
                *
                * *******************************/
                DataObject.HoaDon hoadon = new DataObject.HoaDon();
                hoadon.IDKhachHang     = IdKhachHang;
                hoadon.IDNguon         = Convert.ToInt32(sourceId);
                hoadon.NgayTao         = DateTime.Now;
                hoadon.NguoiTao        = "";
                hoadon.TongSoNgay      = Convert.ToInt32(songayconlai);
                hoadon.TongTien        = Convert.ToDecimal(tong != "" ? tong : "0");
                hoadon.TongTienConNo   = Convert.ToDecimal(conNo != "" ? conNo : "0");
                hoadon.TongTienThuDuoc = Convert.ToDecimal(sotienthuduoc != "" ? sotienthuduoc : "0");
                hoadon.TrangThai       = "Chưa xử lý";
                hoadon.ChietKhau       = Convert.ToDecimal(sotienthuduoc != "" ? chietkhau : "0");
                int hoadonId = Servies.HoaDonServices.InsertDataReturnId(hoadon);

                /*********************************
                * Insert Chi tiết hóa đơn , hoa đơn package , hóa đơn ngày , sản phẩm
                *
                * *******************************/
                for (int i = 0; i < infoBill.Count; i++)
                {
                    int     IdChiTietHoaHD = InsertChiTietHoaDonReturnId(infoBill[i], hoadonId, IdKhachHang);
                    dynamic dataHD         = infoBill[i].data;
                    for (int k = 0; k < dataHD.Count; k++)
                    {
                        int idPackageHD = InsertPackageChiTietHoaDonReturnId(dataHD[k], IdChiTietHoaHD);

                        dynamic detailMaster = dataHD[k].detalMaster;
                        int     idNgayHDLe   = -1;
                        for (int j = 0; j < detailMaster.Count; j++)
                        {
                            if (dataHD[k].fLoaiHinhDonId == 1)
                            {
                                int idNgayHD = 0;
                                if (detailMaster[j].deliveryDate != "")
                                {
                                    idNgayHD = InsertNgayHoaDonReturnId(detailMaster[j], idPackageHD);
                                }
                                else
                                {
                                    InsertHoaDonSanPhamReturnId(detailMaster[j], idNgayHD);
                                }
                            }
                            else
                            {
                                if (j == 0)
                                {
                                    idNgayHDLe = InsertNgayHoaDonReturnId(detailMaster[j], idPackageHD);
                                    InsertHoaDonSanPhamReturnId(detailMaster[j], idNgayHDLe);
                                }
                                else
                                {
                                    InsertHoaDonSanPhamReturnId(detailMaster[j], idNgayHDLe);
                                }
                            }
                        }
                    }
                }

                return(hoten);
            }
            catch (Exception e)
            {
                return("001");
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            String type     = context.Request.Form["type"].ToString();
            String jsonData = context.Request.Form["data"].ToString();

            //DataObject.viewBillTemp obj = new JavaScriptSerializer().Deserialize<DataObject.viewBillTemp>(jsonData);
            if (type == "insert")
            {
                try
                {
                    String hoten         = "";
                    String maKH          = "";
                    String ngaySinh      = "";
                    String soDienThoai   = "";
                    String email         = "";
                    String diaChi        = "";
                    String maquan        = "";
                    String sourceName    = "";
                    String sourceId      = "";
                    String songayconlai  = "";
                    String tong          = "";
                    String sotienthuduoc = "";
                    String chietkhau     = "";
                    String conNo         = "";

                    dynamic data         = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonData);
                    dynamic inFoCustomer = data.inFoCustomer;
                    dynamic infoBill     = data.infoBill;
                    hoten         = inFoCustomer.hoTen;
                    maKH          = inFoCustomer.maKH;
                    ngaySinh      = inFoCustomer.ngaySinh;
                    soDienThoai   = inFoCustomer.soDienThoai;
                    email         = inFoCustomer.email;
                    diaChi        = inFoCustomer.diaChi;
                    maquan        = inFoCustomer.maquan;
                    sourceName    = data.sourceName;
                    sourceId      = data.sourceId;
                    songayconlai  = data.songayconlai;
                    tong          = data.tong;
                    sotienthuduoc = data.sotienthuduoc;
                    chietkhau     = data.chietkhau;
                    conNo         = data.conNo;

                    /*********************************
                    * Check and Insert Khách hàng nếu không tồn tại
                    * Nếu tồn tại getId Khách hàng
                    *
                    * *******************************/
                    int IdKhachHang = returnIdKH(soDienThoai, hoten, email, diaChi, maquan, ngaySinh);

                    /*********************************
                    * Insert Hóa đơn
                    *
                    * *******************************/
                    DataObject.HoaDon hoadon = new DataObject.HoaDon();
                    hoadon.IDKhachHang     = IdKhachHang;
                    hoadon.IDNguon         = Convert.ToInt32(sourceId);
                    hoadon.NgayTao         = DateTime.Now;
                    hoadon.NguoiTao        = "";
                    hoadon.TongSoNgay      = Convert.ToInt32(songayconlai);
                    hoadon.TongTien        = Convert.ToDecimal(tong != "" ? tong : "0");
                    hoadon.TongTienConNo   = Convert.ToDecimal(conNo != "" ? conNo : "0");
                    hoadon.TongTienThuDuoc = Convert.ToDecimal(sotienthuduoc != "" ? sotienthuduoc : "0");
                    hoadon.TrangThai       = "Chưa xử lý";
                    hoadon.ChietKhau       = Convert.ToDecimal(sotienthuduoc != "" ? chietkhau : "0");
                    int hoadonId = Servies.HoaDonServices.InsertDataReturnId(hoadon);

                    /*********************************
                    * Insert Chi tiết hóa đơn , hoa đơn package , hóa đơn ngày , sản phẩm
                    *
                    * *******************************/
                    for (int i = 0; i < infoBill.Count; i++)
                    {
                        int     IdChiTietHoaHD = InsertChiTietHoaDonReturnId(infoBill[i], hoadonId, IdKhachHang);
                        dynamic dataHD         = infoBill[i].data;
                        for (int k = 0; k < dataHD.Count; k++)
                        {
                            int idPackageHD = InsertPackageChiTietHoaDonReturnId(dataHD[k], IdChiTietHoaHD);

                            dynamic detailMaster = dataHD[k].detalMaster;
                            int     idNgayHDLe   = -1;
                            for (int j = 0; j < detailMaster.Count; j++)
                            {
                                if (dataHD[k].fLoaiHinhDonId == 1)
                                {
                                    int idNgayHD = 0;
                                    if (detailMaster[j].deliveryDate != "")
                                    {
                                        idNgayHD = InsertNgayHoaDonReturnId(detailMaster[j], idPackageHD);
                                    }
                                    else
                                    {
                                        InsertHoaDonSanPhamReturnId(detailMaster[j], idNgayHD);
                                    }
                                }
                                else
                                {
                                    if (j == 0)
                                    {
                                        idNgayHDLe = InsertNgayHoaDonReturnId(detailMaster[j], idPackageHD);
                                        InsertHoaDonSanPhamReturnId(detailMaster[j], idNgayHDLe);
                                    }
                                    else
                                    {
                                        InsertHoaDonSanPhamReturnId(detailMaster[j], idNgayHDLe);
                                    }
                                }
                            }
                        }
                    }
                    context.Response.ContentType = "text/plain";
                    context.Response.Write(hoten);
                }
                catch (Exception e)
                {
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("001");
                }
            }
            else if (type == "update")
            {
                try
                {
                    //Update(obj);
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("insert data success");
                }
                catch (Exception e)
                {
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("Error");
                }
            }
            else if (type == "delete")
            {
                try
                {
                    //DeleteData(obj.ID);
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("insert data success");
                }
                catch (Exception e)
                {
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("Error");
                }
            }
            else if (type == "getDataFilter")
            {
                try
                {
                    // Case ID > 0 -> Result = 1 record
                    // Case ID = 0; -> Result = All Record getDataViewHoaDon(String MaHD,String TenKH,String TenSP)
                    String maReservation = context.Request.Form["MaReservation"].ToString();
                    String ngayHoaDon    = context.Request.Form["ngayHoaDon"].ToString();
                    String quan          = context.Request.Form["quan"].ToString();
                    String soShiper      = context.Request.Form["soShiper"].ToString();
                    String tenShiper     = context.Request.Form["tenShiper"].ToString();
                    String trangThai     = context.Request.Form["trangThai"].ToString();

                    DataTable lst = Servies.HoaDonServices.getDataFilterViewHoaDon(maReservation, ngayHoaDon, quan,
                                                                                   soShiper, tenShiper, trangThai);
                    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 == "getALLData")
            {
                try
                {
                    DataTable lst = Servies.HoaDonServices.getAllDataViewHoaDon();
                    context.Response.ContentType = "application/json";
                    context.Response.Write(JsonConvert.SerializeObject(lst));
                }
                catch (Exception e)
                {
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("Error");
                }
            }

            else
            {
                context.Response.ContentType = "text/plain";
                context.Response.Write("Hello");
            }
        }