Exemplo n.º 1
0
        private void THANHTOAN_HOADON_BANLE_TRALAI()
        {
            bool   success          = false;
            string TONGTIEN_BANGCHU = ConvertSoThanhChu.ChuyenDoiSoThanhChu(_NVGDQUAY_ASYNCCLIENT_DTO_GLOBAL.THANHTIEN);

            try
            {
                LUU_DULIEU(_NVGDQUAY_ASYNCCLIENT_DTO_GLOBAL);
            }
            catch
            {
                MessageBox.Show("CẢNH BÁO ! XẢY RA LỖI KHI LƯU HÓA ĐƠN NÀY, HÃY LƯU LẠI HÓA ĐƠN ĐỂ KIỂM TRA ! XIN CẢM ƠN ");
            }
            try
            {
                string MA_TEN_KHACHHANG = "";
                if (Config.CheckConnectToServer())
                {
                    MA_TEN_KHACHHANG = FrmThanhToanService.LAY_MA_TEN_KHACHHANG_FROM_ORACLE(_NVGDQUAY_ASYNCCLIENT_BILL_GLOBAL.MAKHACHHANG);
                }
                else
                {
                    MA_TEN_KHACHHANG = FrmThanhToanService.LAY_MA_TEN_KHACHHANG_FROM_SQLSERVER(_NVGDQUAY_ASYNCCLIENT_BILL_GLOBAL.MAKHACHHANG);
                }
                using (frmPrintBill_TraLai frmBanTraLai = new frmPrintBill_TraLai())
                {
                    try
                    {
                        BILL_DTO infoBill = new BILL_DTO()
                        {
                            ADDRESS      = Session.Session.CurrentAddress,
                            CONLAI       = _NVGDQUAY_ASYNCCLIENT_BILL_GLOBAL.TIEN_TRALAI_KHACH,
                            PHONE        = Session.Session.CurrentPhone,
                            MAKH         = MA_TEN_KHACHHANG,
                            DIEM         = _NVGDQUAY_ASYNCCLIENT_BILL_GLOBAL.SODIEM,
                            INFOTHUNGAN  = "THU NGÂN: " + Session.Session.CurrentTenNhanVien,
                            MA_GIAODICH  = _NVGDQUAY_ASYNCCLIENT_BILL_GLOBAL.MA_GIAODICH,
                            THANHTIENCHU = TONGTIEN_BANGCHU,
                            TIENKHACHTRA = _NVGDQUAY_ASYNCCLIENT_BILL_GLOBAL.TIENKHACH_TRA,
                            TENCUAHANG   = Session.Session.CurrentNameStore
                        };
                        frmBanTraLai.PrintInvoice_BanLeTraLai(infoBill, _NVGDQUAY_ASYNCCLIENT_BILL_GLOBAL);
                    }
                    catch
                    {
                    }
                    finally
                    {
                        this.handler(true);
                        this.Dispose();
                        frmBanTraLai.Dispose();
                        frmBanTraLai.Refresh();
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLogs.LogError(ex);
            }
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> Delete(string id)
        {
            NvVatTuChungTu instance = await _service.Repository.FindAsync(id);

            List <NvVatTuChungTuChiTiet> chitietinstance = _service.UnitOfWork.Repository <NvVatTuChungTuChiTiet>().DbSet.Where(o => o.MaChungTuPk == instance.MaChungTuPk).ToList();

            if (instance == null)
            {
                return(NotFound());
            }
            try
            {
                if (_service.DeletePhieu(id))
                {
                    _service.Delete(instance.Id);
                    _service.UnitOfWork.Save();
                    return(Ok(instance));
                }
                return(InternalServerError());
            }
            catch (Exception e)
            {
                WriteLogs.LogError(e);
                return(InternalServerError());
            }
        }
Exemplo n.º 3
0
        private void LUU_DULIEU(NVGDQUAY_ASYNCCLIENT_DTO _NVGDQUAY_ASYNCCLIENT_DTO)
        {
            try
            {
                int    countSave = 0;
                string msg       = Config.CheckConnectToServer(out bool result);
                if (msg.Length > 0)
                {
                    MessageBox.Show(msg); return;
                }

                if (result)
                {
                    countSave = SAVE_DATA_TO_ORACLE(_NVGDQUAY_ASYNCCLIENT_DTO);
                }
                else
                {
                    countSave = SAVE_DATA_TO_SQL(_NVGDQUAY_ASYNCCLIENT_DTO);
                }
                if (countSave >= 2)
                {
                    NotificationLauncher.ShowNotification("Thông báo", "Hoàn thành giao dịch", 1, "0x1", "0x8", "normal");
                }
            }
            catch (Exception ex)
            {
                WriteLogs.LogError(ex);
            }
        }
Exemplo n.º 4
0
        public async Task <IHttpActionResult> Put(string id, NvCongNoVm.Dto instance)
        {
            TransferObj <NvCongNo> result = new TransferObj <NvCongNo>();
            NvCongNo check = _service.FindById(instance.Id);

            if (id != instance.Id || check.TrangThai == (int)ApprovalState.IsComplete)
            {
                result.Status  = false;
                result.Message = "Dữ liệu không đúng!";
                return(Ok(result));
            }
            try
            {
                NvCongNo item = _service.UpdatePhieu(instance);
                await _service.UnitOfWork.SaveAsync();

                result.Status  = true;
                result.Message = "Update thành công!";
                result.Data    = item;
            }
            catch (Exception e)
            {
                WriteLogs.LogError(e);
                result.Status  = false;
                result.Message = e.Message.ToString();
            }
            return(Ok(result));
        }
Exemplo n.º 5
0
        public async Task <IHttpActionResult> PostQuery(JObject jsonData)
        {
            TransferObj <PagedObj <NvCongNoVm.Dto> > result = new TransferObj <PagedObj <NvCongNoVm.Dto> >();
            dynamic postData = ((dynamic)jsonData);
            FilterObj <NvCongNoVm.Search> filtered = ((JObject)postData.filtered).ToObject <FilterObj <NvCongNoVm.Search> >();
            PagedObj <NvCongNo>           paged    = ((JObject)postData.paged).ToObject <PagedObj <NvCongNo> >();
            string       unitCode = _service.GetCurrentUnitCode();
            QueryBuilder query    = new QueryBuilder
            {
                Take   = paged.ItemsPerPage,
                Skip   = paged.FromItem - 1,
                Filter = new QueryFilterLinQ()
                {
                    SubFilters = new List <IQueryFilter>()
                    {
                        new QueryFilterLinQ()
                        {
                            Property = ClassHelper.GetProperty(() => new NvCongNo().LoaiChungTu),
                            Method   = FilterMethod.EqualTo,
                            Value    = filtered.AdvanceData.LoaiChungTu
                        },
                        new QueryFilterLinQ()
                        {
                            Property = ClassHelper.GetProperty(() => new NvCongNo().UnitCode),
                            Method   = FilterMethod.EqualTo,
                            Value    = unitCode
                        }
                    },
                    Method = FilterMethod.And
                },
                Orders = new List <IQueryOrder>()
                {
                    new QueryOrder()
                    {
                        Field  = ClassHelper.GetPropertyName(() => new NvCongNo().ICreateDate),
                        Method = OrderMethod.DESC
                    }
                }
            };

            try
            {
                ResultObj <PagedObj <NvCongNo> > filterResult = _service.Filter(filtered, query);
                if (!filterResult.WasSuccessful)
                {
                    return(NotFound());
                }
                result.Data   = Mapper.Map <PagedObj <NvCongNo>, PagedObj <NvCongNoVm.Dto> >(filterResult.Value);
                result.Status = true;
                return(Ok(result));
            }
            catch (Exception e)
            {
                WriteLogs.LogError(e);
                result.Status  = false;
                result.Message = e.Message.ToString();
                return(Ok(result));
            }
        }
Exemplo n.º 6
0
        public static List <GIAODICH_DTO> TIMKIEM_GIAODICHQUAY(string KeySearch, DateTime TuNgay, DateTime DenNgay, int DieuKienLoc)
        {
            List <GIAODICH_DTO> listReturn = new List <GIAODICH_DTO>();

            try
            {
                using (var connection = new OracleConnection(ConfigurationManager.ConnectionStrings["ERBusConnection"].ConnectionString))
                {
                    connection.OpenAsync();
                    OracleCommand cmd = new OracleCommand();
                    cmd.Connection           = connection;
                    cmd.InitialLONGFetchSize = 1000;
                    cmd.CommandText          = "TIMKIEM_GIAODICHQUAY";
                    cmd.CommandType          = CommandType.StoredProcedure;
                    cmd.Parameters.Add("P_KEYSEARCH", OracleDbType.Varchar2).Value        = KeySearch;
                    cmd.Parameters.Add("P_TUNGAY", OracleDbType.Date).Value               = TuNgay;
                    cmd.Parameters.Add("P_DENNGAY", OracleDbType.Date).Value              = DenNgay;
                    cmd.Parameters.Add("P_DIEUKIENLOC", OracleDbType.Int32).Value         = DieuKienLoc;
                    cmd.Parameters.Add("P_UNITCODE", OracleDbType.Varchar2).Value         = Session.Session.CurrentUnitCode;
                    cmd.Parameters.Add("CURSOR_RESULT", OracleDbType.RefCursor).Direction = ParameterDirection.Output;
                    OracleDataReader dataReader = null;
                    dataReader = cmd.ExecuteReader();
                    if (dataReader.HasRows)
                    {
                        while (dataReader.Read())
                        {
                            GIAODICH_DTO GDQUAY_DTO = new GIAODICH_DTO();
                            decimal      TIENKHACH_TRA, TIENTHE, TIEN_TRALAI_KHACH, THANHTIEN = 0;
                            GDQUAY_DTO.MA_GIAODICH   = dataReader["MA_GIAODICH"].ToString();
                            GDQUAY_DTO.LOAI_GIAODICH = dataReader["LOAI_GIAODICH"].ToString();
                            GDQUAY_DTO.I_CREATE_DATE = DateTime.Parse(dataReader["I_CREATE_DATE"].ToString());
                            GDQUAY_DTO.I_CREATE_BY   = dataReader["I_CREATE_BY"].ToString();
                            GDQUAY_DTO.NGAY_GIAODICH = DateTime.Parse(dataReader["NGAY_GIAODICH"].ToString());
                            GDQUAY_DTO.MA_VOUCHER    = dataReader["MA_VOUCHER"].ToString();
                            decimal.TryParse(dataReader["TIENKHACH_TRA"].ToString(), out TIENKHACH_TRA);
                            GDQUAY_DTO.TIENKHACH_TRA = TIENKHACH_TRA;
                            decimal.TryParse(dataReader["TIENTHE"].ToString(), out TIENTHE);
                            GDQUAY_DTO.TIENTHE = TIENTHE;
                            decimal.TryParse(dataReader["TIEN_TRALAI_KHACH"].ToString(), out TIEN_TRALAI_KHACH);
                            GDQUAY_DTO.TIEN_TRALAI_KHACH = TIEN_TRALAI_KHACH;
                            decimal.TryParse(dataReader["TIENTHE"].ToString(), out TIENTHE);
                            GDQUAY_DTO.TIENTHE = TIENTHE;
                            decimal.TryParse(dataReader["THANHTIEN"].ToString(), out THANHTIEN);
                            GDQUAY_DTO.THANHTIEN    = THANHTIEN;
                            GDQUAY_DTO.THOIGIAN_TAO = dataReader["THOIGIAN_TAO"].ToString();
                            GDQUAY_DTO.MAKHACHHANG  = dataReader["MAKHACHHANG"].ToString();
                            GDQUAY_DTO.UNITCODE     = dataReader["UNITCODE"].ToString();
                            listReturn.Add(GDQUAY_DTO);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLogs.LogError(ex);
                NotificationLauncher.ShowNotification("Thông báo", "Xảy ra lỗi", 1, "0x1", "0x8", "normal");
            }
            return(listReturn);
        }
Exemplo n.º 7
0
        public async Task <IHttpActionResult> PostQuery(JObject jsonData)
        {
            var result   = new TransferObj <PagedObj <NvPhieuDatHangNCCVm.Dto> >();
            var postData = ((dynamic)jsonData);
            var filtered = ((JObject)postData.filtered).ToObject <FilterObj <NvPhieuDatHangNCCVm.Search> >();

            filtered.OrderType = "DESC";
            filtered.OrderBy   = "Ngay";
            var paged    = ((JObject)postData.paged).ToObject <PagedObj <NvDatHang> >();
            var unitCode = _service.GetCurrentUnitCode();
            var query    = new QueryBuilder
            {
                Take   = paged.ItemsPerPage,
                Skip   = paged.FromItem - 1,
                Filter = new QueryFilterLinQ()
                {
                    SubFilters = new List <IQueryFilter>()
                    {
                        new QueryFilterLinQ()
                        {
                            Property = ClassHelper.GetProperty(() => new NvDatHang().Loai),
                            Method   = FilterMethod.EqualTo,
                            Value    = (int)LoaiDatHang.NHACUNGCAP
                        },
                        new QueryFilterLinQ()
                        {
                            Property = ClassHelper.GetProperty(() => new NvVatTuChungTu().UnitCode),
                            Method   = FilterMethod.EqualTo,
                            Value    = unitCode
                        },
                        new QueryFilterLinQ()
                        {
                            Property = ClassHelper.GetProperty(() => new NvDatHang().SoPhieuCon),
                            Method   = FilterMethod.Null,
                        }
                    },
                    Method = FilterMethod.And
                },
            };

            try
            {
                var filterResult = _service.Filter(filtered, query);
                if (!filterResult.WasSuccessful)
                {
                    return(NotFound());
                }

                result.Data   = Mapper.Map <PagedObj <NvDatHang>, PagedObj <NvPhieuDatHangNCCVm.Dto> >(filterResult.Value);
                result.Status = true;
                return(Ok(result));
            }
            catch (Exception e)
            {
                WriteLogs.LogError(e);
                return(InternalServerError());
            }
        }
Exemplo n.º 8
0
        protected void Application_Error(Object sender, EventArgs e)
        {
            Exception ex = Server.GetLastError();

            if (ex is ThreadAbortException)
            {
                return;
            }
            WriteLogs.LogError(ex);
        }
Exemplo n.º 9
0
        public static string LAY_MA_TEN_KHACHHANG_FROM_SQLSERVER(string MAKHACHHANG)
        {
            string RESULT = "";

            try
            {
                using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["TBNETERP_CLIENT"].ConnectionString))
                {
                    try
                    {
                        connection.Open();
                        if (connection.State == ConnectionState.Open)
                        {
                            SqlCommand cmd = new SqlCommand();
                            cmd.Connection  = connection;
                            cmd.CommandText = "SELECT CONCAT (DM_KHACHHANG.MAKH,' - ',DM_KHACHHANG.TENKH) AS KHACHHANG FROM dbo.DM_KHACHHANG WHERE DM_KHACHHANG.MAKH = '" + MAKHACHHANG + "'";
                            cmd.CommandType = CommandType.Text;
                            SqlDataReader dataReader = cmd.ExecuteReader();
                            if (dataReader.HasRows)
                            {
                                while (dataReader.Read())
                                {
                                    if (dataReader["KHACHHANG"] != null)
                                    {
                                        RESULT = dataReader["KHACHHANG"].ToString();
                                    }
                                    else
                                    {
                                        RESULT = "";
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                        NotificationLauncher.ShowNotificationWarning("THÔNG BÁO", "KHÔNG TÌM THẤY THÔNG TIN KHÁCH HÀNG", 1, "0x1", "0x8", "normal");
                    }
                    finally
                    {
                        connection.Close();
                        connection.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLogs.LogError(ex);
                NotificationLauncher.ShowNotificationError("Thông báo", "Xảy ra lỗi", 1, "0x1", "0x8", "normal");
            }
            return(RESULT);
        }
Exemplo n.º 10
0
        public static string LAY_MA_TEN_KHACHHANG_FROM_ORACLE(string MAKHACHHANG)
        {
            string RESULT = "";

            try
            {
                using (OracleConnection connection = new OracleConnection(ConfigurationManager.ConnectionStrings["ERBusConnection"].ConnectionString))
                {
                    try
                    {
                        connection.Open();
                        if (connection.State == ConnectionState.Open)
                        {
                            OracleCommand cmd = new OracleCommand();
                            cmd.Connection  = connection;
                            cmd.CommandText = "SELECT MAKHACHHANG || ' - ' || TENKHACHHANG AS KHACHHANG FROM KHACHHANG WHERE MAKHACHHANG = '" + MAKHACHHANG + "'";
                            cmd.CommandType = CommandType.Text;
                            OracleDataReader dataReader = cmd.ExecuteReader();
                            if (dataReader.HasRows)
                            {
                                while (dataReader.Read())
                                {
                                    if (dataReader["KHACHHANG"] != null)
                                    {
                                        RESULT = dataReader["KHACHHANG"].ToString();
                                    }
                                    else
                                    {
                                        RESULT = "";
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                        NotificationLauncher.ShowNotificationWarning("THÔNG BÁO", "KHÔNG TÌM THẤY THÔNG TIN KHÁCH HÀNG", 1, "0x1", "0x8", "normal");
                    }
                    finally
                    {
                        connection.Close();
                        connection.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLogs.LogError(ex);
                NotificationLauncher.ShowNotificationError("Thông báo", "Xảy ra lỗi", 1, "0x1", "0x8", "normal");
            }
            return(RESULT);
        }
Exemplo n.º 11
0
        public async Task <IHttpActionResult> GetCountExportTransactionNotApproved()
        {
            var result = new TransferObj <decimal>();

            try
            {
                var data = _service.GetCountExportTransactionNotApproved();
                result.Data   = data;
                result.Status = true;
            }
            catch (Exception e)
            {
                WriteLogs.LogError(e);
                result.Message = e.Message.ToString();
                result.Status  = false;
            }
            return(Ok(result));
        }
Exemplo n.º 12
0
        public async Task <IHttpActionResult> PostKiemTraTonHang(DashboardVm.Parameter code)
        {
            var result = new TransferObj <List <DashboardVm.InventoryMerchandise> >();

            try
            {
                var data = _service.GetTonMatHang(code.MaVatTu);
                result.Data   = data;
                result.Status = true;
            }
            catch (Exception e)
            {
                WriteLogs.LogError(e);
                result.Message = e.Message.ToString();
                result.Status  = false;
            }
            return(Ok(result));
        }
Exemplo n.º 13
0
        public async Task <IHttpActionResult> GetRetailRevenue()
        {
            var result = new TransferObj <List <RetailRevenue> >();

            try
            {
                var data = _service.GetRevenue();
                result.Data   = data;
                result.Status = true;
            }
            catch (Exception e)
            {
                WriteLogs.LogError(e);
                result.Message = e.Message.ToString();
                result.Status  = false;
            }
            return(Ok(result));
        }
Exemplo n.º 14
0
        public async Task <IHttpActionResult> GetBestOfFiveMerchandiseSelled()
        {
            var result = new TransferObj <List <DashboardVm.BestMerchandise> >();

            try
            {
                var data = _service.GetBestOfFiveMerchandiseSelled();
                result.Data   = data;
                result.Status = true;
            }
            catch (Exception e)
            {
                WriteLogs.LogError(e);
                result.Message = e.Message.ToString();
                result.Status  = false;
            }
            return(Ok(result));
        }
Exemplo n.º 15
0
        public async Task <IHttpActionResult> GetAmmountSupplierLend(string code)
        {
            if (string.IsNullOrEmpty(code))
            {
                return(BadRequest());
            }
            var result = new TransferObj <NvCongNoVm.Dto>();

            try
            {
                var data = _service.GetAmmountSupplierLend(code);
                result.Data   = data;
                result.Status = true;
            }
            catch (Exception e)
            {
                WriteLogs.LogError(e);
                result.Message = e.Message.ToString();
                result.Status  = false;
            }
            return(Ok(result));
        }
Exemplo n.º 16
0
        public IHttpActionResult GetMenu(string username)
        {
            var result = new TransferObj <List <ChoiceObj> >();

            try
            {
                var            _unitCode = _service.GetCurrentUnitCode();
                List <AU_MENU> lstMenu   = new List <AU_MENU>();
                if (username.Equals("admin"))
                {
                    lstMenu = _service.Repository.DbSet.Where(x => x.TrangThai == 10 && x.UnitCode == _unitCode).OrderBy(x => x.Sort).ToList();
                }
                else
                {
                    lstMenu = _service.GetAllForStarting(username, _unitCode);
                }
                result.Data = new List <ChoiceObj>();
                if (lstMenu != null)
                {
                    lstMenu.ForEach(x =>
                    {
                        ChoiceObj obj = new ChoiceObj()
                        {
                            Id     = x.Id,
                            Text   = x.Title,
                            Parent = x.MenuIdCha,
                            Value  = x.MenuId,
                        };
                        result.Data.Add(obj);
                    });
                }
            }
            catch (Exception ex)
            {
                WriteLogs.LogError(ex);
            }
            return(Ok(result));
        }
Exemplo n.º 17
0
        public async Task <IHttpActionResult> Post(NvCongNoVm.Dto instance)
        {
            TransferObj <NvCongNo> result = new TransferObj <NvCongNo>();

            try
            {
                NvCongNo item = _service.InsertPhieu(instance);
                await _service.UnitOfWork.SaveAsync();

                result.Data    = item;
                result.Message = "Thêm mới thành công";
                result.Status  = true;
                return(CreatedAtRoute("DefaultApi", new { controller = this, id = instance.Id }, result));
            }
            catch (Exception e)
            {
                WriteLogs.LogError(e);
                result.Message = e.Message.ToString();
                result.Status  = false;
            }

            return(Ok(result));
        }
Exemplo n.º 18
0
 private void LUU_DULIEU(GIAODICH_DTO _NVGDQUAY_ASYNCCLIENT_DTO)
 {
     try
     {
         int countSave = 0;
         if (Config.CheckConnectToServer())
         {
             countSave = SAVE_DATA_TO_ORACLE(_NVGDQUAY_ASYNCCLIENT_DTO);
         }
         else
         {
             countSave = SAVE_DATA_TO_SQL(_NVGDQUAY_ASYNCCLIENT_DTO);
         }
         if (countSave >= 2)
         {
             NotificationLauncher.ShowNotification("Thông báo", "Hoàn thành giao dịch", 1, "0x1", "0x8", "normal");
         }
     }
     catch (Exception ex)
     {
         WriteLogs.LogError(ex);
     }
 }
Exemplo n.º 19
0
        public async Task <IHttpActionResult> Delete(string id)
        {
            NvDatHang instance = await _service.Repository.FindAsync(id);

            if (instance == null)
            {
                return(NotFound());
            }
            try
            {
                if (_service.DeletePhieu(id))
                {
                    _service.Delete(instance.Id);
                    _service.UnitOfWork.Save();
                    return(Ok(instance));
                }
                return(InternalServerError());
            }
            catch (Exception e)
            {
                WriteLogs.LogError(e);
                return(InternalServerError());
            }
        }
Exemplo n.º 20
0
 private void INSERT_DATA_HANG_GIAODICHQUAY_SQL(NVGDQUAY_ASYNCCLIENT_DTO _NVGDQUAY_ASYNCCLIENT_DTO, ref int countCheckInsertSuccess)
 {
     if (_NVGDQUAY_ASYNCCLIENT_DTO.LST_DETAILS.Count > 0)
     {
         using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["TBNETERP_CLIENT"].ConnectionString))
         {
             connection.Open();
             if (connection.State == ConnectionState.Open)
             {
                 try
                 {
                     foreach (NVHANGGDQUAY_ASYNCCLIENT ITEM in _NVGDQUAY_ASYNCCLIENT_DTO.LST_DETAILS)
                     {
                         SqlCommand command = new SqlCommand();
                         command.Connection = connection;
                         string queryInsertItem = string.Format(@"INSERT INTO [dbo].[NVHANGGDQUAY_ASYNCCLIENT]([ID],[MAGDQUAYPK],[MAKHOHANG],[MADONVI],[MAVATTU],[MANGUOITAO],[NGUOITAO],[MABOPK],[NGAYTAO],[NGAYPHATSINH],[SOLUONG],[TTIENCOVAT],[GIABANLECOVAT],[TYLECHIETKHAU],[TIENCHIETKHAU],[TYLEKHUYENMAI],[TIENKHUYENMAI],[TYLEVOUCHER],[TIENVOUCHER],[TYLELAILE],[GIAVON],[MAVAT],[VATBAN],[MACHUONGTRINHKM],[UNITCODE]) 
                             VALUES (@ID,@MAGDQUAYPK,@MAKHOHANG,@MADONVI,@MAVATTU,@MANGUOITAO,@NGUOITAO,@MABOPK,@NGAYTAO,@NGAYPHATSINH,@SOLUONG,@TTIENCOVAT,@GIABANLECOVAT,@TYLECHIETKHAU,@TIENCHIETKHAU,@TYLEKHUYENMAI,@TIENKHUYENMAI,@TYLEVOUCHER,@TIENVOUCHER,@TYLELAILE,@GIAVON,@MAVAT,@VATBAN,@MACHUONGTRINHKM,@UNITCODE)");
                         command.CommandText = queryInsertItem;
                         command.CommandType = CommandType.Text;
                         command.Parameters.Add("ID", SqlDbType.NVarChar, 50).Value              = ITEM.ID;
                         command.Parameters.Add("MAGDQUAYPK", SqlDbType.NVarChar, 50).Value      = ITEM.MAGDQUAYPK;
                         command.Parameters.Add("MAKHOHANG", SqlDbType.NVarChar, 50).Value       = ITEM.MAKHOHANG;
                         command.Parameters.Add("MADONVI", SqlDbType.NVarChar, 50).Value         = ITEM.MADONVI;
                         command.Parameters.Add("MAVATTU", SqlDbType.NVarChar, 50).Value         = ITEM.MAVATTU;
                         command.Parameters.Add("MANGUOITAO", SqlDbType.NVarChar, 50).Value      = Session.Session.CurrentMaNhanVien;
                         command.Parameters.Add("NGUOITAO", SqlDbType.NVarChar, 50).Value        = ITEM.NGUOITAO;
                         command.Parameters.Add("MABOPK", SqlDbType.NVarChar, 50).Value          = ITEM.MABOPK;
                         command.Parameters.Add("NGAYTAO", SqlDbType.Date).Value                 = ITEM.NGAYTAO;
                         command.Parameters.Add("NGAYPHATSINH", SqlDbType.Date).Value            = ITEM.NGAYPHATSINH;
                         command.Parameters.Add("SOLUONG", SqlDbType.Decimal).Value              = ITEM.SOLUONG;
                         command.Parameters.Add("TTIENCOVAT", SqlDbType.Decimal).Value           = ITEM.TTIENCOVAT;
                         command.Parameters.Add("GIABANLECOVAT", SqlDbType.Decimal).Value        = ITEM.GIABANLECOVAT;
                         command.Parameters.Add("TIENCHIETKHAU", SqlDbType.Decimal).Value        = ITEM.TIENCHIETKHAU;
                         command.Parameters.Add("TYLECHIETKHAU", SqlDbType.Decimal).Value        = ITEM.TYLECHIETKHAU;
                         command.Parameters.Add("TYLEKHUYENMAI", SqlDbType.Decimal).Value        = ITEM.TYLEKHUYENMAI;
                         command.Parameters.Add("TIENKHUYENMAI", SqlDbType.Decimal).Value        = ITEM.TIENKHUYENMAI;
                         command.Parameters.Add("TYLEVOUCHER", SqlDbType.Decimal).Value          = ITEM.TYLEVOUCHER;
                         command.Parameters.Add("TIENVOUCHER", SqlDbType.Decimal).Value          = ITEM.TIENVOUCHER;
                         command.Parameters.Add("TYLELAILE", SqlDbType.Decimal).Value            = ITEM.TYLELAILE;
                         command.Parameters.Add("GIAVON", SqlDbType.Decimal).Value               = ITEM.GIAVON;
                         command.Parameters.Add("MAVAT", SqlDbType.NVarChar, 50).Value           = ITEM.MAVAT;
                         command.Parameters.Add("VATBAN", SqlDbType.Decimal).Value               = ITEM.VATBAN;
                         command.Parameters.Add("MACHUONGTRINHKM", SqlDbType.NVarChar, 50).Value = ITEM.MACHUONGTRINHKM;
                         command.Parameters.Add("UNITCODE", SqlDbType.NVarChar, 50).Value        = ITEM.UNITCODE != null ? ITEM.UNITCODE : Session.Session.CurrentUnitCode;
                         try
                         {
                             if (command.ExecuteNonQuery() > 0)
                             {
                                 countCheckInsertSuccess++;
                             }
                         }
                         catch (Exception e)
                         {
                             WriteLogs.LogError(e);
                         }
                     }
                 }
                 catch (Exception ex)
                 {
                     WriteLogs.LogError(ex);
                 }
                 finally
                 {
                     connection.Close();
                     connection.Dispose();
                 }
             }
             else
             {
                 NotificationLauncher.ShowNotificationError("Thông báo", "Không có kế nối với cơ sở dữ liệu", 1, "0x1", "0x8", "normal");
             }
         }
     }
 }
Exemplo n.º 21
0
        public async Task <IHttpActionResult> ReceiveDataKiemKe(string MaKho)
        {
            string UNITCODE_GLOBAL = "";

            NvKiemKeVm.Dto returnList = new NvKiemKeVm.Dto();
            if (!string.IsNullOrEmpty(MaKho))
            {
                UNITCODE_GLOBAL = MaKho.Substring(0, MaKho.LastIndexOf('-'));
                NvKiemKeVm.Dto lst     = new NvKiemKeVm.Dto();
                List <string>  vatTu   = new List <string>();
                string         path    = HttpContext.Current.Server.MapPath("/Upload/KiemKe/");
                HttpRequest    request = HttpContext.Current.Request;
                if (request.Files.Count > 0)
                {
                    try
                    {
                        HttpPostedFile file = request.Files[0];
                        file.SaveAs(path + file.FileName);
                        //kiem tra ton tai file
                        if (File.Exists(path + file.FileName))
                        {
                            if (file.FileName.Contains(".txt"))
                            {
                                //doc du lieu tu file text
                                string[] lines = File.ReadAllLines(path + file.FileName);
                                foreach (string line in lines)
                                {
                                    string[] data        = line.Split(',');
                                    string   MaVatTu     = data[0].ToString();
                                    string   SoTonKiemKe = data[1].ToString();
                                    vatTu.Add(MaVatTu);
                                }
                                string[] arrayVatTu = vatTu.ToArray();
                                string   paraVatTu  = String.Join(",", arrayVatTu);
                                lst.DataDetails = ProcedureCollection.GetInventoryForActionInventoryByOne(UNITCODE_GLOBAL, MaKho, paraVatTu);
                                foreach (var value in lst.DataDetails)
                                {
                                    foreach (string line in lines)
                                    {
                                        string[] data = line.Split(',');
                                        if (data[0].ToString() == value.MaVatTu)
                                        {
                                            decimal SoLuongKiemKe = 0;
                                            decimal.TryParse(data[1].ToString(), out SoLuongKiemKe);
                                            value.SoLuongKiemKe = SoLuongKiemKe;
                                            returnList.DataDetails.Add(value);
                                        }
                                    }
                                }
                                returnList.KhoKiemKe  = MaKho;
                                returnList.NgayKiemKe = DateTime.Now.Date;
                                returnList.NgayIn     = DateTime.Now.Date;
                                int    number = 0;
                                string maKe   = "";
                                if (lst.DataDetails.Count > 10)
                                {
                                    for (int i = 0; i < 10; i++)
                                    {
                                        if (lst.DataDetails[i].KeKiemKe == lst.DataDetails[i + 1].KeKiemKe)
                                        {
                                            number++;
                                            maKe = lst.DataDetails[i].KeKiemKe;
                                        }
                                    }
                                }
                                if (number > 5)
                                {
                                    returnList.KeKiemKe = maKe;
                                }
                                else
                                {
                                    returnList.KeKiemKe = lst.DataDetails[0].KeKiemKe;
                                }
                                returnList.MaPhieuKiemKe = _serviceKK.BuildCode();
                            }
                        }
                        else
                        {
                            return(NotFound());
                        }
                    }
                    catch (Exception ex)
                    {
                        WriteLogs.LogError(ex);
                        return(InternalServerError());
                    }
                }
                //lấy những mã không kiểm kê nhưng nằm trong kệ
                string maKeHangHoa = returnList.KeKiemKe;
                var    hangTrongKe = ProcedureCollection.LayThongTinHangThuocKe(UNITCODE_GLOBAL, returnList.KhoKiemKe, maKeHangHoa);
                try
                {
                    if (hangTrongKe != null && hangTrongKe.Count > 0)
                    {
                        for (int i = 0; i < hangTrongKe.Count; i++)
                        {
                            var data = returnList.DataDetails.Find(x => x.MaVatTu == hangTrongKe[i].MaVatTu);
                            if (data == null)
                            {
                                hangTrongKe[i].SoLuongKiemKe = 0;
                                returnList.DataDetails.Add(hangTrongKe[i]);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    WriteLogs.LogError(ex);
                }
            }
            else
            {
                return(NotFound());
            }
            return(Ok(returnList));
        }
Exemplo n.º 22
0
        private void THANHTOAN_HOADON_BANLE_TRALAI()
        {
            string TONGTIEN_BANGCHU = ConvertSoThanhChu.ChuyenDoiSoThanhChu(_NVGDQUAY_ASYNCCLIENT_DTO_GLOBAL.TTIENCOVAT);

            try
            {
                LUU_DULIEU(_NVGDQUAY_ASYNCCLIENT_DTO_GLOBAL);
            }
            catch
            {
                MessageBox.Show("CẢNH BÁO ! XẢY RA LỖI KHI LƯU HÓA ĐƠN NÀY, HÃY LƯU LẠI HÓA ĐƠN ĐỂ KIỂM TRA ! XIN CẢM ƠN ");
            }
            try
            {
                string MA_TEN_KHACHHANG = "";

                string msg = Config.CheckConnectToServer(out bool result);
                if (msg.Length > 0)
                {
                    MessageBox.Show(msg); return;
                }

                if (result)
                {
                    MA_TEN_KHACHHANG = FrmThanhToanService.LAY_MA_TEN_KHACHHANG_FROM_ORACLE(_NVGDQUAY_ASYNCCLIENT_BILL_GLOBAL.MAKHACHHANG);
                }
                else
                {
                    MA_TEN_KHACHHANG = FrmThanhToanService.LAY_MA_TEN_KHACHHANG_FROM_SQLSERVER(_NVGDQUAY_ASYNCCLIENT_BILL_GLOBAL.MAKHACHHANG);
                }

                using (frmPrintBill_TraLai frmBanTraLai = new frmPrintBill_TraLai())
                {
                    try
                    {
                        BILL_DTO infoBill = new BILL_DTO()
                        {
                            ADDRESS      = Session.Session.CurrentAddress,
                            CONLAI       = _NVGDQUAY_ASYNCCLIENT_BILL_GLOBAL.TIENTRALAI,
                            PHONE        = Session.Session.CurrentPhone,
                            MAKH         = MA_TEN_KHACHHANG,
                            DIEM         = 0,
                            INFOTHUNGAN  = "THU NGÂN: " + _NVGDQUAY_ASYNCCLIENT_BILL_GLOBAL.NGUOITAO + "\t QUẦY: " + _NVGDQUAY_ASYNCCLIENT_BILL_GLOBAL.MAQUAYBAN,
                            MAGIAODICH   = _NVGDQUAY_ASYNCCLIENT_BILL_GLOBAL.MAGIAODICH,
                            THANHTIENCHU = TONGTIEN_BANGCHU,
                            TIENKHACHTRA = _NVGDQUAY_ASYNCCLIENT_BILL_GLOBAL.TIENKHACHDUA,
                            QUAYHANG     = _NVGDQUAY_ASYNCCLIENT_BILL_GLOBAL.MAQUAYBAN,
                        };
                        frmBanTraLai.PrintInvoice_BanLeTraLai(infoBill, _NVGDQUAY_ASYNCCLIENT_BILL_GLOBAL);
                    }
                    catch
                    {
                    }
                    finally
                    {
                        this.handler(true);
                        this.Dispose();
                        frmBanTraLai.Dispose();
                        frmBanTraLai.Refresh();
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLogs.LogError(ex);
            }
        }
Exemplo n.º 23
0
 private void INSERT_DATA_HANG_GIAODICHQUAY(NVGDQUAY_ASYNCCLIENT_DTO _NVGDQUAY_ASYNCCLIENT_DTO, ref int countCheckInsertSuccess)
 {
     if (_NVGDQUAY_ASYNCCLIENT_DTO.LST_DETAILS.Count > 0)
     {
         using (OracleConnection connection = new OracleConnection(ConfigurationManager.ConnectionStrings["TBNETERP_SERVER"].ConnectionString))
         {
             connection.Open();
             if (connection.State == ConnectionState.Open)
             {
                 try
                 {
                     foreach (NVHANGGDQUAY_ASYNCCLIENT ITEM in _NVGDQUAY_ASYNCCLIENT_DTO.LST_DETAILS)
                     {
                         OracleCommand command = new OracleCommand();
                         command.Connection = connection;
                         string queryInsertItem = string.Format(@"INSERT INTO NVHANGGDQUAY_ASYNCCLIENT (ID,MAGDQUAYPK,MAKHOHANG,MADONVI,MAVATTU,BARCODE,TENDAYDU,NGUOITAO,MABOPK,NGAYTAO,NGAYPHATSINH,
                             SOLUONG,TTIENCOVAT,VATBAN,GIABANLECOVAT,MAKHACHHANG,MAKEHANG,MACHUONGTRINHKM,LOAIKHUYENMAI,TIENCHIETKHAU,TYLECHIETKHAU,TYLEKHUYENMAI,TIENKHUYENMAI,TYLEVOUCHER,
                             TIENVOUCHER,TYLELAILE,GIAVON,ISBANAM,MAVAT) VALUES (:ID,:MAGDQUAYPK,:MAKHOHANG,:MADONVI,:MAVATTU,:BARCODE,:TENDAYDU,:NGUOITAO,:MABOPK,:NGAYTAO,:NGAYPHATSINH,
                             :SOLUONG,:TTIENCOVAT,:VATBAN,:GIABANLECOVAT,:MAKHACHHANG,:MAKEHANG,:MACHUONGTRINHKM,:LOAIKHUYENMAI,:TIENCHIETKHAU,:TYLECHIETKHAU,:TYLEKHUYENMAI,:TIENKHUYENMAI,:TYLEVOUCHER,
                             :TIENVOUCHER,:TYLELAILE,:GIAVON,:ISBANAM,:MAVAT)");
                         command.CommandText = queryInsertItem;
                         command.CommandType = CommandType.Text;
                         command.Parameters.Add("ID", OracleDbType.NVarchar2, 50).Value              = ITEM.ID;
                         command.Parameters.Add("MAGDQUAYPK", OracleDbType.NVarchar2, 50).Value      = ITEM.MAGDQUAYPK;
                         command.Parameters.Add("MAKHOHANG", OracleDbType.NVarchar2, 50).Value       = ITEM.MAKHOHANG;
                         command.Parameters.Add("MADONVI", OracleDbType.NVarchar2, 50).Value         = ITEM.MADONVI;
                         command.Parameters.Add("MAVATTU", OracleDbType.NVarchar2, 50).Value         = ITEM.MAVATTU;
                         command.Parameters.Add("BARCODE", OracleDbType.NVarchar2, 2000).Value       = ITEM.BARCODE;
                         command.Parameters.Add("TENDAYDU", OracleDbType.NVarchar2, 300).Value       = ITEM.TENDAYDU;
                         command.Parameters.Add("NGUOITAO", OracleDbType.NVarchar2, 300).Value       = ITEM.NGUOITAO;
                         command.Parameters.Add("MABOPK", OracleDbType.NVarchar2, 50).Value          = ITEM.MABOPK;
                         command.Parameters.Add("NGAYTAO", OracleDbType.Date).Value                  = ITEM.NGAYTAO;
                         command.Parameters.Add("NGAYPHATSINH", OracleDbType.Date).Value             = ITEM.NGAYPHATSINH;
                         command.Parameters.Add("SOLUONG", OracleDbType.Int32).Value                 = ITEM.SOLUONG;
                         command.Parameters.Add("TTIENCOVAT", OracleDbType.Decimal).Value            = ITEM.TTIENCOVAT;
                         command.Parameters.Add("VATBAN", OracleDbType.Decimal).Value                = ITEM.VATBAN;
                         command.Parameters.Add("GIABANLECOVAT", OracleDbType.Decimal).Value         = ITEM.GIABANLECOVAT;
                         command.Parameters.Add("MAKHACHHANG", OracleDbType.NVarchar2, 50).Value     = ITEM.MAKHACHHANG;
                         command.Parameters.Add("MAKEHANG", OracleDbType.NVarchar2, 50).Value        = ITEM.MAKEHANG;
                         command.Parameters.Add("MACHUONGTRINHKM", OracleDbType.NVarchar2, 50).Value = ITEM.MACHUONGTRINHKM;
                         command.Parameters.Add("LOAIKHUYENMAI", OracleDbType.NVarchar2, 50).Value   = ITEM.LOAIKHUYENMAI;
                         command.Parameters.Add("TIENCHIETKHAU", OracleDbType.Decimal).Value         = ITEM.TIENCHIETKHAU;
                         command.Parameters.Add("TYLECHIETKHAU", OracleDbType.Decimal).Value         = ITEM.TYLECHIETKHAU;
                         command.Parameters.Add("TYLEKHUYENMAI", OracleDbType.Decimal).Value         = ITEM.TYLEKHUYENMAI;
                         command.Parameters.Add("TIENKHUYENMAI", OracleDbType.Decimal).Value         = ITEM.TIENKHUYENMAI;
                         command.Parameters.Add("TYLEVOUCHER", OracleDbType.Decimal).Value           = ITEM.TYLEVOUCHER;
                         command.Parameters.Add("TIENVOUCHER", OracleDbType.Decimal).Value           = ITEM.TIENVOUCHER;
                         command.Parameters.Add("TYLELAILE", OracleDbType.Decimal).Value             = ITEM.TYLELAILE;
                         command.Parameters.Add("GIAVON", OracleDbType.Decimal).Value                = ITEM.GIAVON;
                         command.Parameters.Add("ISBANAM", OracleDbType.Decimal).Value               = ITEM.ISBANAM;
                         command.Parameters.Add("MAVAT", OracleDbType.NVarchar2, 50).Value           = ITEM.MAVAT;
                         try
                         {
                             if (command.ExecuteNonQuery() > 0)
                             {
                                 countCheckInsertSuccess++;
                             }
                         }
                         catch (Exception e)
                         {
                             WriteLogs.LogError(e);
                         }
                     }
                 }
                 catch (Exception ex)
                 {
                     WriteLogs.LogError(ex);
                 }
                 finally
                 {
                     connection.Close();
                     connection.Dispose();
                 }
             }
             else
             {
                 NotificationLauncher.ShowNotificationError("THÔNG BÁO", "KHÔNG CÓ KẾT NỐI VỚI CƠ SỞ DỮ LIỆU ORACLE", 1, "0x1", "0x8", "normal");
             }
         }
     }
 }
Exemplo n.º 24
0
        public string SAVE_MAKHACHHANG_TO_ORACLE()
        {
            string RESULT = "";

            using (OracleConnection connection = new OracleConnection(ConfigurationManager.ConnectionStrings["TBNETERP_SERVER"].ConnectionString))
            {
                connection.Open();
                if (connection.State == ConnectionState.Open)
                {
                    try
                    {
                        int           CURRENT = 0;
                        OracleCommand command = new OracleCommand();
                        command.Connection = connection;
                        string querySelectItem = "SELECT \"TYPE\",CODE,\"CURRENT\" FROM MD_ID_BUILDER WHERE CODE = 'KH'";
                        command.CommandText = querySelectItem;
                        command.CommandType = CommandType.Text;
                        OracleDataReader dataReaderBuildCode = command.ExecuteReader();
                        if (dataReaderBuildCode.HasRows)
                        {
                            while (dataReaderBuildCode.Read())
                            {
                                MD_ID_BUILDER _MD_ID_BUILDER = new MD_ID_BUILDER();
                                _MD_ID_BUILDER.ID       = Guid.NewGuid().ToString();
                                _MD_ID_BUILDER.TYPE     = "KH";
                                _MD_ID_BUILDER.CODE     = "KH";
                                _MD_ID_BUILDER.CURRENT  = "0000";
                                _MD_ID_BUILDER.UNITCODE = Session.Session.CurrentUnitCode;
                                int CURRENT_NUMBER = 0;
                                int.TryParse(dataReaderBuildCode["CURRENT"].ToString(), out CURRENT_NUMBER);
                                string SO_MA = GENERATE_NUMBER(CURRENT_NUMBER.ToString());
                                _MD_ID_BUILDER.CURRENT = SO_MA;
                                OracleCommand commandUpdate = new OracleCommand();
                                commandUpdate.Connection = connection;
                                string queryUpdateItem = "UPDATE MD_ID_BUILDER SET \"CURRENT\" = '" + _MD_ID_BUILDER.CURRENT + "' WHERE \"TYPE\" = '" + _MD_ID_BUILDER.TYPE + "' AND \"CODE\" = '" + _MD_ID_BUILDER.CODE + "' ";
                                commandUpdate.CommandText = queryUpdateItem;
                                commandUpdate.CommandType = CommandType.Text;
                                commandUpdate.ExecuteNonQuery();
                                RESULT = string.Format("{0}{1}", _MD_ID_BUILDER.CODE, SO_MA);
                            }
                        }
                        else
                        {
                            MD_ID_BUILDER _MD_ID_BUILDER = new MD_ID_BUILDER();
                            _MD_ID_BUILDER.ID       = Guid.NewGuid().ToString();
                            _MD_ID_BUILDER.TYPE     = "KH";
                            _MD_ID_BUILDER.CODE     = "KH";
                            _MD_ID_BUILDER.CURRENT  = "0000";
                            _MD_ID_BUILDER.UNITCODE = Session.Session.CurrentUnitCode;
                            string SO_MA = GENERATE_NUMBER(_MD_ID_BUILDER.CURRENT);
                            _MD_ID_BUILDER.CURRENT = SO_MA;
                            OracleCommand commandInsert = new OracleCommand();
                            commandInsert.Connection = connection;
                            string queryInsertItem = "INSERT INTO MD_ID_BUILDER(ID,\"TYPE\",CODE,\"CURRENT\",\"UNITCODE\",NGAYTAO) VALUES ('" + _MD_ID_BUILDER.ID + "','" + _MD_ID_BUILDER.TYPE + "','" + _MD_ID_BUILDER.TYPE + "','" + _MD_ID_BUILDER.CURRENT + "','" + _MD_ID_BUILDER.UNITCODE + "','" + DateTime.Now + "')";
                            commandInsert.CommandText = queryInsertItem;
                            commandInsert.CommandType = CommandType.Text;
                            commandInsert.ExecuteNonQuery();
                        }
                    }
                    catch (Exception ex)
                    {
                        WriteLogs.LogError(ex);
                    }
                    finally
                    {
                        connection.Close();
                        connection.Dispose();
                    }
                }
                else
                {
                    NotificationLauncher.ShowNotificationError("THÔNG BÁO", "KHÔNG CÓ KẾT NỐI VỚI CƠ SỞ DỮ LIỆU ORACLE", 1, "0x1", "0x8", "normal");
                }
            }
            return(RESULT);
        }
Exemplo n.º 25
0
        public static void DongBoTatCaDuLieuBan()
        {
            int totalParent   = 0;
            int totalChildren = 0;

            try
            {
                SplashScreenManager.ShowForm(typeof(WaitForm1));
                using (OracleConnection connectionOracle = new OracleConnection(ConfigurationManager.ConnectionStrings["ERBusConnection"].ConnectionString))
                {
                    connectionOracle.Open();
                    if (connectionOracle.State == ConnectionState.Open)
                    {
                        try
                        {
                            using (SqlConnection connectionClient = new SqlConnection(ConfigurationManager.ConnectionStrings["ERBusCashier"].ConnectionString))
                            {
                                connectionClient.Open();
                                try
                                {
                                    if (connectionClient.State == ConnectionState.Open)
                                    {
                                        //bảng cha
                                        SqlCommand cmdSql = new SqlCommand();
                                        cmdSql.Connection  = connectionClient;
                                        cmdSql.CommandText = @"SELECT [ID],[MA_GIAODICH],[LOAI_GIAODICH],[NGAY_GIAODICH],[MAKHACHHANG],[THOIGIAN_TAO],[TIENKHACH_TRA],[TIEN_TRALAI_KHACH],[MAKHO_XUAT],[MA_VOUCHER],[DIENGIAI],[I_CREATE_DATE],[I_CREATE_BY],[I_UPDATE_DATE],[I_UPDATE_BY],[I_STATE],[UNITCODE]  FROM [ERBUS_CASHIER].[dbo].[GIAODICH]";
                                        cmdSql.CommandType = CommandType.Text;
                                        SqlDataReader dataReaderClient = cmdSql.ExecuteReader();
                                        if (dataReaderClient.HasRows)
                                        {
                                            while (dataReaderClient.Read())
                                            {
                                                OracleCommand cmdOracleSelect = new OracleCommand();
                                                cmdOracleSelect.Connection  = connectionOracle;
                                                cmdOracleSelect.CommandText = @"SELECT ID,MA_GIAODICH,UNITCODE FROM GIAODICH WHERE ID = :ID AND MA_GIAODICH = :MA_GIAODICH AND UNITCODE = '" + Session.Session.CurrentUnitCode + "'";
                                                cmdOracleSelect.CommandType = CommandType.Text;
                                                cmdOracleSelect.Parameters.Add("ID", OracleDbType.NVarchar2, 50).Value          = dataReaderClient["ID"].ToString();
                                                cmdOracleSelect.Parameters.Add("MA_GIAODICH", OracleDbType.NVarchar2, 70).Value = dataReaderClient["MA_GIAODICH"].ToString();
                                                OracleDataReader dataReaderOracle = cmdOracleSelect.ExecuteReader();
                                                if (!dataReaderOracle.HasRows)
                                                {
                                                    DateTime NGAY_GIAODICH;
                                                    DateTime I_CREATE_DATE     = DateTime.Now;
                                                    DateTime I_UPDATE_DATE     = DateTime.Now;
                                                    decimal  TIENKHACH_TRA     = 0;
                                                    decimal  TIEN_TRALAI_KHACH = 0;
                                                    string   ID = dataReaderClient["ID"] != null
                                                        ? dataReaderClient["ID"].ToString()
                                                        : Guid.NewGuid().ToString();
                                                    string MA_GIAODICH = dataReaderClient["MA_GIAODICH"] != null
                                                        ? dataReaderClient["MA_GIAODICH"].ToString()
                                                        : "";
                                                    string LOAI_GIAODICH = dataReaderClient["LOAI_GIAODICH"] != null
                                                        ? dataReaderClient["LOAI_GIAODICH"].ToString()
                                                        : "";
                                                    DateTime.TryParse(
                                                        dataReaderClient["NGAY_GIAODICH"] != null
                                                            ? dataReaderClient["NGAY_GIAODICH"].ToString()
                                                            : "", out NGAY_GIAODICH);
                                                    string MAKHACHHANG = dataReaderClient["MAKHACHHANG"] != null
                                                        ? dataReaderClient["MAKHACHHANG"].ToString()
                                                        : "";
                                                    string THOIGIAN_TAO = dataReaderClient["THOIGIAN_TAO"] != null
                                                        ? dataReaderClient["THOIGIAN_TAO"].ToString()
                                                        : "";
                                                    decimal.TryParse(
                                                        dataReaderClient["TIENKHACH_TRA"] != null
                                                            ? dataReaderClient["TIENKHACH_TRA"].ToString()
                                                            : "", out TIENKHACH_TRA);
                                                    decimal.TryParse(
                                                        dataReaderClient["TIEN_TRALAI_KHACH"] != null
                                                            ? dataReaderClient["TIEN_TRALAI_KHACH"].ToString()
                                                            : "", out TIEN_TRALAI_KHACH);
                                                    string MAKHO_XUAT = dataReaderClient["MAKHO_XUAT"] != null
                                                       ? dataReaderClient["MAKHO_XUAT"].ToString()
                                                       : "";
                                                    string MA_VOUCHER = dataReaderClient["MA_VOUCHER"] != null
                                                       ? dataReaderClient["MA_VOUCHER"].ToString()
                                                       : "";
                                                    string DIENGIAI = dataReaderClient["DIENGIAI"] != null
                                                       ? dataReaderClient["DIENGIAI"].ToString()
                                                       : "";
                                                    DateTime.TryParse(
                                                        dataReaderClient["I_CREATE_DATE"] != null
                                                        ? dataReaderClient["I_CREATE_DATE"].ToString()
                                                        : "", out I_CREATE_DATE);
                                                    string I_CREATE_BY = dataReaderClient["I_CREATE_BY"] != null
                                                        ? dataReaderClient["I_CREATE_BY"].ToString()
                                                        : "";
                                                    DateTime.TryParse(
                                                        dataReaderClient["I_UPDATE_DATE"] != null
                                                        ? dataReaderClient["I_UPDATE_DATE"].ToString()
                                                        : "", out I_UPDATE_DATE);
                                                    string I_UPDATE_BY = dataReaderClient["I_UPDATE_BY"] != null
                                                        ? dataReaderClient["I_UPDATE_BY"].ToString()
                                                        : "";
                                                    string I_STATE = dataReaderClient["I_STATE"] != null
                                                        ? dataReaderClient["I_STATE"].ToString()
                                                        : "";
                                                    string UNITCODE = dataReaderClient["UNITCODE"] != null
                                                        ? dataReaderClient["UNITCODE"].ToString()
                                                        : "";
                                                    OracleCommand cmdOracleInsert = new OracleCommand();
                                                    cmdOracleInsert.Connection  = connectionOracle;
                                                    cmdOracleInsert.CommandText = string.Format(@"INSERT INTO GIAODICH(ID,MA_GIAODICH,LOAI_GIAODICH,NGAY_GIAODICH,MAKHACHHANG,THOIGIAN_TAO,TIENKHACH_TRA,TIEN_TRALAI_KHACH,MAKHO_XUAT,MA_VOUCHER,DIENGIAI,I_CREATE_DATE,I_CREATE_BY,I_UPDATE_DATE,I_UPDATE_BY,I_STATE,UNITCODE) VALUES (:ID,:MA_GIAODICH,:LOAI_GIAODICH,:NGAY_GIAODICH,:MAKHACHHANG,:THOIGIAN_TAO,:TIENKHACH_TRA,:TIEN_TRALAI_KHACH,:MAKHO_XUAT,:MA_VOUCHER,:DIENGIAI,:I_CREATE_DATE,:I_CREATE_BY,:I_UPDATE_DATE,:I_UPDATE_BY,:I_STATE,:UNITCODE)");
                                                    cmdOracleInsert.CommandType = CommandType.Text;
                                                    cmdOracleInsert.Parameters.Add("ID", OracleDbType.NVarchar2, 50).Value          = ID;
                                                    cmdOracleInsert.Parameters.Add("MA_GIAODICH", OracleDbType.NVarchar2, 70).Value = MA_GIAODICH;
                                                    cmdOracleInsert.Parameters
                                                    .Add("LOAI_GIAODICH", OracleDbType.NVarchar2, 15).Value =
                                                        LOAI_GIAODICH;
                                                    cmdOracleInsert.Parameters.Add("NGAY_GIAODICH", OracleDbType.Date).Value =
                                                        NGAY_GIAODICH;
                                                    cmdOracleInsert.Parameters.Add("MAKHACHHANG", OracleDbType.NVarchar2, 50)
                                                    .Value = MAKHACHHANG;
                                                    cmdOracleInsert.Parameters.Add("THOIGIAN_TAO", OracleDbType.NVarchar2, 12)
                                                    .Value = THOIGIAN_TAO;
                                                    cmdOracleInsert.Parameters.Add("TIENKHACH_TRA", OracleDbType.Decimal).Value =
                                                        TIENKHACH_TRA;
                                                    cmdOracleInsert.Parameters.Add("TIEN_TRALAI_KHACH", OracleDbType.Decimal).Value =
                                                        TIEN_TRALAI_KHACH;
                                                    cmdOracleInsert.Parameters.Add("MAKHO_XUAT", OracleDbType.NVarchar2, 50)
                                                    .Value = MAKHO_XUAT;
                                                    cmdOracleInsert.Parameters.Add("MA_VOUCHER", OracleDbType.NVarchar2, 50)
                                                    .Value = MA_VOUCHER;
                                                    cmdOracleInsert.Parameters.Add("DIENGIAI", OracleDbType.NVarchar2, 50)
                                                    .Value = DIENGIAI;
                                                    cmdOracleInsert.Parameters.Add("I_CREATE_DATE", OracleDbType.Date).Value        = I_CREATE_DATE;
                                                    cmdOracleInsert.Parameters.Add("I_CREATE_BY", OracleDbType.NVarchar2, 25).Value = I_CREATE_BY;
                                                    cmdOracleInsert.Parameters.Add("I_UPDATE_DATE", OracleDbType.Date).Value        = I_UPDATE_DATE;
                                                    cmdOracleInsert.Parameters.Add("I_UPDATE_BY", OracleDbType.NVarchar2, 25).Value = I_UPDATE_BY;
                                                    cmdOracleInsert.Parameters.Add("I_STATE", OracleDbType.NVarchar2, 1).Value      = I_STATE;
                                                    cmdOracleInsert.Parameters.Add("UNITCODE", OracleDbType.NVarchar2, 10).Value    = UNITCODE;
                                                    int rowCount = cmdOracleInsert.ExecuteNonQuery();
                                                    if (rowCount > 0)
                                                    {
                                                        totalParent += rowCount;
                                                    }
                                                }
                                            }
                                        }

                                        //bảng con
                                        SqlCommand cmdSqlDetails = new SqlCommand();
                                        cmdSqlDetails.Connection  = connectionClient;
                                        cmdSqlDetails.CommandText = string.Format(@"SELECT [ID],[MA_GIAODICH],[MAHANG],[MATHUE_RA],[SOLUONG],[GIABANLE_VAT],[MA_KHUYENMAI],[TYLE_KHUYENMAI],[TIEN_KHUYENMAI],[TYLE_CHIETKHAU],[TIEN_CHIETKHAU],[TIENTHE_VIP],[TIEN_VOUCHER],[THANHTIEN],[SAPXEP]  FROM [ERBUS_CASHIER].[dbo].[GIAODICH_CHITIET]");
                                        cmdSqlDetails.CommandType = CommandType.Text;
                                        SqlDataReader dataReaderClientDetails = cmdSqlDetails.ExecuteReader();
                                        if (dataReaderClientDetails.HasRows)
                                        {
                                            while (dataReaderClientDetails.Read())
                                            {
                                                OracleCommand cmdOracleSelect = new OracleCommand();
                                                cmdOracleSelect.Connection  = connectionOracle;
                                                cmdOracleSelect.CommandText = string.Format(@"SELECT ID,MA_GIAODICH FROM GIAODICH_CHITIET WHERE ID=:ID AND MA_GIAODICH=:MA_GIAODICH");
                                                cmdOracleSelect.CommandType = CommandType.Text;
                                                cmdOracleSelect.Parameters.Add("ID", OracleDbType.NVarchar2, 50).Value          = dataReaderClientDetails["ID"].ToString();
                                                cmdOracleSelect.Parameters.Add("MA_GIAODICH", OracleDbType.NVarchar2, 70).Value = dataReaderClientDetails["MA_GIAODICH"].ToString();
                                                OracleDataReader dataReaderOracleDetails = cmdOracleSelect.ExecuteReader();
                                                if (!dataReaderOracleDetails.HasRows)
                                                {
                                                    decimal SOLUONG        = 0;
                                                    decimal GIABANLE_VAT   = 0;
                                                    decimal TYLE_KHUYENMAI = 0;
                                                    decimal TIEN_KHUYENMAI = 0;
                                                    decimal TYLE_CHIETKHAU = 0;
                                                    decimal TIEN_CHIETKHAU = 0;
                                                    decimal TIENTHE_VIP    = 0;
                                                    decimal TIEN_VOUCHER   = 0;
                                                    decimal THANHTIEN      = 0;
                                                    int     SAPXEP         = 0;
                                                    string  ID             = dataReaderClientDetails["ID"] != null
                                                        ? dataReaderClientDetails["ID"].ToString()
                                                        : Guid.NewGuid().ToString();
                                                    string MA_GIAODICH = dataReaderClientDetails["MA_GIAODICH"] != null
                                                        ? dataReaderClientDetails["MA_GIAODICH"].ToString()
                                                        : "";
                                                    string MAHANG = dataReaderClientDetails["MAHANG"] != null
                                                        ? dataReaderClientDetails["MAHANG"].ToString()
                                                        : "";
                                                    string MATHUE_RA = dataReaderClientDetails["MATHUE_RA"] != null
                                                        ? dataReaderClientDetails["MATHUE_RA"].ToString()
                                                        : "";
                                                    decimal.TryParse(
                                                        dataReaderClientDetails["SOLUONG"] != null
                                                            ? dataReaderClientDetails["SOLUONG"].ToString()
                                                            : "", out SOLUONG);
                                                    decimal.TryParse(
                                                        dataReaderClientDetails["GIABANLE_VAT"] != null
                                                            ? dataReaderClientDetails["GIABANLE_VAT"].ToString()
                                                            : "", out GIABANLE_VAT);
                                                    string MA_KHUYENMAI = dataReaderClientDetails["MA_KHUYENMAI"] != null
                                                        ? dataReaderClientDetails["MA_KHUYENMAI"].ToString()
                                                        : "";
                                                    decimal.TryParse(
                                                        dataReaderClientDetails["TYLE_KHUYENMAI"] != null
                                                            ? dataReaderClientDetails["TYLE_KHUYENMAI"].ToString()
                                                            : "", out TYLE_KHUYENMAI);
                                                    decimal.TryParse(
                                                        dataReaderClientDetails["TIEN_KHUYENMAI"] != null
                                                            ? dataReaderClientDetails["TIEN_KHUYENMAI"].ToString()
                                                            : "", out TIEN_KHUYENMAI);
                                                    decimal.TryParse(
                                                        dataReaderClientDetails["TYLE_CHIETKHAU"] != null
                                                            ? dataReaderClientDetails["TYLE_CHIETKHAU"].ToString()
                                                            : "", out TYLE_CHIETKHAU);
                                                    decimal.TryParse(
                                                        dataReaderClientDetails["TIEN_CHIETKHAU"] != null
                                                            ? dataReaderClientDetails["TIEN_CHIETKHAU"].ToString()
                                                            : "", out TIEN_CHIETKHAU);
                                                    decimal.TryParse(
                                                        dataReaderClientDetails["TIENTHE_VIP"] != null
                                                            ? dataReaderClientDetails["TIENTHE_VIP"].ToString()
                                                            : "", out TIENTHE_VIP);
                                                    decimal.TryParse(
                                                        dataReaderClientDetails["TIEN_VOUCHER"] != null
                                                            ? dataReaderClientDetails["TIEN_VOUCHER"].ToString()
                                                            : "", out TIEN_VOUCHER);
                                                    decimal.TryParse(
                                                        dataReaderClientDetails["THANHTIEN"] != null
                                                            ? dataReaderClientDetails["THANHTIEN"].ToString()
                                                            : "", out THANHTIEN);
                                                    decimal.TryParse(
                                                        dataReaderClientDetails["TIEN_VOUCHER"] != null
                                                            ? dataReaderClientDetails["TIEN_VOUCHER"].ToString()
                                                            : "", out TIEN_VOUCHER);
                                                    int.TryParse(
                                                        dataReaderClientDetails["SAPXEP"] != null
                                                            ? dataReaderClientDetails["SAPXEP"].ToString()
                                                            : "", out SAPXEP);
                                                    OracleCommand cmdOracleInsert = new OracleCommand();
                                                    cmdOracleInsert.Connection  = connectionOracle;
                                                    cmdOracleInsert.CommandText = string.Format(@"INSERT INTO GIAODICH_CHITIET(ID,MA_GIAODICH,MAHANG,MATHUE_RA,SOLUONG,GIABANLE_VAT,MA_KHUYENMAI,TYLE_KHUYENMAI,TIEN_KHUYENMAI,TYLE_CHIETKHAU,TIEN_CHIETKHAU,TIENTHE_VIP,TIEN_VOUCHER,THANHTIEN,SAPXEP) 
                                                    VALUES (:ID,:MA_GIAODICH,:MAHANG,:MATHUE_RA,:SOLUONG,:GIABANLE_VAT,:MA_KHUYENMAI,:TYLE_KHUYENMAI,:TIEN_KHUYENMAI,:TYLE_CHIETKHAU,:TIEN_CHIETKHAU,:TIENTHE_VIP,:TIEN_VOUCHER,:THANHTIEN,:SAPXEP)");
                                                    cmdOracleInsert.CommandType = CommandType.Text;
                                                    cmdOracleInsert.Parameters.Add("ID", OracleDbType.NVarchar2, 50).Value = ID;
                                                    cmdOracleInsert.Parameters.Add("MA_GIAODICH", OracleDbType.NVarchar2, 70)
                                                    .Value = MA_GIAODICH;
                                                    cmdOracleInsert.Parameters.Add("MAHANG", OracleDbType.NVarchar2, 50)
                                                    .Value = MAHANG;
                                                    cmdOracleInsert.Parameters.Add("MATHUE_RA", OracleDbType.NVarchar2, 50)
                                                    .Value = MATHUE_RA;
                                                    cmdOracleInsert.Parameters.Add("SOLUONG", OracleDbType.Decimal).Value =
                                                        SOLUONG;
                                                    cmdOracleInsert.Parameters.Add("GIABANLE_VAT", OracleDbType.Decimal).Value =
                                                        GIABANLE_VAT;
                                                    cmdOracleInsert.Parameters.Add("MA_KHUYENMAI", OracleDbType.NVarchar2, 30)
                                                    .Value = MA_KHUYENMAI;
                                                    cmdOracleInsert.Parameters.Add("TYLE_KHUYENMAI", OracleDbType.Decimal)
                                                    .Value = TYLE_KHUYENMAI;
                                                    cmdOracleInsert.Parameters.Add("TIEN_KHUYENMAI", OracleDbType.Decimal)
                                                    .Value = TIEN_KHUYENMAI;
                                                    cmdOracleInsert.Parameters.Add("TYLE_CHIETKHAU", OracleDbType.Decimal)
                                                    .Value = TYLE_CHIETKHAU;
                                                    cmdOracleInsert.Parameters.Add("TIEN_CHIETKHAU", OracleDbType.Decimal)
                                                    .Value = TIEN_CHIETKHAU;
                                                    cmdOracleInsert.Parameters.Add("TIENTHE_VIP", OracleDbType.Decimal).Value =
                                                        TIENTHE_VIP;
                                                    cmdOracleInsert.Parameters.Add("TIEN_VOUCHER", OracleDbType.Decimal).Value =
                                                        TIEN_VOUCHER;
                                                    cmdOracleInsert.Parameters.Add("THANHTIEN", OracleDbType.Decimal).Value =
                                                        THANHTIEN;
                                                    cmdOracleInsert.Parameters.Add("SAPXEP", OracleDbType.Int32).Value =
                                                        SAPXEP;
                                                    int rowCount = cmdOracleInsert.ExecuteNonQuery();
                                                    if (rowCount > 0)
                                                    {
                                                        totalChildren += rowCount;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                catch
                                {
                                }
                                finally
                                {
                                    connectionClient.Close();
                                }
                            }
                        }
                        catch
                        {
                        }
                        finally
                        {
                            connectionOracle.Close();
                            SplashScreenManager.CloseForm();
                        }
                    }
                    MessageBox.Show("Đồng bộ thành công " + totalParent + " bản ghi ");
                    MessageBox.Show("Đồng bộ thành công " + totalChildren + " bản ghi giao dịch con");
                }
            }
            catch (Exception ex)
            {
                WriteLogs.LogError(ex);
                MessageBox.Show("Xảy ra lỗi khi đồng bộ dữ liệu");
                SplashScreenManager.CloseForm();
            }
        }
Exemplo n.º 26
0
        public List <TIMKIEM_VATTU_DTO> TIMKIEM_DULIEU_HANGHOA_DATABASE_ORACLE(string DIEUKIENLOC, int SUDUNG_TIMKIEM_ALL, int DIEUKIENCHON, string UNITCODE)
        {
            List <TIMKIEM_VATTU_DTO> LST_TIMKIEM_VATTU_DTO = new List <TIMKIEM_VATTU_DTO>();

            if (!string.IsNullOrEmpty(DIEUKIENLOC))
            {
                using (OracleConnection connection = new OracleConnection(ConfigurationManager.ConnectionStrings["TBNETERP_SERVER"].ConnectionString))
                {
                    try
                    {
                        connection.Open();
                        if (connection.State == ConnectionState.Open)
                        {
                            OracleCommand command = new OracleCommand();
                            command.Connection  = connection;
                            command.CommandType = CommandType.StoredProcedure;
                            command.CommandText = @"BANLE_TIMKIEM_BOHANG_MAHANG";
                            command.Parameters.Add(@"P_MADONVI", OracleDbType.NVarchar2, 50).Value     = UNITCODE;
                            command.Parameters.Add(@"P_TUKHOA", OracleDbType.NVarchar2, 50).Value      = DIEUKIENLOC.ToString().ToUpper().Trim();
                            command.Parameters.Add(@"P_SUDUNG_TIMKIEM_ALL", OracleDbType.Int32).Value  = SUDUNG_TIMKIEM_ALL;
                            command.Parameters.Add(@"P_DIEUKIENCHON", OracleDbType.Int32).Value        = DIEUKIENCHON;
                            command.Parameters.Add(@"CURSOR_RESULT", OracleDbType.RefCursor).Direction = ParameterDirection.Output;
                            OracleDataReader dataReader = command.ExecuteReader();
                            if (dataReader.HasRows)
                            {
                                while (dataReader.Read())
                                {
                                    TIMKIEM_VATTU_DTO TIMKIEM_VATTU_DTO = new TIMKIEM_VATTU_DTO();
                                    if (dataReader["MAVATTU"] != null)
                                    {
                                        TIMKIEM_VATTU_DTO.MAVATTU = dataReader["MAVATTU"].ToString();
                                    }
                                    if (dataReader["MAKHAC"] != null)
                                    {
                                        TIMKIEM_VATTU_DTO.MAKHAC = dataReader["MAKHAC"].ToString();
                                    }
                                    if (dataReader["TENVATTU"] != null)
                                    {
                                        TIMKIEM_VATTU_DTO.TENVATTU = dataReader["TENVATTU"].ToString();
                                    }
                                    if (dataReader["MALOAIVATTU"] != null)
                                    {
                                        TIMKIEM_VATTU_DTO.MALOAIVATTU = dataReader["MALOAIVATTU"].ToString();
                                    }
                                    if (dataReader["MANHOMVATTU"] != null)
                                    {
                                        TIMKIEM_VATTU_DTO.MANHOMVATTU = dataReader["MANHOMVATTU"].ToString();
                                    }
                                    if (dataReader["DONVITINH"] != null)
                                    {
                                        TIMKIEM_VATTU_DTO.DONVITINH = dataReader["DONVITINH"].ToString();
                                    }
                                    if (dataReader["MANHACUNGCAP"] != null)
                                    {
                                        TIMKIEM_VATTU_DTO.MANHACUNGCAP = dataReader["MANHACUNGCAP"].ToString();
                                    }
                                    if (dataReader["TENNHACUNGCAP"] != null)
                                    {
                                        TIMKIEM_VATTU_DTO.TENNHACUNGCAP = dataReader["TENNHACUNGCAP"].ToString();
                                    }
                                    if (dataReader["MAKEHANG"] != null)
                                    {
                                        TIMKIEM_VATTU_DTO.MAKEHANG = dataReader["MAKEHANG"].ToString();
                                    }
                                    if (dataReader["GIABANLEVAT"] != null)
                                    {
                                        decimal GIABANLECOVAT = 0;
                                        decimal.TryParse(dataReader["GIABANLEVAT"].ToString(), out GIABANLECOVAT);
                                        TIMKIEM_VATTU_DTO.GIABANLECOVAT = GIABANLECOVAT;
                                    }
                                    if (dataReader["ITEMCODE"] != null)
                                    {
                                        TIMKIEM_VATTU_DTO.ITEMCODE = dataReader["ITEMCODE"].ToString();
                                    }
                                    if (dataReader["BARCODE"] != null)
                                    {
                                        TIMKIEM_VATTU_DTO.BARCODE = dataReader["BARCODE"].ToString();
                                    }
                                    LST_TIMKIEM_VATTU_DTO.Add(TIMKIEM_VATTU_DTO);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        WriteLogs.LogError(ex);
                    }
                    finally
                    {
                        connection.Close();
                        connection.Dispose();
                    }
                }
            }
            return(LST_TIMKIEM_VATTU_DTO);
        }
Exemplo n.º 27
0
        public int SAVE_DATA_KHACHHANG_TO_ORACLE()
        {
            int RESULT = 0;
            //SAVE ORACLE
            string MAKHACHHANG = SAVE_MAKHACHHANG_TO_ORACLE();

            using (OracleConnection connection = new OracleConnection(ConfigurationManager.ConnectionStrings["TBNETERP_SERVER"].ConnectionString))
            {
                connection.Open();
                if (connection.State == ConnectionState.Open)
                {
                    try
                    {
                        KHACHHANG_DTO _KHACHHANG_DTO = new KHACHHANG_DTO();
                        _KHACHHANG_DTO.MAKH       = MAKHACHHANG;
                        _KHACHHANG_DTO.TENKH      = txtTenKhachHang.Text;
                        _KHACHHANG_DTO.DIACHI     = txtDiaChi.Text;
                        _KHACHHANG_DTO.DIENTHOAI  = txtDienThoai.Text;
                        _KHACHHANG_DTO.CMTND      = txtChungMinhThu.Text;
                        _KHACHHANG_DTO.EMAIL      = "";
                        _KHACHHANG_DTO.SODIEM     = 0;
                        _KHACHHANG_DTO.TONGTIEN   = 0;
                        _KHACHHANG_DTO.NGAYCAPTHE = DateTime.Now;
                        _KHACHHANG_DTO.NGAYHETHAN = DateTime.Now.AddYears(1);
                        _KHACHHANG_DTO.NGAYSINH   = dateNgaySinh.Value;
                        _KHACHHANG_DTO.UNITCODE   = Session.Session.CurrentUnitCode;
                        _KHACHHANG_DTO.MATHE      = txtMaThe.Text;

                        OracleCommand command = new OracleCommand();
                        command.Connection = connection;
                        string queryInsertItem = string.Format(@"INSERT INTO DM_KHACHHANG (ID,MAKH,TENKH,DIACHI,DIENTHOAI,CMTND,SODIEM,TONGTIEN,NGAYCAPTHE,NGAYHETHAN,NGAYSINH,UNITCODE,TRANGTHAI,MATHE) VALUES (:ID,:MAKH,:TENKH,:DIACHI,:DIENTHOAI,:CMTND,:SODIEM,:TONGTIEN,:NGAYCAPTHE,:NGAYHETHAN,:NGAYSINH,:UNITCODE,:TRANGTHAI,:MATHE)");
                        command.CommandText = queryInsertItem;
                        command.CommandType = CommandType.Text;
                        command.Parameters.Add("ID", OracleDbType.NVarchar2, 50).Value        = Guid.NewGuid();
                        command.Parameters.Add("MAKH", OracleDbType.NVarchar2, 50).Value      = _KHACHHANG_DTO.MAKH;
                        command.Parameters.Add("TENKH", OracleDbType.NVarchar2, 50).Value     = _KHACHHANG_DTO.TENKH;
                        command.Parameters.Add("DIACHI", OracleDbType.NVarchar2, 50).Value    = _KHACHHANG_DTO.DIACHI;
                        command.Parameters.Add("DIENTHOAI", OracleDbType.NVarchar2, 50).Value = _KHACHHANG_DTO.DIENTHOAI;
                        command.Parameters.Add("CMTND", OracleDbType.NVarchar2, 50).Value     = _KHACHHANG_DTO.CMTND;
                        command.Parameters.Add("SODIEM", OracleDbType.Decimal).Value          = _KHACHHANG_DTO.SODIEM;
                        command.Parameters.Add("TONGTIEN", OracleDbType.Decimal).Value        = _KHACHHANG_DTO.TONGTIEN;
                        command.Parameters.Add("NGAYCAPTHE", OracleDbType.Date).Value         = _KHACHHANG_DTO.NGAYCAPTHE;
                        command.Parameters.Add("NGAYHETHAN", OracleDbType.Date).Value         = _KHACHHANG_DTO.NGAYHETHAN;
                        command.Parameters.Add("NGAYSINH", OracleDbType.Date).Value           = _KHACHHANG_DTO.NGAYSINH;
                        command.Parameters.Add("UNITCODE", OracleDbType.NVarchar2, 50).Value  = _KHACHHANG_DTO.UNITCODE;
                        command.Parameters.Add("TRANGTHAI", OracleDbType.Int32).Value         = 10;
                        command.Parameters.Add("MATHE", OracleDbType.NVarchar2, 50).Value     = _KHACHHANG_DTO.MATHE;
                        try
                        {
                            if (command.ExecuteNonQuery() > 0)
                            {
                                RESULT++;
                            }
                            _STATUS_THEMMOI_KHACHHANG(_KHACHHANG_DTO);
                        }
                        catch (Exception e)
                        {
                            WriteLogs.LogError(e);
                            NotificationLauncher.ShowNotificationError("THÔNG BÁO", "XẢY RA LỖI KHI LƯU THÔNG TIN KHÁCH HÀNG", 1, "0x1", "0x8", "normal");
                        }
                    }
                    catch (Exception ex)
                    {
                        WriteLogs.LogError(ex);
                    }
                    finally
                    {
                        connection.Close();
                        connection.Dispose();
                    }
                }
                else
                {
                    NotificationLauncher.ShowNotificationError("THÔNG BÁO", "KHÔNG CÓ KẾT NỐI VỚI CƠ SỞ DỮ LIỆU TỚI ORACLE", 1, "0x1", "0x8", "normal");
                }
            }
            return(RESULT);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Lưu dữ liệu bán lẻ
        /// </summary>
        /// <param name="header"></param>
        /// <param name="details"></param>
        /// <returns></returns>
        private int SAVE_DATA_TO_ORACLE(NVGDQUAY_ASYNCCLIENT_DTO _NVGDQUAY_ASYNCCLIENT_DTO)
        {
            int countCheckInsertSuccess = 0;

            if (_NVGDQUAY_ASYNCCLIENT_DTO != null)
            {
                using (OracleConnection connection = new OracleConnection(ConfigurationManager.ConnectionStrings["TBNETERP_SERVER"].ConnectionString))
                {
                    try
                    {
                        connection.Open();
                        if (connection.State == ConnectionState.Open)
                        {
                            try
                            {
                                string        queryInsert = "";
                                OracleCommand cmd         = new OracleCommand();
                                cmd.Connection = connection;
                                queryInsert    =
                                    string.Format(
                                        @"INSERT INTO NVGDQUAY_ASYNCCLIENT (ID,MAGIAODICH,MAGIAODICHQUAYPK,MADONVI,LOAIGIAODICH,NGAYTAO,MANGUOITAO,
                                    NGUOITAO,MAQUAYBAN,NGAYPHATSINH,HINHTHUCTHANHTOAN,MAVOUCHER,TIENKHACHDUA,TIENVOUCHER,TIENTHEVIP,TIENTRALAI,TIENTHE,TIENCOD,TIENMAT,TTIENCOVAT,
                                    THOIGIAN,MAKHACHHANG,I_CREATE_DATE,I_CREATE_BY,I_STATE,UNITCODE) VALUES (
                                    :ID,:MAGIAODICH,:MAGIAODICHQUAYPK,:MADONVI,:LOAIGIAODICH,:NGAYTAO,:MANGUOITAO,
                                    :NGUOITAO,:MAQUAYBAN,:NGAYPHATSINH,:HINHTHUCTHANHTOAN,:MAVOUCHER,:TIENKHACHDUA,:TIENVOUCHER,:TIENTHEVIP,:TIENTRALAI,:TIENTHE,:TIENCOD,:TIENMAT,:TTIENCOVAT,
                                    :THOIGIAN,:MAKHACHHANG,:I_CREATE_DATE,:I_CREATE_BY,:I_STATE,:UNITCODE)");
                                cmd.CommandText = queryInsert;
                                cmd.CommandType = CommandType.Text;
                                cmd.Parameters.Add("ID", OracleDbType.NVarchar2, 50).Value               = _NVGDQUAY_ASYNCCLIENT_DTO.ID;
                                cmd.Parameters.Add("MAGIAODICH", OracleDbType.NVarchar2, 50).Value       = _NVGDQUAY_ASYNCCLIENT_DTO.MAGIAODICH;
                                cmd.Parameters.Add("MAGIAODICHQUAYPK", OracleDbType.NVarchar2, 50).Value = _NVGDQUAY_ASYNCCLIENT_DTO.MAGIAODICHQUAYPK;
                                cmd.Parameters.Add("MADONVI", OracleDbType.NVarchar2, 50).Value          = _NVGDQUAY_ASYNCCLIENT_DTO.MADONVI;
                                cmd.Parameters.Add("LOAIGIAODICH", OracleDbType.Int32).Value             = _NVGDQUAY_ASYNCCLIENT_DTO.LOAIGIAODICH;
                                cmd.Parameters.Add("NGAYTAO", OracleDbType.Date).Value = _NVGDQUAY_ASYNCCLIENT_DTO.NGAYTAO;
                                cmd.Parameters.Add("MANGUOITAO", OracleDbType.NVarchar2, 300).Value        = _NVGDQUAY_ASYNCCLIENT_DTO.MANGUOITAO;
                                cmd.Parameters.Add("NGUOITAO", OracleDbType.NVarchar2, 300).Value          = _NVGDQUAY_ASYNCCLIENT_DTO.NGUOITAO;
                                cmd.Parameters.Add("MAQUAYBAN", OracleDbType.NVarchar2, 300).Value         = _NVGDQUAY_ASYNCCLIENT_DTO.MAQUAYBAN;
                                cmd.Parameters.Add("NGAYPHATSINH", OracleDbType.Date).Value                = _NVGDQUAY_ASYNCCLIENT_DTO.NGAYPHATSINH;
                                cmd.Parameters.Add("HINHTHUCTHANHTOAN", OracleDbType.NVarchar2, 200).Value = _NVGDQUAY_ASYNCCLIENT_DTO.HINHTHUCTHANHTOAN;
                                cmd.Parameters.Add("MAVOUCHER", OracleDbType.NVarchar2, 50).Value          = _NVGDQUAY_ASYNCCLIENT_DTO.MAVOUCHER;
                                cmd.Parameters.Add("TIENKHACHDUA", OracleDbType.Decimal).Value             = _NVGDQUAY_ASYNCCLIENT_DTO.TIENKHACHDUA;
                                cmd.Parameters.Add("TIENVOUCHER", OracleDbType.Decimal).Value              = _NVGDQUAY_ASYNCCLIENT_DTO.TIENVOUCHER;
                                cmd.Parameters.Add("TIENTHEVIP", OracleDbType.Decimal).Value               = _NVGDQUAY_ASYNCCLIENT_DTO.TIENTHEVIP;
                                cmd.Parameters.Add("TIENTRALAI", OracleDbType.Decimal).Value               = _NVGDQUAY_ASYNCCLIENT_DTO.TIENTRALAI;
                                cmd.Parameters.Add("TIENTHE ", OracleDbType.Decimal).Value          = _NVGDQUAY_ASYNCCLIENT_DTO.TIENTHE >= _NVGDQUAY_ASYNCCLIENT_DTO.TTIENCOVAT ? _NVGDQUAY_ASYNCCLIENT_DTO.TTIENCOVAT : _NVGDQUAY_ASYNCCLIENT_DTO.TIENTHE;
                                cmd.Parameters.Add("TIENCOD", OracleDbType.Decimal).Value           = _NVGDQUAY_ASYNCCLIENT_DTO.TIENCOD;
                                cmd.Parameters.Add("TIENMAT", OracleDbType.Decimal).Value           = _NVGDQUAY_ASYNCCLIENT_DTO.TIENMAT >= _NVGDQUAY_ASYNCCLIENT_DTO.TTIENCOVAT ? _NVGDQUAY_ASYNCCLIENT_DTO.TTIENCOVAT : _NVGDQUAY_ASYNCCLIENT_DTO.TIENMAT;
                                cmd.Parameters.Add("TTIENCOVAT", OracleDbType.Decimal).Value        = _NVGDQUAY_ASYNCCLIENT_DTO.TTIENCOVAT;
                                cmd.Parameters.Add("THOIGIAN", OracleDbType.NVarchar2, 150).Value   = _NVGDQUAY_ASYNCCLIENT_DTO.THOIGIAN;
                                cmd.Parameters.Add("MAKHACHHANG", OracleDbType.NVarchar2, 50).Value = _NVGDQUAY_ASYNCCLIENT_DTO.MAKHACHHANG;
                                cmd.Parameters.Add("I_CREATE_DATE", OracleDbType.Date).Value        = _NVGDQUAY_ASYNCCLIENT_DTO.I_CREATE_DATE;
                                cmd.Parameters.Add("I_CREATE_BY", OracleDbType.NVarchar2, 50).Value = _NVGDQUAY_ASYNCCLIENT_DTO.I_CREATE_BY;
                                cmd.Parameters.Add("I_STATE", OracleDbType.NVarchar2, 50).Value     = _NVGDQUAY_ASYNCCLIENT_DTO.I_STATE;
                                cmd.Parameters.Add("UNITCODE", OracleDbType.NVarchar2, 50).Value    = _NVGDQUAY_ASYNCCLIENT_DTO.UNITCODE;
                                if (cmd.ExecuteNonQuery() > 0)
                                {
                                    countCheckInsertSuccess++;
                                    INSERT_DATA_HANG_GIAODICHQUAY(_NVGDQUAY_ASYNCCLIENT_DTO, ref countCheckInsertSuccess);
                                }
                                //chạy store tăng xuất nhập tồn
                                if (!string.IsNullOrEmpty(Session.Session.CurrentTableNamePeriod))
                                {
                                    OracleCommand cmdTruTon = new OracleCommand();
                                    cmdTruTon.Connection  = connection;
                                    cmdTruTon.CommandText = @"TBNETERP.XNT.XNT_TANG_PHIEU";
                                    cmdTruTon.CommandType = CommandType.StoredProcedure;
                                    cmdTruTon.Parameters.Add("P_TABLENAME", OracleDbType.Varchar2, 50).Value = Session.Session.CurrentTableNamePeriod;
                                    cmdTruTon.Parameters.Add("P_NAM", OracleDbType.Varchar2, 50).Value       = Session.Session.CurrentYear;
                                    cmdTruTon.Parameters.Add("P_KY", OracleDbType.Decimal).Value             = decimal.Parse(Session.Session.CurrentPeriod);
                                    cmdTruTon.Parameters.Add("P_ID", OracleDbType.Varchar2, 50).Value        = _NVGDQUAY_ASYNCCLIENT_DTO.ID;
                                    cmdTruTon.ExecuteNonQuery();
                                }
                            }
                            catch (Exception ex)
                            {
                                WriteLogs.LogError(ex);
                            }
                            finally
                            {
                                SAVE_DATA_TO_SQL_HAVE_INTERNET(_NVGDQUAY_ASYNCCLIENT_DTO);
                                connection.Close();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        WriteLogs.LogError(ex);
                    }
                }
            }
            return(countCheckInsertSuccess);
        }
Exemplo n.º 29
0
        private void LOGIN()
        {
            string Username = txtUserName.Text.Trim();
            string passWord = txtPassWord.Text.Trim();
            string passMd5  = MD5Encrypt.MD5Hash(passWord).Trim();

            //check true false login
            try
            {
                string msg = Config.CheckConnectToServer(out bool result);
                if (msg.Length > 0)
                {
                    MessageBox.Show(msg); return;
                }

                //BEGIN LOGIN
                if (result) // nếu có mạng lan
                {
                    using (OracleConnection connection = new OracleConnection(ConfigurationManager.ConnectionStrings["TBNETERP_SERVER"].ConnectionString))
                    {
                        connection.Open();
                        if (connection.State == ConnectionState.Open)
                        {
                            try
                            {
                                OracleCommand cmd = new OracleCommand();
                                cmd.Connection  = connection;
                                cmd.CommandText = string.Format(@"SELECT * FROM AU_NGUOIDUNG WHERE USERNAME = '******' AND PASSWORD = '******'");
                                OracleDataReader dataReader = null;
                                dataReader = cmd.ExecuteReader();
                                if (dataReader.HasRows)
                                {
                                    while (dataReader.Read())
                                    {
                                        Session.Session.CurrentMaNhanVien  = dataReader["MANHANVIEN"].ToString();
                                        Session.Session.CurrentTenNhanVien = dataReader["TENNHANVIEN"].ToString();
                                        Session.Session.CurrentUnitCode    = dataReader["UNITCODE"].ToString();
                                        if (!string.IsNullOrEmpty(Session.Session.CurrentUnitCode))
                                        {
                                            Session.Session.CurrentCodeStore = Session.Session.CurrentUnitCode.Split('-')[1];
                                        }
                                        OracleCommand command = new OracleCommand();
                                        command.Connection  = connection;
                                        command.CommandText = string.Format(@"SELECT * FROM AU_DONVI WHERE MADONVI = '" + Session.Session.CurrentUnitCode + "'");
                                        OracleDataReader dataReaderDonVi = null;
                                        dataReaderDonVi = command.ExecuteReader();
                                        if (dataReaderDonVi.HasRows)
                                        {
                                            while (dataReaderDonVi.Read())
                                            {
                                                Session.Session.CurrentPhone     = dataReaderDonVi["SODIENTHOAI"].ToString();
                                                Session.Session.CurrentAddress   = dataReaderDonVi["DIACHI"].ToString();
                                                Session.Session.CurrentNameStore = dataReaderDonVi["TENCUAHANG"].ToString();
                                            }
                                        }
                                        Session.Session.CurrentUserName        = dataReader["USERNAME"].ToString();
                                        Session.Session.CurrentNgayPhatSinh    = FrmXuatBanLeService.GET_NGAYHACHTOAN_CSDL_ORACLE();
                                        Session.Session.CurrentTableNamePeriod = FrmXuatBanLeService.GET_TABLE_NAME_NGAYHACHTOAN_CSDL_ORACLE();
                                        Session.Session.CurrentWareHouse       = (Session.Session.CurrentUnitCode + "-K2").ToUpper().Trim();
                                        SplashScreenManager.ShowForm(typeof(WaitForm1));

                                        SYNCHRONIZE_DATA.SYNCHRONIZE_AU_NGUOIDUNG();
                                        SYNCHRONIZE_DATA.SYNCHRONIZE_DM_BOHANG();
                                        SYNCHRONIZE_DATA.SYNCHRONIZE_DM_BOHANGCHITIET();
                                        SYNCHRONIZE_DATA.SYNCHRONIZE_DM_KHACHHANG();
                                        SYNCHRONIZE_DATA.SYNCHRONIZE_KHUYENMAI();
                                        SYNCHRONIZE_DATA.SYNCHRONIZE_AU_THAMSOHETHONG();
                                        SYNCHRONIZE_DATA.SYNCHRONIZE_AU_DONVI();
                                        SYNCHRONIZE_DATA.SYNCHRONIZE_DM_VATTU();
                                        SYNCHRONIZE_DATA.SYNCHRONIZE_DM_HANGKHACHHANG();

                                        SplashScreenManager.CloseForm();
                                        FrmMain frmMain = new FrmMain();
                                        frmMain.ShowDialog();
                                        break;
                                    }
                                }
                                else
                                {
                                    NotificationLauncher.ShowNotificationWarning("Thông báo", "Thông tin đăng nhập không đúng", 1, "0x1", "0x8", "normal");
                                    txtPassWord.Text = "";
                                    txtPassWord.Focus();
                                }
                            }
                            catch (Exception ex)
                            {
                                NotificationLauncher.ShowNotificationError("Thông báo", "Không có kết nối với cơ sở dữ liệu máy chủ", 1, "0x1", "0x8", "normal");
                                WriteLogs.LogError(ex);
                            }
                            finally
                            {
                                connection.Close();
                                connection.Dispose();
                            }
                        }
                        else
                        {
                            NotificationLauncher.ShowNotificationError("Thông báo", "Không có kế nối với cơ sở dữ liệu", 1, "0x1", "0x8", "normal");
                        }
                    }
                }
                else
                {
                    //Kết nối với SQL
                    using (SqlConnection connectionSa = new SqlConnection(ConfigurationManager.ConnectionStrings["TBNETERP_CLIENT"].ConnectionString))
                    {
                        connectionSa.Open();
                        if (connectionSa.State == ConnectionState.Open)
                        {
                            try
                            {
                                SqlCommand cmdSelectSa = new SqlCommand();
                                cmdSelectSa.Connection  = connectionSa;
                                cmdSelectSa.CommandText = string.Format(@"SELECT [ID],[USERNAME],[PASSWORD],[MANHANVIEN],[TENNHANVIEN],[SODIENTHOAI],[SOCHUNGMINHTHU],[GIOITINH],[TRANGTHAI],[LEVEL],[UNITCODE],[PARENT_UNITCODE] FROM [dbo].[AU_NGUOIDUNG] WHERE USERNAME = '******' AND PASSWORD = '******'");
                                SqlDataReader dataReader = null;
                                dataReader = cmdSelectSa.ExecuteReader();
                                if (dataReader.HasRows)
                                {
                                    while (dataReader.Read())
                                    {
                                        Session.Session.CurrentMaNhanVien  = dataReader["MANHANVIEN"].ToString();
                                        Session.Session.CurrentTenNhanVien = dataReader["TENNHANVIEN"].ToString();
                                        Session.Session.CurrentUnitCode    = dataReader["UNITCODE"].ToString();
                                        if (!string.IsNullOrEmpty(Session.Session.CurrentUnitCode))
                                        {
                                            Session.Session.CurrentCodeStore = Session.Session.CurrentUnitCode.Split('-')[1];
                                        }
                                        SqlCommand commandDonVi = new SqlCommand();
                                        commandDonVi.Connection  = connectionSa;
                                        commandDonVi.CommandText = string.Format(@"SELECT [ID],[MADONVI],[MADONVICHA],[TENDONVI],[SODIENTHOAI],[DIACHI],[TRANGTHAI],[MACUAHANG],[TENCUAHANG],[UNITCODE] FROM [dbo].[AU_DONVI] WHERE MADONVI = '" + Session.Session.CurrentUnitCode + "'");
                                        SqlDataReader dataReaderDonVi = null;
                                        dataReaderDonVi = commandDonVi.ExecuteReader();
                                        if (dataReaderDonVi.HasRows)
                                        {
                                            while (dataReaderDonVi.Read())
                                            {
                                                Session.Session.CurrentPhone     = dataReaderDonVi["SODIENTHOAI"].ToString();
                                                Session.Session.CurrentAddress   = dataReaderDonVi["DIACHI"].ToString();
                                                Session.Session.CurrentNameStore = dataReaderDonVi["TENCUAHANG"].ToString();
                                            }
                                        }
                                        Session.Session.CurrentUserName = dataReader["USERNAME"].ToString();
                                        //nếu mất mạng thì ngày phát sinh là ngày hiện tại
                                        Session.Session.CurrentNgayPhatSinh = DateTime.Now;
                                        Session.Session.CurrentWareHouse    = (Session.Session.CurrentUnitCode + "-K2").ToUpper().Trim();
                                        FrmMain frmMain = new FrmMain();
                                        frmMain.ShowDialog();
                                        break;
                                    }
                                }
                                else
                                {
                                    NotificationLauncher.ShowNotificationWarning("Thông báo", "Thông tin đăng nhập không đúng", 1, "0x1", "0x8", "normal");
                                    txtPassWord.Text = "";
                                    txtPassWord.Focus();
                                }
                            }
                            catch (Exception ex)
                            {
                                NotificationLauncher.ShowNotificationError("Thông báo", "Không có kế nối với cơ sở dữ liệu máy bán", 1, "0x1", "0x8", "normal");
                                WriteLogs.LogError(ex);
                            }
                            finally
                            {
                                connectionSa.Close();
                                connectionSa.Dispose();
                            }
                        }
                        else
                        {
                            NotificationLauncher.ShowNotificationError("Thông báo", "Không có kế nối với cơ sở dữ liệu", 1, "0x1", "0x8", "normal");
                        }
                    }
                }
                //END LOGIN
            }
            catch (Exception ex)
            {
                NotificationLauncher.ShowNotificationError("Thông báo", "Không có kế nối với cơ sở dữ liệu máy bán", 1, "0x1", "0x8", "normal");
                WriteLogs.LogError(ex);
            }
        }
Exemplo n.º 30
0
        private void btnDongBo_Click(object sender, EventArgs e)
        {
            int hdSV = 0;
            int mhSV = 0;
            int hdMT = 0;
            int mhMT = 0;

            using (OracleConnection connection = new OracleConnection(ConfigurationManager.ConnectionStrings["TBNETERP_SERVER"].ConnectionString))
            {
                string msg = Config.CheckConnectToServer(out bool result);
                if (msg.Length > 0)
                {
                    MessageBox.Show(msg); return;
                }

                if (result) // nếu có mạng lan
                {
                    connection.Open();
                    if (connection.State == ConnectionState.Open)
                    {
                        foreach (NVGDQUAY_ASYNCCLIENT_DTO item in lstData)
                        {
                            try
                            {
                                OracleCommand orlCommand = new OracleCommand();
                                orlCommand.Connection  = connection;
                                orlCommand.CommandText = @"SELECT * FROM NVGDQUAY_ASYNCCLIENT WHERE MAGIAODICHQUAYPK = '" + item.MAGIAODICHQUAYPK + "'";
                                orlCommand.CommandType = CommandType.Text;
                                try
                                {
                                    OracleDataReader reader = orlCommand.ExecuteReader();
                                    if (!reader.HasRows)
                                    {
                                        try
                                        {
                                            string        queryInsert = "";
                                            OracleCommand cmd         = new OracleCommand();
                                            cmd.Connection = connection;
                                            queryInsert    =
                                                string.Format(
                                                    @"INSERT INTO NVGDQUAY_ASYNCCLIENT (ID,MAGIAODICH,MAGIAODICHQUAYPK,MADONVI,LOAIGIAODICH,NGAYTAO,MANGUOITAO,
                                    NGUOITAO,MAQUAYBAN,NGAYPHATSINH,HINHTHUCTHANHTOAN,MAVOUCHER,TIENKHACHDUA,TIENVOUCHER,TIENTHEVIP,TIENTRALAI,TIENTHE,TIENCOD,TIENMAT,TTIENCOVAT,
                                    THOIGIAN,MAKHACHHANG,I_CREATE_DATE,I_CREATE_BY,I_STATE,UNITCODE) VALUES (
                                    :ID,:MAGIAODICH,:MAGIAODICHQUAYPK,:MADONVI,:LOAIGIAODICH,:NGAYTAO,:MANGUOITAO,
                                    :NGUOITAO,:MAQUAYBAN,:NGAYPHATSINH,:HINHTHUCTHANHTOAN,:MAVOUCHER,:TIENKHACHDUA,:TIENVOUCHER,:TIENTHEVIP,:TIENTRALAI,:TIENTHE,:TIENCOD,:TIENMAT,:TTIENCOVAT,
                                    :THOIGIAN,:MAKHACHHANG,:I_CREATE_DATE,:I_CREATE_BY,:I_STATE,:UNITCODE)");
                                            cmd.CommandText = queryInsert;
                                            cmd.CommandType = CommandType.Text;
                                            cmd.Parameters.Add("ID", OracleDbType.NVarchar2, 50).Value               = item.ID;
                                            cmd.Parameters.Add("MAGIAODICH", OracleDbType.NVarchar2, 50).Value       = item.MAGIAODICH;
                                            cmd.Parameters.Add("MAGIAODICHQUAYPK", OracleDbType.NVarchar2, 50).Value = item.MAGIAODICHQUAYPK;
                                            cmd.Parameters.Add("MADONVI", OracleDbType.NVarchar2, 50).Value          = item.UNITCODE;
                                            cmd.Parameters.Add("LOAIGIAODICH", OracleDbType.Int32).Value             = item.LOAIGIAODICH;
                                            cmd.Parameters.Add("NGAYTAO", OracleDbType.Date).Value = item.NGAYTAO;
                                            cmd.Parameters.Add("MANGUOITAO", OracleDbType.NVarchar2, 300).Value        = item.MANGUOITAO;
                                            cmd.Parameters.Add("NGUOITAO", OracleDbType.NVarchar2, 300).Value          = item.NGUOITAO;
                                            cmd.Parameters.Add("MAQUAYBAN", OracleDbType.NVarchar2, 300).Value         = item.MAQUAYBAN;
                                            cmd.Parameters.Add("NGAYPHATSINH", OracleDbType.Date).Value                = item.NGAYPHATSINH;
                                            cmd.Parameters.Add("HINHTHUCTHANHTOAN", OracleDbType.NVarchar2, 200).Value = item.HINHTHUCTHANHTOAN;
                                            cmd.Parameters.Add("MAVOUCHER", OracleDbType.NVarchar2, 50).Value          = item.MAVOUCHER;
                                            cmd.Parameters.Add("TIENKHACHDUA", OracleDbType.Decimal).Value             = item.TIENKHACHDUA;
                                            cmd.Parameters.Add("TIENVOUCHER", OracleDbType.Decimal).Value              = item.TIENVOUCHER;
                                            cmd.Parameters.Add("TIENTHEVIP", OracleDbType.Decimal).Value               = item.TIENTHEVIP;
                                            cmd.Parameters.Add("TIENTRALAI", OracleDbType.Decimal).Value               = item.TIENTRALAI;
                                            cmd.Parameters.Add("TIENTHE ", OracleDbType.Decimal).Value          = item.TIENTHE;
                                            cmd.Parameters.Add("TIENCOD", OracleDbType.Decimal).Value           = item.TIENCOD;
                                            cmd.Parameters.Add("TIENMAT", OracleDbType.Decimal).Value           = item.TIENMAT;
                                            cmd.Parameters.Add("TTIENCOVAT", OracleDbType.Decimal).Value        = item.TTIENCOVAT;
                                            cmd.Parameters.Add("THOIGIAN", OracleDbType.NVarchar2, 150).Value   = item.THOIGIAN;
                                            cmd.Parameters.Add("MAKHACHHANG", OracleDbType.NVarchar2, 50).Value = item.MAKHACHHANG;
                                            cmd.Parameters.Add("I_CREATE_DATE", OracleDbType.Date).Value        = item.NGAYTAO;
                                            cmd.Parameters.Add("I_CREATE_BY", OracleDbType.NVarchar2, 50).Value = item.MANGUOITAO;
                                            cmd.Parameters.Add("I_STATE", OracleDbType.NVarchar2, 50).Value     = "40";
                                            cmd.Parameters.Add("UNITCODE", OracleDbType.NVarchar2, 50).Value    = item.UNITCODE;
                                            if (cmd.ExecuteNonQuery() > 0)
                                            {
                                                hdSV++;
                                                int tempId = 0;
                                                foreach (NVHANGGDQUAY_ASYNCCLIENT itemData in item.LST_DETAILS)
                                                {
                                                    tempId++;
                                                    OracleCommand command2 = new OracleCommand();
                                                    command2.Connection = connection;
                                                    string queryInsertItem =
                                                        string.Format(
                                                            @"INSERT INTO NVHANGGDQUAY_ASYNCCLIENT (ID,MAGDQUAYPK,MAKHOHANG,MADONVI,MAVATTU,BARCODE,TENDAYDU,NGUOITAO,MABOPK,NGAYTAO,NGAYPHATSINH,
                                                SOLUONG,TTIENCOVAT,VATBAN,GIABANLECOVAT,MAKHACHHANG,MAKEHANG,MACHUONGTRINHKM,LOAIKHUYENMAI,TIENCHIETKHAU,TYLECHIETKHAU,TYLEKHUYENMAI,TIENKHUYENMAI,TYLEVOUCHER,
                                                TIENVOUCHER,TYLELAILE,GIAVON,ISBANAM,MAVAT) VALUES (:ID,:MAGDQUAYPK,:MAKHOHANG,:MADONVI,:MAVATTU,:BARCODE,:TENDAYDU,:NGUOITAO,:MABOPK,:NGAYTAO,:NGAYPHATSINH,
                                                :SOLUONG,:TTIENCOVAT,:VATBAN,:GIABANLECOVAT,:MAKHACHHANG,:MAKEHANG,:MACHUONGTRINHKM,:LOAIKHUYENMAI,:TIENCHIETKHAU,:TYLECHIETKHAU,:TYLEKHUYENMAI,:TIENKHUYENMAI,:TYLEVOUCHER,
                                                :TIENVOUCHER,:TYLELAILE,:GIAVON,:ISBANAM,:MAVAT)");
                                                    command2.CommandText = queryInsertItem;
                                                    command2.CommandType = CommandType.Text;
                                                    command2.Parameters.Add("ID", OracleDbType.NVarchar2, 50).Value         = Guid.NewGuid().ToString();
                                                    command2.Parameters.Add("MAGDQUAYPK", OracleDbType.NVarchar2, 50).Value = itemData.MAGDQUAYPK;
                                                    command2.Parameters.Add("MAKHOHANG", OracleDbType.NVarchar2, 50).Value  = itemData.MAKHOHANG;
                                                    command2.Parameters.Add("MADONVI", OracleDbType.NVarchar2, 50).Value    = itemData.MADONVI;
                                                    command2.Parameters.Add("MAVATTU", OracleDbType.NVarchar2, 50).Value    = itemData.MAVATTU;
                                                    command2.Parameters.Add("BARCODE", OracleDbType.NVarchar2, 2000).Value  = itemData.BARCODE;
                                                    command2.Parameters.Add("TENDAYDU", OracleDbType.NVarchar2, 300).Value  = itemData.TENDAYDU;
                                                    command2.Parameters.Add("NGUOITAO", OracleDbType.NVarchar2, 300).Value  = item.MANGUOITAO;
                                                    command2.Parameters.Add("MABOPK", OracleDbType.NVarchar2, 50).Value     = itemData.MABOPK;
                                                    command2.Parameters.Add("NGAYTAO", OracleDbType.Date).Value             = itemData.NGAYTAO;
                                                    command2.Parameters.Add("NGAYPHATSINH", OracleDbType.Date).Value        = itemData.NGAYPHATSINH;
                                                    command2.Parameters.Add("SOLUONG", OracleDbType.Int32).Value            =
                                                        itemData.SOLUONG;
                                                    command2.Parameters.Add("TTIENCOVAT", OracleDbType.Decimal).Value =
                                                        itemData.TTIENCOVAT;
                                                    command2.Parameters.Add("VATBAN", OracleDbType.Decimal).Value =
                                                        itemData.VATBAN;
                                                    command2.Parameters.Add("GIABANLECOVAT", OracleDbType.Decimal).Value =
                                                        itemData.GIABANLECOVAT;
                                                    command2.Parameters.Add("MAKHACHHANG", OracleDbType.NVarchar2, 50).Value =
                                                        itemData.MAKHACHHANG;
                                                    command2.Parameters.Add("MAKEHANG", OracleDbType.NVarchar2, 50).Value =
                                                        itemData.MAKEHANG;
                                                    command2.Parameters.Add("MACHUONGTRINHKM", OracleDbType.NVarchar2, 50).Value
                                                        = itemData.MACHUONGTRINHKM;
                                                    command2.Parameters.Add("LOAIKHUYENMAI", OracleDbType.NVarchar2, 50).Value =
                                                        itemData.LOAIKHUYENMAI;
                                                    command2.Parameters.Add("TIENCHIETKHAU", OracleDbType.Decimal).Value =
                                                        itemData.TIENCHIETKHAU;
                                                    command2.Parameters.Add("TYLECHIETKHAU", OracleDbType.Decimal).Value =
                                                        itemData.TYLECHIETKHAU;
                                                    command2.Parameters.Add("TYLEKHUYENMAI", OracleDbType.Decimal).Value =
                                                        itemData.TYLEKHUYENMAI;
                                                    command2.Parameters.Add("TIENKHUYENMAI", OracleDbType.Decimal).Value =
                                                        itemData.TIENKHUYENMAI;
                                                    command2.Parameters.Add("TYLEVOUCHER", OracleDbType.Decimal).Value =
                                                        itemData.TYLEVOUCHER;
                                                    command2.Parameters.Add("TIENVOUCHER", OracleDbType.Decimal).Value =
                                                        itemData.TIENVOUCHER;
                                                    command2.Parameters.Add("TYLELAILE", OracleDbType.Decimal).Value =
                                                        itemData.TYLELAILE;
                                                    command2.Parameters.Add("GIAVON", OracleDbType.Decimal).Value =
                                                        itemData.GIAVON;
                                                    command2.Parameters.Add("ISBANAM", OracleDbType.Decimal).Value     = 0;
                                                    command2.Parameters.Add("MAVAT", OracleDbType.NVarchar2, 50).Value =
                                                        itemData.MAVAT;
                                                    try
                                                    {
                                                        command2.ExecuteNonQuery();
                                                        mhSV++;
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        WriteLogs.LogError(ex);
                                                    }
                                                }
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            WriteLogs.LogError(ex);
                                        }
                                    }
                                }
                                catch (Exception x) { }
                            }
                            catch (Exception ex)
                            {
                                WriteLogs.LogError(ex);
                            }
                        }
                    }
                }
            }
            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["TBNETERP_CLIENT"].ConnectionString))
            {
                connection.Open();
                if (connection.State == ConnectionState.Open)
                {
                    foreach (NVGDQUAY_ASYNCCLIENT_DTO item in lstDataOracle)
                    {
                        try
                        {
                            SqlCommand sqlCommand = new SqlCommand();
                            sqlCommand.Connection  = connection;
                            sqlCommand.CommandText = @"SELECT * FROM NVGDQUAY_ASYNCCLIENT WHERE MAGIAODICHQUAYPK = '" + item.MAGIAODICHQUAYPK + "'";
                            sqlCommand.CommandType = CommandType.Text;
                            try
                            {
                                SqlDataReader reader = sqlCommand.ExecuteReader();
                                if (!reader.HasRows)
                                {
                                    try
                                    {
                                        string     queryInsert = "";
                                        SqlCommand cmd         = new SqlCommand();
                                        cmd.Connection = connection;
                                        queryInsert    =
                                            string.Format(
                                                @"INSERT INTO NVGDQUAY_ASYNCCLIENT (ID,MAGIAODICH,MAGIAODICHQUAYPK,MADONVI,LOAIGIAODICH,NGAYTAO,MANGUOITAO,
                                    NGUOITAO,MAQUAYBAN,NGAYPHATSINH,HINHTHUCTHANHTOAN,TIENKHACHDUA,TIENVOUCHER,TIENTHEVIP,TIENTRALAI,TIENTHE,TIENCOD,TIENMAT,TTIENCOVAT,
                                    THOIGIAN,MAKHACHHANG,UNITCODE) VALUES (
                                    @ID,@MAGIAODICH,@MAGIAODICHQUAYPK,@MADONVI,@LOAIGIAODICH,@NGAYTAO,@MANGUOITAO,
                                    @NGUOITAO,@MAQUAYBAN,@NGAYPHATSINH,@HINHTHUCTHANHTOAN,@TIENKHACHDUA,@TIENVOUCHER,@TIENTHEVIP,@TIENTRALAI,@TIENTHE,@TIENCOD,@TIENMAT,@TTIENCOVAT,
                                    @THOIGIAN,@MAKHACHHANG,@UNITCODE)");
                                        cmd.CommandText = queryInsert;
                                        cmd.CommandType = CommandType.Text;
                                        cmd.Parameters.Add("ID", SqlDbType.VarChar, 50).Value               = item.ID;
                                        cmd.Parameters.Add("MAGIAODICH", SqlDbType.VarChar, 50).Value       = item.MAGIAODICH;
                                        cmd.Parameters.Add("MAGIAODICHQUAYPK", SqlDbType.VarChar, 50).Value = item.MAGIAODICHQUAYPK;
                                        cmd.Parameters.Add("MADONVI", SqlDbType.NVarChar, 50).Value         = item.UNITCODE;
                                        cmd.Parameters.Add("LOAIGIAODICH", SqlDbType.Int).Value             = item.LOAIGIAODICH;
                                        cmd.Parameters.Add("NGAYTAO", SqlDbType.Date).Value                    = item.NGAYTAO;
                                        cmd.Parameters.Add("MANGUOITAO", SqlDbType.NVarChar, 300).Value        = item.MANGUOITAO;
                                        cmd.Parameters.Add("NGUOITAO", SqlDbType.NVarChar, 300).Value          = item.NGUOITAO;
                                        cmd.Parameters.Add("MAQUAYBAN", SqlDbType.NVarChar, 300).Value         = item.MAQUAYBAN;
                                        cmd.Parameters.Add("NGAYPHATSINH", SqlDbType.Date).Value               = item.NGAYPHATSINH;
                                        cmd.Parameters.Add("HINHTHUCTHANHTOAN", SqlDbType.NVarChar, 200).Value = item.HINHTHUCTHANHTOAN;
                                        cmd.Parameters.Add("TIENKHACHDUA", SqlDbType.Decimal).Value            = item.TIENKHACHDUA;
                                        cmd.Parameters.Add("TIENVOUCHER", SqlDbType.Decimal).Value             = item.TIENVOUCHER;
                                        cmd.Parameters.Add("TIENTHEVIP", SqlDbType.Decimal).Value              = item.TIENTHEVIP;
                                        cmd.Parameters.Add("TIENTRALAI", SqlDbType.Decimal).Value              = item.TIENTRALAI;
                                        cmd.Parameters.Add("TIENTHE ", SqlDbType.Decimal).Value                = item.TIENTHE;
                                        cmd.Parameters.Add("TIENCOD", SqlDbType.Decimal).Value                 = item.TIENCOD;
                                        cmd.Parameters.Add("TIENMAT", SqlDbType.Decimal).Value                 = item.TIENMAT;
                                        cmd.Parameters.Add("TTIENCOVAT", SqlDbType.Decimal).Value              = item.TTIENCOVAT;
                                        cmd.Parameters.Add("THOIGIAN", SqlDbType.NVarChar, 150).Value          = item.THOIGIAN;
                                        cmd.Parameters.Add("MAKHACHHANG", SqlDbType.NVarChar, 50).Value        = item.MAKHACHHANG;
                                        cmd.Parameters.Add("UNITCODE", SqlDbType.NVarChar, 50).Value           = item.UNITCODE;
                                        if (cmd.ExecuteNonQuery() > 0)
                                        {
                                            hdMT++;
                                            int tempId = 0;
                                            foreach (NVHANGGDQUAY_ASYNCCLIENT itemData in item.LST_DETAILS)
                                            {
                                                tempId++;
                                                SqlCommand command2 = new SqlCommand();
                                                command2.Connection = connection;
                                                string queryInsertItem = string.Format(@"INSERT INTO [dbo].[NVHANGGDQUAY_ASYNCCLIENT]([ID],[MAGDQUAYPK],[MAKHOHANG],[MADONVI],[MAVATTU],[MANGUOITAO],[NGUOITAO],[MABOPK],[NGAYTAO],[NGAYPHATSINH],[SOLUONG],[TTIENCOVAT],[GIABANLECOVAT],[TYLECHIETKHAU],[TIENCHIETKHAU],[TYLEKHUYENMAI],[TIENKHUYENMAI],[TYLEVOUCHER],[TIENVOUCHER],[TYLELAILE],[GIAVON],[MAVAT],[VATBAN],[MACHUONGTRINHKM],[UNITCODE]) 
                                    VALUES (@ID,@MAGDQUAYPK,@MAKHOHANG,@MADONVI,@MAVATTU,@MANGUOITAO,@NGUOITAO,@MABOPK,@NGAYTAO,@NGAYPHATSINH,@SOLUONG,@TTIENCOVAT,@GIABANLECOVAT,@TYLECHIETKHAU,@TIENCHIETKHAU,@TYLEKHUYENMAI,@TIENKHUYENMAI,@TYLEVOUCHER,@TIENVOUCHER,@TYLELAILE,@GIAVON,@MAVAT,@VATBAN,@MACHUONGTRINHKM,@UNITCODE)");
                                                command2.CommandText = queryInsertItem;
                                                command2.CommandType = CommandType.Text;
                                                command2.Parameters.Add("ID", SqlDbType.NVarChar, 50).Value              = itemData.ID;
                                                command2.Parameters.Add("MAGDQUAYPK", SqlDbType.NVarChar, 50).Value      = itemData.MAGDQUAYPK;
                                                command2.Parameters.Add("MAKHOHANG", SqlDbType.NVarChar, 50).Value       = itemData.MAKHOHANG;
                                                command2.Parameters.Add("MADONVI", SqlDbType.NVarChar, 50).Value         = itemData.MADONVI;
                                                command2.Parameters.Add("MAVATTU", SqlDbType.NVarChar, 50).Value         = itemData.MAVATTU;
                                                command2.Parameters.Add("MANGUOITAO", SqlDbType.NVarChar, 50).Value      = Session.Session.CurrentMaNhanVien;
                                                command2.Parameters.Add("NGUOITAO", SqlDbType.NVarChar, 50).Value        = itemData.NGUOITAO;
                                                command2.Parameters.Add("MABOPK", SqlDbType.NVarChar, 50).Value          = itemData.MABOPK;
                                                command2.Parameters.Add("NGAYTAO", SqlDbType.Date).Value                 = itemData.NGAYTAO;
                                                command2.Parameters.Add("NGAYPHATSINH", SqlDbType.Date).Value            = itemData.NGAYPHATSINH;
                                                command2.Parameters.Add("SOLUONG", SqlDbType.Decimal).Value              = itemData.SOLUONG;
                                                command2.Parameters.Add("TTIENCOVAT", SqlDbType.Decimal).Value           = itemData.TTIENCOVAT;
                                                command2.Parameters.Add("GIABANLECOVAT", SqlDbType.Decimal).Value        = itemData.GIABANLECOVAT;
                                                command2.Parameters.Add("TIENCHIETKHAU", SqlDbType.Decimal).Value        = itemData.TIENCHIETKHAU;
                                                command2.Parameters.Add("TYLECHIETKHAU", SqlDbType.Decimal).Value        = itemData.TYLECHIETKHAU;
                                                command2.Parameters.Add("TYLEKHUYENMAI", SqlDbType.Decimal).Value        = itemData.TYLEKHUYENMAI;
                                                command2.Parameters.Add("TIENKHUYENMAI", SqlDbType.Decimal).Value        = itemData.TIENKHUYENMAI;
                                                command2.Parameters.Add("TYLEVOUCHER", SqlDbType.Decimal).Value          = itemData.TYLEVOUCHER;
                                                command2.Parameters.Add("TIENVOUCHER", SqlDbType.Decimal).Value          = itemData.TIENVOUCHER;
                                                command2.Parameters.Add("TYLELAILE", SqlDbType.Decimal).Value            = itemData.TYLELAILE;
                                                command2.Parameters.Add("GIAVON", SqlDbType.Decimal).Value               = itemData.GIAVON;
                                                command2.Parameters.Add("MAVAT", SqlDbType.NVarChar, 50).Value           = itemData.MAVAT;
                                                command2.Parameters.Add("VATBAN", SqlDbType.Decimal).Value               = itemData.VATBAN;
                                                command2.Parameters.Add("MACHUONGTRINHKM", SqlDbType.NVarChar, 50).Value = itemData.MACHUONGTRINHKM;
                                                command2.Parameters.Add("UNITCODE", SqlDbType.NVarChar, 50).Value        = itemData.UNITCODE != null ? itemData.UNITCODE : ";";
                                                try
                                                {
                                                    command2.ExecuteNonQuery();
                                                    mhMT++;
                                                }
                                                catch (Exception ex)
                                                {
                                                    WriteLogs.LogError(ex);
                                                }
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        WriteLogs.LogError(ex);
                                    }
                                }
                            }
                            catch (Exception x) { }
                        }
                        catch (Exception ex)
                        {
                            WriteLogs.LogError(ex);
                        }
                    }
                }
            }
            MessageBox.Show("Đã đồng bộ " + hdSV + " hóa đơn trên server với " + mhSV + " mặt hàng \n " + hdMT + " hóa đơn sql với " + mhMT + "mặt hàng");
        }