private void InserVaoRaCa(LinqToExcel.Row row, int timeIndex, DateTime time) { VaoRaCaController controller = new VaoRaCaController(); DAL.VaoRaCa vao = new VaoRaCa(); vao.MaCa = ""; vao.Order = 1; vao.MaChamCong = row[maChamCong].ToString().Trim(); vao.Time = row[timeIndex].ToString().Trim(); if (vao.Time.Length <= 5) { vao.Time += ":00"; } string _time = string.Empty; if (int.Parse(vao.Time.Split(':')[0]) > 23) { _time = "23:59:00"; } else { _time = vao.Time; } vao.NgayChamCong = DateTime.Parse(time.ToString("yyyy-MM-dd " + _time)); vao.ID = vao.MaChamCong + vao.NgayChamCong.Day + vao.NgayChamCong.Month + vao.NgayChamCong.Year + vao.NgayChamCong.Hour + vao.NgayChamCong.Minute + vao.NgayChamCong.Second; vao.DiVao = true; controller.InsertAndUpdate(vao); }
/// <summary> /// Hàm tính toán tổng hợp công /// </summary> /// <param name="lists">Danh sách thông tin chấm công cần tính</param> /// <param name="isNew"><b>true</b> nếu tổng hợp mới, <b>false</b> nếu cập nhật lại</param> private string TinhToanThongTinCong(List <TongHopCongTheoThangInfo> lists, bool isNew) { try { TimeController timeController = new TimeController(); string error = ""; #region lấy các cấu hình cho tổng hợp công // lấy các ngày cuối tuần trong tháng List <string> listWeekend = timeController.GetWeekKend(Session["MaDonVi"].ToString()); // lấy danh sách chấm công đặc biệt Dictionary <string, int> dicSpecialEmployee = new Dictionary <string, int>(); List <DAL.DanhSachNhanVienChamCongDacBiet> listEmployees = new DieuKienChamCongDacBietController().GetByAll(); foreach (var item in listEmployees) { dicSpecialEmployee.Add(item.MaCB, item.SoLanChitTay); } // lấy ngày công chuẩn //double ngayCongChuan = timeController.GetNumberDayOfWork(); #endregion // lấy tháng DAL.DanhSachBangTongHopCong thcong = new DanhSachBangTongHopCongController().GetById(int.Parse(hdfIdBangTongHopCong.Text)); //int maxDays = 31;//DateTime.DaysInMonth(thcong.Nam, thcong.Thang); int tong = 0; foreach (var item in lists) { try { tong++; #region các tham biến double tongGioCongDinhMuc = 0, tongGioCongThucTe = 0; int tongPhutDiTre = 0, tongPhutVeSom = 0, tongSoPhutLamThuaGio = 0; int tongSoPhutLamThemNgayThuong = 0, tongSoPhutLamThemNgayNghi = 0, tongSoPhutLamThemNgayLe = 0; double nghiLe = 0, nghiPhep = 0, nghiCheDo = 0, nghiBu = 0, nghiKhongLuong = 0; int tongSoLamQuenQuetThe = 0, tongSoLanDiMuon = 0, tongSoLanVeSom = 0; string ngayLe = "", thongKeCaLamViec = ""; float tongCaLamViecNgayThuong = 0, tongCaLamViecNgayNghi = 0, tongCaLamViecNgayLe = 0, tongThoiGianRaNgoaiBiTruGio = 0, tongCaNghi = 0; bool isFail = false; int soLanChitTayBatBuoc = -1; if (dicSpecialEmployee.ContainsKey(item.MA_CB)) { soLanChitTayBatBuoc = dicSpecialEmployee[item.MA_CB]; } // thống kê ca làm việc định dạng MaCa1=a,MaCa2=b Dictionary <string, int> dicThongKeCaLamViec = new Dictionary <string, int>(); #endregion // tính toán các ngày nghỉ //if (soLanChitTayBatBuoc == -1) new TongHopCongController().GetNgayNghi(item.MA_CB, thcong.FromDate, thcong.ToDate, ref ngayLe, ref nghiLe, ref nghiPhep, ref nghiCheDo, ref nghiBu, ref nghiKhongLuong, Session["MaDonVi"].ToString()); DateTime day = thcong.FromDate; while (day <= thcong.ToDate) { #region tổng hợp thông tin trong một ngày try { #region các biến cục bộ double gioCongDinhMuc = 0, gioCongThucTe = 0; int soPhutDiTre = 0, soPhutVeSom = 0, soPhutDiSom = 0, soPhutVeMuon = 0; int soPhutLamThemNgayThuong = 0, soPhutLamThemNgayNghi = 0, soPhutLamThemNgayLe = 0, soPhutLamThuaGio = 0; int soLanQuenQuetThe = 0, soLanDiMuon = 0, soLanVeSom = 0; float soCaLamViecNgayThuong = 0, soCaLamViecNgayNghi = 0, soCaLamViecNgayLe = 0, thoiGianRaNgoaiBiTruGio = 0, soCaNghi = 0; string thoiGianDiFirst = "", thoiGianVeLast = ""; DAL.DanhSachCa ca = new DanhSachCa(); #endregion try { // lấy ca làm việc của cán bộ ca = new DanhSachCaController().GetByMaChamCong(item.MaChamCong, day, Session["MaDonVi"].ToString()); #region cập nhật thống kê ca làm việc if (ca == null) { continue; } #endregion // tính các tham số liên quan if (soLanChitTayBatBuoc == -1) { new TongHopCongController().GetCaLamViecTrongNgay(ngayLe.Split(','), listWeekend, item.MaChamCong, day, ca, ref dicThongKeCaLamViec, ref gioCongDinhMuc, ref gioCongThucTe, ref soPhutDiTre, ref soPhutVeSom, ref soPhutDiSom, ref soPhutVeMuon, ref soPhutLamThemNgayThuong, ref soPhutLamThemNgayNghi, ref soPhutLamThemNgayLe, ref soLanQuenQuetThe, ref soLanDiMuon, ref soLanVeSom, ref soPhutLamThuaGio, ref soCaLamViecNgayThuong, ref soCaLamViecNgayNghi, ref soCaLamViecNgayLe, ref thoiGianRaNgoaiBiTruGio, ref soCaNghi, ref thoiGianDiFirst, ref thoiGianVeLast); //new TongHopCongController().GetCaLamViecTrongNgay1(ngayLe.Split(','), listWeekend, item.MaChamCong, day, ca, ref gioCongDinhMuc, // ref gioCongThucTe, ref soPhutDiTre, ref soPhutVeSom, ref thoiGianDiFirst, ref thoiGianVeLast, ref thoiGianRaNgoaiBiTruGio, // ref soLanDiMuon, ref soLanVeSom); } else { List <DAL.VaoRaCa> dsVaoRaCa = new VaoRaCaController().GetByMaChamCongAndDay(item.MaChamCong, day); if (dsVaoRaCa.Count >= soLanChitTayBatBuoc) { //gioCongDinhMuc += ca.TongGio != null ? ca.TongGio.Value : 0; //gioCongThucTe += (ca.TongGio != null ? ca.TongGio.Value : 0) * 60; if (ca.NghiGiuaCa != "" && ca.VaoGiuaCa != "") { gioCongThucTe += 1; soCaLamViecNgayThuong += 1; } else { gioCongThucTe += 0.5; soCaLamViecNgayThuong += (float)0.5; } } } } catch (Exception ex) { isFail = true; error += ex.Message + "<br />"; } #region tính các thời gian liên quan DAL.TongHopCongTheoNgay theoNgay = new TongHopCongTheoNgay(); theoNgay.MaCa = ca.MaCa; theoNgay.MaChamCong = item.MaChamCong; theoNgay.NgayThang = day; //theoNgay.SoLanDiMuon = soLanDiMuon; //theoNgay.SoLanVeSom = soLanVeSom; //theoNgay.SoNgayCong = Math.Round((gioCongThucTe / ca.TongGio == 0 ? 1 : ca.TongGio), 1); theoNgay.SoPhutDiMuon = soPhutDiTre; //theoNgay.SoPhutDiSom = soPhutVeSom; //theoNgay.SoPhutLamThemNgayLe = soPhutLamThemNgayLe; //theoNgay.SoPhutLamThemNgayNghi = soPhutLamThemNgayNghi; //theoNgay.SoPhutLamThemNgayThuong = soPhutLamThemNgayThuong; //theoNgay.SoPhutLamThuaGio = soPhutLamThuaGio; //theoNgay.SoPhutLamViec = gioCongThucTe; //theoNgay.SoPhutRaNgoai = //tongGioCongDinhMuc += gioCongDinhMuc; //tongGioCongThucTe += gioCongThucTe; //tongPhutDiTre += soPhutDiTre; //tongPhutVeSom += soPhutVeSom; //tongSoPhutLamThemNgayThuong += soPhutLamThemNgayThuong; //tongSoPhutLamThemNgayNghi += soPhutLamThemNgayNghi; //tongSoPhutLamThemNgayLe += soPhutLamThemNgayLe; //tongSoLamQuenQuetThe += soLanQuenQuetThe; //tongSoLanDiMuon += soLanDiMuon; //tongSoLanVeSom += soLanVeSom; //tongSoPhutLamThuaGio += soPhutLamThuaGio; //tongCaLamViecNgayThuong += soCaLamViecNgayThuong; //tongCaLamViecNgayNghi += soCaLamViecNgayNghi; //tongCaLamViecNgayLe += soCaLamViecNgayLe; //tongThoiGianRaNgoaiBiTruGio += thoiGianRaNgoaiBiTruGio; //tongCaNghi += soCaNghi; #endregion day.AddDays(1); } catch (Exception ex) { error += ex.Message + "<br />"; } #endregion } // thống kê số ca làm việc của từng cán bộ if (soLanChitTayBatBuoc == -1) { thongKeCaLamViec = new TongHopCongController().GetThongKeCaLamViec(dicThongKeCaLamViec); } #region Cập nhật vào bảng tổng hợp công //DAL.TongHopCong cong = new TongHopCong() //{ // MA_CB = item.MA_CB, // IdDanhSachBangTongHopCong = int.Parse(hdfIdBangTongHopCong.Text), // SoPhutDiTre = tongPhutDiTre, // SoPhutLamThemNgayLe = tongSoPhutLamThemNgayLe, // SoPhutLamThemNgayNghi = tongSoPhutLamThemNgayNghi, // SoPhutLamThemNgayThuong = tongSoPhutLamThemNgayThuong, // GioCongThucTe = tongGioCongThucTe, // tính theo phút // GioCongDinhMuc = tongGioCongDinhMuc, // SoPhutVeSom = tongPhutVeSom, // NghiBu = nghiBu, // NghiKhongLuong = nghiKhongLuong, // NghiCheDo = nghiCheDo, // NghiLe = nghiLe, // NghiPhep = nghiPhep, // TinhToanSai = isFail, // SoLanQuenQuetThe = tongSoLamQuenQuetThe, // SoLanDiTre = tongSoLanDiMuon, // SoLanVeSom = tongSoLanVeSom, // TongThoiGianLamThuaGio = tongSoPhutLamThuaGio, // ThongKeCaLamViec = thongKeCaLamViec, // TongCaLamViecNgayThuong = tongCaLamViecNgayThuong, // TongCaLamViecNgayNghi = tongCaLamViecNgayNghi, // TongCaLamViecNgayLe = tongCaLamViecNgayLe, // ThoiGianRaNgoaiBiTru = tongThoiGianRaNgoaiBiTruGio, // TongCaNghi = tongCaNghi, //}; //if (isNew == true) //{ // new TongHopCongController().Insert(cong); //} //else //{ // cong.ID = item.ID; // new TongHopCongController().Update(cong); //} #endregion } catch (Exception ex) { error += ex.Message + "<br />"; } } X.Msg.Alert("", error).Show(); return(""); } catch (Exception ex) { X.Msg.Alert("Thông báo từ hệ thống", ex.Message).Show(); return(ex.Message); } }
protected void btnImport_Click(object sender, DirectEventArgs e) { try { VaoRaCaController controller = new VaoRaCaController(); TongHopCongTheoNgayController ngayCtr = new TongHopCongTheoNgayController(); int ngayChamCong = 6; int gioVao = 7; int gioRa = 8; int count = 0; int rowIndex = 0; string oldMaChamCong = string.Empty; string extension = System.IO.Path.GetExtension(fUpload.PostedFile.FileName).ToLower(); if (!extension.Equals(".xls") && !extension.Equals(".xlsx")) { X.Msg.Alert("Thông báo", "File bạn chọn không phải Excel").Show(); return; } string fileName = System.IO.Path.GetFileName(fUpload.PostedFile.FileName); string fileLocation = Server.MapPath("File") + "\\" + fileName; string error = ""; List <Row> dataExcel = ExcelEngine.GetInstance().GetDataFromExcel(fileLocation, cbSheetName.SelectedItem.Value, 0); foreach (Row item in dataExcel) { try { rowIndex++; if (count > 20) { break; } // xóa dữ liệu cũ if (chkXoa.Checked) { if (!string.IsNullOrEmpty(item[maChamCong].ToString().Trim()) && item[maChamCong].ToString().Trim() != oldMaChamCong) { if (!string.IsNullOrEmpty(item[ngayChamCong].ToString().Trim())) { string ngayChamCongString = item[ngayChamCong].ToString(); if (ngayChamCongString.Length > 10) { ngayChamCongString = ngayChamCongString.Remove(10); } DateTime time = DateTime.ParseExact(ngayChamCongString, "dd/MM/yyyy", null); controller.DeleteByMaChamCongAndMonthYear(item[maChamCong].ToString().Trim(), time); ngayCtr.DeleteByDay(time, item[maChamCong].ToString().Trim()); oldMaChamCong = item[maChamCong].ToString().Trim(); } } } // nếu có dữ liệu if (!string.IsNullOrEmpty(item[maChamCong].ToString().Trim()) && !string.IsNullOrEmpty(item[ngayChamCong].ToString().Trim()) && (!string.IsNullOrEmpty(item[gioVao].ToString().Trim()) || !string.IsNullOrEmpty(item[gioRa].ToString().Trim()))) { count = 0; string ngayChamCongString = item[ngayChamCong].ToString(); if (ngayChamCongString.Length > 10) { ngayChamCongString = ngayChamCongString.Remove(10); } DateTime time = DateTime.ParseExact(ngayChamCongString, "dd/MM/yyyy", null); //if (chkXoa.Checked) //{ // controller.DeleteByMaChamCongAndMonthYear(item[maChamCong].ToString().Trim(), time); //} if (!string.IsNullOrEmpty(item[gioVao].ToString().Trim())) { InserVaoRaCa(item, gioVao, time); } if (!string.IsNullOrEmpty(item[gioRa].ToString().Trim())) { InserVaoRaCa(item, gioRa, time); } } else { count++; } } catch (Exception ex) { // error += item[maChamCong].ToString().Trim() + "-" + item[ngayChamCong].ToString().Trim() + "-" + // item[gioVao].ToString().Trim() + "-" + item[gioRa].ToString().Trim() + "<br/>"; //error += "Number : " + count + item[maChamCong].ToString() + rowIndex + ex.Message + ",";// ex.Message + "(" + count + ")"; } } if (string.IsNullOrEmpty(error)) { Dialog.ShowNotification("Nhập dữ liệu từ Excel thành công"); } else { Dialog.ShowError("Không đọc được dòng " + error.Remove(error.LastIndexOf(","))); } wdImportExcelFile.Hide(); } catch (Exception ex) { Dialog.ShowError(ex.Message); } finally { string fn = System.IO.Path.GetFileName(fUpload.PostedFile.FileName); string saveLocation = Server.MapPath("File") + "\\" + fn; FileInfo file = new FileInfo(saveLocation); if (file.Exists) { file.Delete(); } } }