public ActionResult CapNhatDiemDo_CongToModal(int DiemDoID = -1, int CongToID = -1, int LienKetID = -1) { CapNhatDiemDo_CongToViewModel ct = new CapNhatDiemDo_CongToViewModel(); // Cap nhat Cong To if (CongToID != -1) { ViewBag.CongToManage = "edit"; ViewBag.DiemDoID = DiemDoID; ViewBag.LienKetID = LienKetID; var rs = CongToDAO.GetCongToTheoDiemDoByCongToID(CongToID, DiemDoID, out ct); return(View(ct)); } else { // Thay doi cong to ViewBag.CongToManage = "change"; ViewBag.DiemDoID = DiemDoID; ViewBag.LienKetID = LienKetID; return(View()); } }
public void OnCreatedTSVH(object source, FileSystemEventArgs e) { Common.MoveFile(e, conf); /*ShowNotificationMessage(500, "Create", $"{e.Name}", ToolTipIcon.None);*/ for (int count = 0; count <= 2000; count++) { try { DbContextService db = new DbContextService(); //Console.WriteLine("Try to access file !!!"); reader = new StreamReader(e.FullPath); //Console.WriteLine("Access file successfully !!!"); string fileName = e.Name.Split('.')[0]; string serial = fileName.Split('_')[0]; // check Serial Cong To if (!CongToDAO.CheckSerialCongTo(serial)) { //ShowNotificationMessage(50, "Error", "Công to serial không tồn tại", ToolTipIcon.Error); reader.Close(); return; } // read file string line; List <string> data = new List <string>(); while ((line = reader.ReadLine()) != null) { data.Add(line); } DateTime dt = new DateTime(); var dt_Str = data[1].Split(',')[2]; var rs_Dt = DateTime.TryParseExact(dt_Str, "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt); if (!rs_Dt) { //ShowNotificationMessage(50, "Error", "Định dạng thời gian không đúng", ToolTipIcon.Error); reader.Close(); return; } if (!ThongSoVanHanhDAO.checkExistTSVH(serial, dt)) { ThongSoVanHanh tsvh = new ThongSoVanHanh(); tsvh.Serial = serial; tsvh.ThoiGianCongTo = dt; var bool_rs = true; //var he_so_nhan = 0.001;//from W to kW tsvh.P_Nhan = Common.ParseDouble(data[6 - 1].Split(',')[1], ref bool_rs); tsvh.P_Giao = Common.ParseDouble(data[7 - 1].Split(',')[1], ref bool_rs); tsvh.Q_Nhan = Common.ParseDouble(data[13 - 1].Split(',')[1], ref bool_rs); tsvh.Q_Giao = Common.ParseDouble(data[14 - 1].Split(',')[1], ref bool_rs); tsvh.P_Nhan_BT = Common.ParseDouble(data[19 - 1].Split(',')[1], ref bool_rs); tsvh.P_Nhan_CD = Common.ParseDouble(data[20 - 1].Split(',')[1], ref bool_rs); tsvh.P_Nhan_TD = Common.ParseDouble(data[21 - 1].Split(',')[1], ref bool_rs); tsvh.P_Giao_BT = Common.ParseDouble(data[22 - 1].Split(',')[1], ref bool_rs); tsvh.P_Giao_CD = Common.ParseDouble(data[23 - 1].Split(',')[1], ref bool_rs); tsvh.P_Giao_TD = Common.ParseDouble(data[24 - 1].Split(',')[1], ref bool_rs); tsvh.PhaseA_Amps = Common.ParseDouble(data[72 - 1].Split(',')[1], ref bool_rs); tsvh.PhaseA_Volts = Common.ParseDouble(data[73 - 1].Split(',')[1], ref bool_rs); tsvh.PhaseA_PowerFactor = Common.ParseDouble(data[77 - 1].Split(',')[1], ref bool_rs); tsvh.PhaseA_Frequency = Common.ParseDouble(data[78 - 1].Split(',')[1], ref bool_rs); tsvh.PhaseA_Angle = Common.ParseDouble(data[79 - 1].Split(',')[1], ref bool_rs); tsvh.PhaseB_Amps = Common.ParseDouble(data[72 - 1].Split(',')[2], ref bool_rs); tsvh.PhaseB_Volts = Common.ParseDouble(data[73 - 1].Split(',')[2], ref bool_rs); tsvh.PhaseB_PowerFactor = Common.ParseDouble(data[77 - 1].Split(',')[2], ref bool_rs); tsvh.PhaseB_Frequency = Common.ParseDouble(data[78 - 1].Split(',')[2], ref bool_rs); tsvh.PhaseB_Angle = Common.ParseDouble(data[79 - 1].Split(',')[2], ref bool_rs); tsvh.PhaseC_Amps = Common.ParseDouble(data[72 - 1].Split(',')[3], ref bool_rs); tsvh.PhaseC_Volts = Common.ParseDouble(data[73 - 1].Split(',')[3], ref bool_rs); tsvh.PhaseC_PowerFactor = Common.ParseDouble(data[77 - 1].Split(',')[3], ref bool_rs); tsvh.PhaseC_Frequency = Common.ParseDouble(data[78 - 1].Split(',')[3], ref bool_rs); tsvh.PhaseC_Angle = Common.ParseDouble(data[79 - 1].Split(',')[3], ref bool_rs); tsvh.Phase_Rotation = data[80 - 1].Split(',')[4]; if (!bool_rs) { //ShowNotificationMessage(50, "Error", "Lỗi format number in file", ToolTipIcon.Error); reader.Close(); return; } var rs = ThongSoVanHanhDAO.Create(tsvh); if (!rs.Equals("success")) { //ShowNotificationMessage(50, "Error", rs, ToolTipIcon.Error); reader.Close(); return; } } //ShowNotificationMessage(50, "Success", "Reading file 'Thông số vận hành' finished!!!!", ToolTipIcon.Info); //reader.Close(); break; } catch (IOException) { //Console.WriteLine("Wait to access file !!!"); //ShowNotificationMessage(50, "Error", "Wait to access file !!!", ToolTipIcon.Error); Thread.Sleep(100); } catch { //Console.WriteLine(ex.Message); //ShowNotificationMessage(50, "Error", ex.Message, ToolTipIcon.Error); break; } finally { try { reader.Close(); } catch { } } } }
public void OnCreatedCSC(object source, FileSystemEventArgs e) { Common.MoveFile(e, conf); /*ShowNotificationMessage(500, "Create", $"{e.Name}", ToolTipIcon.None);*/ for (var count = 0; count < 20000; count++) { try { DbContextService db = new DbContextService(); //Console.WriteLine("Try to access file !!!"); reader = new StreamReader(e.FullPath); //Console.WriteLine("Access file successfully !!!"); string fileName = e.Name.Split('.')[0]; string serial = fileName.Split('_')[0]; // check Serial Cong To if (!CongToDAO.CheckSerialCongTo(serial)) { //ShowNotificationMessage(50, "Error", "Công to serial không tồn tại", ToolTipIcon.Error); reader.Close(); return; } // read file string line; List <string> data = new List <string>(); while ((line = reader.ReadLine()) != null) { data.Add(line); } int numberRecord = int.Parse(Math.Floor((Decimal)data.Count / 74).ToString()); for (int i = 0; i < 3; i++) { data.RemoveAt(0); } for (int i = 0; i < numberRecord; i++) { DateTime dt = DateTime.Parse(data[i * 74 + 72 - 1].Split(',')[1]); if (!ChiSoChotDAO.checkExistCSC(serial, dt)) { ChiSoChot csc = new ChiSoChot(); csc.CongToSerial = serial; csc.thang = dt; var bool_check = true; csc.TongGiao = Common.ParseDouble(data[i * 74 + 7 - 1].Split(',')[1], ref bool_check); csc.PhanKhangGiao = Common.ParseDouble(data[i * 74 + 14 - 1].Split(',')[1], ref bool_check); csc.BinhThuongGiao = Common.ParseDouble(data[i * 74 + 22 - 1].Split(',')[1], ref bool_check); csc.CaoDiemGiao = Common.ParseDouble(data[i * 74 + 23 - 1].Split(',')[1], ref bool_check); csc.ThapDiemGiao = Common.ParseDouble(data[i * 74 + 24 - 1].Split(',')[1], ref bool_check); csc.TongNhan = Common.ParseDouble(data[i * 74 + 6 - 1].Split(',')[1], ref bool_check); csc.PhangKhangNhan = Common.ParseDouble(data[i * 74 + 13 - 1].Split(',')[1], ref bool_check); csc.BinhThuongNhan = Common.ParseDouble(data[i * 74 + 19 - 1].Split(',')[1], ref bool_check); csc.CaoDiemNhan = Common.ParseDouble(data[i * 74 + 20 - 1].Split(',')[1], ref bool_check); csc.ThapDiemNhan = Common.ParseDouble(data[i * 74 + 21 - 1].Split(',')[1], ref bool_check); var rs = ChiSoChotDAO.Create(csc); if (!rs.Equals("success")) { //ShowNotificationMessage(50, "Error", rs, ToolTipIcon.Info); reader.Close(); return; } } } //ShowNotificationMessage(50, "Success", "Reading file 'Chỉ Số Chốt' finished!!!!", ToolTipIcon.Info); //reader.Close(); break; } catch (IOException) { //Console.WriteLine("Wait to access file !!!"); //ShowNotificationMessage(50, "Error", "Wait to access file !!!", ToolTipIcon.Error); Thread.Sleep(100); } catch { //Console.WriteLine(ex.Message); //ShowNotificationMessage(50, "Error", ex.Message, ToolTipIcon.Error); break; } finally { try { reader.Close(); } catch { } } } }
public void OnCreatedCSC(object source, FileSystemEventArgs e) { /*ShowNotificationMessage(500, "Create", $"{e.Name}", ToolTipIcon.None);*/ while (true) { try { DbContextService db = new DbContextService(); //Console.WriteLine("Try to access file !!!"); StreamReader reader = new StreamReader(e.FullPath); //Console.WriteLine("Access file successfully !!!"); string fileName = e.Name.Split('.')[0]; string serial = fileName.Split('_')[0]; // check Serial Cong To if (!CongToDAO.CheckSerialCongTo(serial)) { ShowNotificationMessage(50, "Error", "Công to serial không tồn tại", ToolTipIcon.Error); reader.Close(); return; } // read file string line; List <string> data = new List <string>(); while ((line = reader.ReadLine()) != null) { data.Add(line); } int numberRecord = int.Parse(Math.Floor((Decimal)data.Count / 58).ToString()); for (int i = 0; i < 3; i++) { data.RemoveAt(0); } for (int i = 0; i < numberRecord; i++) { DateTime dt = DateTime.Parse(data[i * 58 + 56 - 1].Split(',')[1]); if (!ChiSoChotDAO.checkExistCSC(serial, dt)) { ChiSoChot csc = new ChiSoChot(); csc.CongToSerial = serial; csc.thang = dt; csc.TongGiao = double.Parse(data[i * 58 + 7 - 1].Split(',')[1]); csc.PhanKhangGiao = double.Parse(data[i * 58 + 14 - 1].Split(',')[1]); csc.BinhThuongGiao = double.Parse(data[i * 58 + 22 - 1].Split(',')[1]); csc.CaoDiemGiao = double.Parse(data[i * 58 + 23 - 1].Split(',')[1]); csc.ThapDiemGiao = double.Parse(data[i * 58 + 24 - 1].Split(',')[1]); csc.TongNhan = double.Parse(data[i * 58 + 6 - 1].Split(',')[1]); csc.PhangKhangNhan = double.Parse(data[i * 58 + 13 - 1].Split(',')[1]); csc.BinhThuongNhan = double.Parse(data[i * 58 + 19 - 1].Split(',')[1]); csc.CaoDiemNhan = double.Parse(data[i * 58 + 20 - 1].Split(',')[1]); csc.ThapDiemNhan = double.Parse(data[i * 58 + 21 - 1].Split(',')[1]); var rs = ChiSoChotDAO.Create(csc); if (!rs.Equals("success")) { ShowNotificationMessage(50, "Error", rs, ToolTipIcon.Info); reader.Close(); return; } } } ShowNotificationMessage(50, "Success", "Reading file 'Chỉ Số Chốt' finished!!!!", ToolTipIcon.Info); reader.Close(); break; } catch (IOException) { //Console.WriteLine("Wait to access file !!!"); ShowNotificationMessage(50, "Error", "Wait to access file !!!", ToolTipIcon.Error); Thread.Sleep(100); } catch (Exception ex) { //Console.WriteLine(ex.Message); ShowNotificationMessage(50, "Error", ex.Message, ToolTipIcon.Error); break; } finally { try { string fileName = e.Name; string sourcePath = conf.ThuMucQuet; string targetPath = conf.ThuMucChuyen; //Combine file và đường dẫn string sourceFile = System.IO.Path.Combine(sourcePath, fileName); string destFile = System.IO.Path.Combine(targetPath, fileName); //Copy file từ file nguồn đến file đích System.IO.File.Copy(sourceFile, destFile, true); ShowNotificationMessage(50, "Di chuyển file !!!", "Thành công", ToolTipIcon.None); } catch (Exception ex) { ShowNotificationMessage(50, "Error !!!", ex.Message, ToolTipIcon.Error); } } } }
public void OnCreatedTSVH(object source, FileSystemEventArgs e) { /*ShowNotificationMessage(500, "Create", $"{e.Name}", ToolTipIcon.None);*/ while (true) { try { DbContextService db = new DbContextService(); //Console.WriteLine("Try to access file !!!"); StreamReader reader = new StreamReader(e.FullPath); //Console.WriteLine("Access file successfully !!!"); string fileName = e.Name.Split('.')[0]; string serial = fileName.Split('_')[0]; // check Serial Cong To if (!CongToDAO.CheckSerialCongTo(serial)) { ShowNotificationMessage(50, "Error", "Công to serial không tồn tại", ToolTipIcon.Error); reader.Close(); return; } // read file string line; List <string> data = new List <string>(); while ((line = reader.ReadLine()) != null) { data.Add(line); } DateTime dt = new DateTime(); var dt_Str = data[1].Split(',')[2]; var rs_Dt = DateTime.TryParseExact(dt_Str, "M/dd/yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt); if (!rs_Dt) { ShowNotificationMessage(50, "Error", "Định dạng thời gian không đúng", ToolTipIcon.Error); reader.Close(); return; } if (!ThongSoVanHanhDAO.checkExistTSVH(serial, dt)) { ThongSoVanHanh tsvh = new ThongSoVanHanh(); tsvh.Serial = serial; tsvh.ThoiGianCongTo = dt; tsvh.P_Nhan = double.Parse(data[6 - 1].Split(',')[1]); tsvh.P_Giao = double.Parse(data[7 - 1].Split(',')[1]); tsvh.Q_Nhan = double.Parse(data[13 - 1].Split(',')[1]); tsvh.Q_Giao = double.Parse(data[14 - 1].Split(',')[1]); tsvh.P_Nhan_BT = double.Parse(data[19 - 1].Split(',')[1]); tsvh.P_Nhan_CD = double.Parse(data[20 - 1].Split(',')[1]); tsvh.P_Nhan_TD = double.Parse(data[21 - 1].Split(',')[1]); tsvh.P_Giao_BT = double.Parse(data[22 - 1].Split(',')[1]); tsvh.P_Giao_CD = double.Parse(data[23 - 1].Split(',')[1]); tsvh.P_Giao_TD = double.Parse(data[24 - 1].Split(',')[1]); tsvh.PhaseA_Amps = double.Parse(data[56 - 1].Split(',')[1]); tsvh.PhaseA_Volts = double.Parse(data[57 - 1].Split(',')[1]); tsvh.PhaseA_PowerFactor = double.Parse(data[61 - 1].Split(',')[1]); tsvh.PhaseA_Frequency = double.Parse(data[62 - 1].Split(',')[1]); tsvh.PhaseA_Angle = double.Parse(data[63 - 1].Split(',')[1]); tsvh.PhaseB_Amps = double.Parse(data[56 - 1].Split(',')[2]); tsvh.PhaseB_Volts = double.Parse(data[57 - 1].Split(',')[2]); tsvh.PhaseB_PowerFactor = double.Parse(data[61 - 1].Split(',')[2]); tsvh.PhaseB_Frequency = double.Parse(data[62 - 1].Split(',')[2]); tsvh.PhaseB_Angle = double.Parse(data[63 - 1].Split(',')[2]); tsvh.PhaseC_Amps = double.Parse(data[56 - 1].Split(',')[3]); tsvh.PhaseC_Volts = double.Parse(data[57 - 1].Split(',')[3]); tsvh.PhaseC_PowerFactor = double.Parse(data[61 - 1].Split(',')[3]); tsvh.PhaseC_Frequency = double.Parse(data[62 - 1].Split(',')[3]); tsvh.PhaseC_Angle = double.Parse(data[63 - 1].Split(',')[3]); tsvh.Phase_Rotation = data[64 - 1].Split(',')[4]; var rs = ThongSoVanHanhDAO.Create(tsvh); if (!rs.Equals("success")) { ShowNotificationMessage(50, "Error", rs, ToolTipIcon.Error); reader.Close(); return; } } ShowNotificationMessage(50, "Success", "Reading file 'Thông số vận hành' finished!!!!", ToolTipIcon.Info); reader.Close(); break; } catch (IOException) { //Console.WriteLine("Wait to access file !!!"); ShowNotificationMessage(50, "Error", "Wait to access file !!!", ToolTipIcon.Error); Thread.Sleep(100); } catch (Exception ex) { //Console.WriteLine(ex.Message); ShowNotificationMessage(50, "Error", ex.Message, ToolTipIcon.Error); break; } finally { try { string fileName = e.Name; string sourcePath = conf.ThuMucQuet; string targetPath = conf.ThuMucChuyen; //Combine file và đường dẫn string sourceFile = System.IO.Path.Combine(sourcePath, fileName); string destFile = System.IO.Path.Combine(targetPath, fileName); //Copy file từ file nguồn đến file đích System.IO.File.Copy(sourceFile, destFile, true); ShowNotificationMessage(50, "Di chuyển file !!!", "Thành công", ToolTipIcon.None); } catch (Exception ex) { ShowNotificationMessage(50, "Error !!!", ex.Message, ToolTipIcon.Error); } } } }
public ActionResult CapNhatDiemDo_CreateOrUpdateCongTo(int id_congto, int id_diemdo, string serial, string loai_congto, string ct_dd_thoigianketthuc, string ct_dd_thoigianbatdau, int id_lienket = -1) { try { DateTime dt_start = new DateTime(); var rs_start = DateTime.TryParseExact(ct_dd_thoigianbatdau, "dd - MM - yyyy", null, DateTimeStyles.None, out dt_start); if (!rs_start) { return(Json(new { success = false, message = "Thời gian bắt đầu không đúng định dạng" })); } DateTime?dt_end = new DateTime(); if (string.IsNullOrEmpty(ct_dd_thoigianketthuc)) { dt_end = null; } else { DateTime dt = new DateTime(); var rs_end = DateTime.TryParseExact(ct_dd_thoigianketthuc, "dd - MM - yyyy", null, DateTimeStyles.None, out dt); if (!rs_end) { return(Json(new { success = false, message = "Thời gian kết thúc không đúng định dạng" })); } dt_end = dt; } if (dt_start > dt_end) { return(Json(new { success = false, message = "Thời gian bắt đầu phải nhỏ hơn Thời gian kết thúc" })); } // if update cong to if (id_congto != -1) { CongTo ct = new CongTo() { ID = id_congto, Serial = serial, Type = loai_congto }; var rs_checkexist = CongToDAO.CheckCongToExistBySerialExceptOneID(serial, id_congto); if (rs_checkexist) { return(Json(new { success = false, message = "Công tơ đã tồn tại" })); } // kiem tra co dang duoc su dung hay chua var rs_check_congto_using = LienKetDiemDoCongToDAO.CheckCongToUsingFollowTimeByID(id_congto, id_lienket, dt_start, dt_end); if (rs_check_congto_using) { // neu da duoc su dung return(Json(new { success = false, message = "Công tơ đã được sử dụng vào khoảng thời gian này" })); } //cap nhat thong tin cong to var rs_update_congto = CongToDAO.UpdateCongTo(ct); var rs_update_lienket = LienKetDiemDoCongToDAO.CapNhatThoiGian(id_lienket, dt_start, dt_end); } // if create or add cong to to diem do else { // lien ket cong to voi diem do CongTo ct = new CongTo(); ct.Serial = serial; ct.Type = loai_congto; // kiem tra cong to da ton tai hay chua var rs_checkexist = CongToDAO.CheckCongToExistBySerial(serial); if (rs_checkexist) { // neu cong to da ton tai var ct_temp = CongToDAO.GetCongToBySerial(serial); // kiem tra co dang duoc su dung hay chua var rs_check_congto_using = LienKetDiemDoCongToDAO.CheckCongToUsingFollowTimeByID(id_congto, id_diemdo, dt_start, dt_end); if (rs_check_congto_using) { // neu da duoc su dung return(Json(new { success = false, message = "Công tơ đã được sử dụng vào khoảng thời gian này" })); } // neu chua duoc su dung => cap nhat lien ket if (id_lienket != -1) { var old_lienket = LienKetDiemDoCongToDAO.GetLienKetById(id_lienket); var rs_update_lienket = LienKetDiemDoCongToDAO.CapNhatThoiGian(id_lienket, old_lienket.ThoiGianBatDau, dt_start.AddDays(-1)); } var rs_create_lk = LienKetDiemDoCongToDAO.CreateLienKet(ct_temp.ID, id_diemdo, dt_start, dt_end); } else { //neu cong to chua ton tai => tao moi var rs_create = CongToDAO.CreateCongTo(ref ct); if (!rs_create) { return(Json(new { success = false, message = "Công tơ đã tồn tại" })); } else { if (id_lienket != -1) { var old_lienket = LienKetDiemDoCongToDAO.GetLienKetById(id_lienket); var rs_update_lienket = LienKetDiemDoCongToDAO.CapNhatThoiGian(id_lienket, old_lienket.ThoiGianBatDau, dt_start.AddDays(-1)); } var rs_create_lk = LienKetDiemDoCongToDAO.CreateLienKet(ct.ID, id_diemdo, dt_start, dt_end); } } } return(Json(new { success = true, message = "Thành Công" })); } catch (Exception ex) { return(Json(new { success = false, message = ex.Message })); } }