public ActionResult CongSuatMaxMinPartialView()
        {
            var listDiemDo = DiemDoDAO.getAllDiemDo();

            ViewBag.listDiemDo = listDiemDo;
            return(PartialView());
        }
Пример #2
0
        public ActionResult CapNhatDiemDoManageModal(int id)
        {
            ViewBag.ListNhaMay = NhaMayDAO.GetAllNhaMay();
            ViewBag.ListTCDD   = TinhChatDiemDoDAO.GetAllTCDD();
            DiemDo dd = new DiemDo();

            if (id == 0)
            {
                //return Json(new { success = true, data = View() });
                return(PartialView());
            }

            var rs = DiemDoDAO.GetDiemDoById(id, out dd);

            //return Json(new { success = rs, data = View(sldk) });
            return(PartialView(dd));
        }
Пример #3
0
        public ActionResult CapNhatDiemDo_CreateOrUpdate(int?maDiemDo, int?thuTuHienThi, int nha_may_id, int id_tinh_chat_diem_do, int id_diemdo, string tenDiemDo = "")
        {
            if (maDiemDo == null)
            {
                return(Json(new { success = false, message = "Mã điểm đo không được để trống!!!" }));
            }

            if (thuTuHienThi == null)
            {
                return(Json(new { success = false, message = "Thứ tự hiển thị không được để trống!!!" }));
            }

            if (string.IsNullOrEmpty(tenDiemDo))
            {
                return(Json(new { success = false, message = "Tên điểm đo không được để trống!!!" }));
            }

            var rs = "";

            if (id_diemdo == 0)
            {
                //create
                rs = DiemDoDAO.CreateDiemDo(maDiemDo.Value, tenDiemDo, thuTuHienThi.Value, nha_may_id, id_tinh_chat_diem_do);
            }
            else
            {
                // update
                rs = DiemDoDAO.UpdateDiemDo(maDiemDo.Value, tenDiemDo, thuTuHienThi.Value, nha_may_id, id_tinh_chat_diem_do, id_diemdo);
            }

            if (rs.Equals("success"))
            {
                return(Json(new { success = true, message = "Thành Công!!!" }));
            }
            else
            {
                return(Json(new { success = false, message = rs }));
            }
        }
Пример #4
0
        public ActionResult CapNhatDiemDoPaging(int id_tcdd_db, bool allow_history = false)
        {
            try
            {
                using (Model1 db = new Model1())
                {
                    RequestPagingModel rpm = new RequestPagingModel();
                    rpm.length         = int.Parse(HttpContext.Request["length"]);
                    rpm.start          = int.Parse(Request["start"]);
                    rpm.searchValue    = HttpContext.Request["search[value]"];
                    rpm.sortColumnName = HttpContext.Request["columns[" + Request["order[0][column]"] + "][name]"];
                    rpm.sortDirection  = Request["order[0][dir]"];
                    rpm.draw           = Request["draw"];

                    int?tcdd_id = null;
                    if (id_tcdd_db != -1)
                    {
                        tcdd_id = id_tcdd_db;
                    }

                    PagingModel <DiemDoViewModel> pm = new PagingModel <DiemDoViewModel>();
                    var response = DiemDoDAO.GetDiemDoPaging(out pm, rpm, tcdd_id, allow_history);

                    if (!response)
                    {
                        return(Json(new { success = false, message = "Lỗi truy cập cơ sở dữ liệu" }, JsonRequestBehavior.AllowGet));
                        //return Json(null, JsonRequestBehavior.AllowGet);
                    }

                    return(Json(pm, JsonRequestBehavior.AllowGet));
                }
            }
            catch
            {
                return(null);
            }
        }
Пример #5
0
        public void OnCreatedSanLuong(object source, FileSystemEventArgs e)
        {
            while (true)
            {
                try
                {
                    DbContextService db = new DbContextService();
                    // get cong thuc
                    DateTime date       = DateTime.Now.AddDays(-1);
                    string   congThuc   = db.CongThucTongSanLuongs.Where(x => x.ThoiGianBatDau <date && x.ThoiGianKetThuc> date).Select(x => x.CongThuc).First();
                    int      congThucID = db.CongThucTongSanLuongs.Where(x => x.ThoiGianBatDau <date && x.ThoiGianKetThuc> date).Select(x => x.ID).First();
                    string[] divided    = congThuc.Split(' ');// tach cac phan tu trong cong thuc
                    // add Phan Tu trong cong thuc
                    List <PhanTu> listPhanTu = new List <PhanTu>();
                    for (int i = 0; i < divided.Length; i++)
                    {
                        if (divided[i].Length > 1) // divice la phan tu
                        {
                            string[] temp      = divided[i].Split('~');
                            var      tenDiemDo = temp[0];
                            var      tenKenh   = temp[1];
                            PhanTu   pt        = new PhanTu();
                            pt.DiemDoID = db.DiemDoes.Where(x => x.TenDiemDo == tenDiemDo).Select(x => x.ID).FirstOrDefault();
                            if (pt.DiemDoID == 0)
                            {
                                ShowNotificationMessage(50, "Error", "Điểm đo trong Công thức không tồn tại !!!", ToolTipIcon.Error);
                                return;
                            }
                            pt.KenhID = db.Kenhs.Where(x => x.Ten == tenKenh).Select(x => x.ID).FirstOrDefault();
                            if (pt.KenhID == 0)
                            {
                                ShowNotificationMessage(50, "Error", "Kênh trong Công thức không tồn tại !!!", ToolTipIcon.Error);
                                return;
                            }
                            pt.index = i;
                            listPhanTu.Add(pt);
                        }
                    }
                    bool checkDiemDoTSLN = true;

                    //Console.WriteLine("Try to access file !!!");
                    StreamReader reader = new StreamReader(e.FullPath);
                    //Console.WriteLine("Access file successfully !!!");
                    string fileName = e.Name;
                    // get DiemDoID
                    int get_DiemDoID = DiemDoDAO.GetDiemDoID(int.Parse(fileName.Split('.')[0].Substring(5)));
                    if (get_DiemDoID == 0)
                    {
                        ShowNotificationMessage(50, "Error", "Điểm đo không tồn tại !!!", ToolTipIcon.Error);
                        reader.Close();
                        return;
                    }
                    // check điểm đo có trong công thức hay không
                    int indexPhanTu = 0;
                    foreach (var i in listPhanTu)
                    {
                        if (i.DiemDoID == get_DiemDoID)
                        {
                            checkDiemDoTSLN = true;
                            indexPhanTu     = listPhanTu.IndexOf(i);
                            ShowNotificationMessage(50, "Thông báo", "Điểm đo có trong công thức !!!", ToolTipIcon.Info);
                            break;
                        }
                    }
                    if (!checkDiemDoTSLN)
                    {
                        ShowNotificationMessage(50, "Thông báo", "Điểm đo không có trong công thức !!!", ToolTipIcon.Info);
                        checkDiemDoTSLN = false;
                    }


                    string day   = fileName.Substring(0, 2);
                    string month = fileName.Substring(2, 2);
                    //fix year
                    string   year = (DateTime.Now.Year).ToString();
                    DateTime time = DateTime.Parse(month + "/" + day + "/" + year);
                    // read file
                    string line;
                    int    count = 1;
                    while ((line = reader.ReadLine()) != null)
                    {
                        if (count == 1 || count == 2 || count == 8 || count == 9)
                        {
                            string[] word       = line.Split(',');
                            int      get_KenhID = KenhDAO.GetKenhID(word[1]);
                            if (get_KenhID == 0)
                            {
                                ShowNotificationMessage(50, "Error", "Kênh không tồn tại !!!", ToolTipIcon.Error);
                                reader.Close();
                                return;
                            }
                            //check kenh
                            bool checkKenhTSLN = false;
                            if (listPhanTu[indexPhanTu].KenhID == get_KenhID)
                            {
                                checkKenhTSLN = true;
                            }


                            for (int i = 2; i < word.Length; i++)
                            {
                                SanLuong sl = new SanLuong
                                {
                                    Ngay     = time,
                                    DiemDoID = get_DiemDoID,
                                    KenhID   = get_KenhID
                                };
                                sl.ChuKy = short.Parse((i - 1).ToString());
                                /*sl.GiaTri = Convert.ToDouble(string.Format("{0:0.##}", word[i]) );*/
                                sl.GiaTri = Convert.ToDouble(word[i]);
                                if (!SanLuongDAO.checkExistSL(sl))
                                {
                                    var rs = SanLuongDAO.InsertSanLuong(sl);
                                    if (rs != "success")
                                    {
                                        ShowNotificationMessage(50, "Error", rs, ToolTipIcon.Error);
                                        reader.Close();
                                        return;
                                    }

                                    // tinh luy ke
                                    if (checkDiemDoTSLN && checkKenhTSLN)
                                    {
                                        // tinh tong san luong ngay
                                        bool checkInsertDay         = false;
                                        bool checkInsertMonth       = false;
                                        bool checkInsertYear        = false;
                                        bool checkInsertMonthYear   = false;
                                        TongSanLuong_Ngay     tslng = TongSanLuong_NgayDAO.GetByNgayAndChuKy(time, i - 1);
                                        TongSanLuong_Thang    tslt  = TongSanLuong_ThangDAO.GetByTime(time);
                                        TongSanLuong_Nam      tsln  = TongSanLuong_NamDAO.GetByTime(time);
                                        TongSanLuong_ThangNam tsltn = TongSanLuong_ThangNamDAO.GetByTime(time);
                                        if (tslng == null)
                                        {
                                            // create new tslng
                                            tslng = new TongSanLuong_Ngay()
                                            {
                                                Ngay       = sl.Ngay,
                                                ChuKy      = sl.ChuKy,
                                                CongThucID = congThucID,
                                                GiaTri     = 0
                                            };
                                            checkInsertDay = true;
                                        }
                                        if (tslt == null)
                                        {
                                            // create new tslt
                                            tslt = new TongSanLuong_Thang()
                                            {
                                                Thang  = time.Month,
                                                Nam    = time.Year,
                                                GiaTri = 0
                                            };
                                            checkInsertMonth = true;
                                        }
                                        if (tsln == null)
                                        {
                                            // create new tsln
                                            tsln = new TongSanLuong_Nam()
                                            {
                                                Nam    = time.Year,
                                                GiaTri = 0
                                            };
                                            checkInsertYear = true;
                                        }
                                        if (tsltn == null)
                                        {
                                            // create new tsltn
                                            tsltn = new TongSanLuong_ThangNam()
                                            {
                                                Ngay        = time,
                                                GiaTriNam   = TongSanLuong_ThangNamDAO.GetClosestYearValue(time),
                                                GiaTriThang = TongSanLuong_ThangNamDAO.GetClosestMonthValue(time)
                                            };
                                            checkInsertMonthYear = true;
                                        }
                                        //tinh toan gia tri
                                        if (listPhanTu[indexPhanTu].index == 0 || divided[listPhanTu[indexPhanTu].index - 1].Equals("+"))
                                        {
                                            tslng.GiaTri += sl.GiaTri;
                                            tslt.GiaTri  += sl.GiaTri;
                                            tsln.GiaTri  += sl.GiaTri;

                                            tsltn.GiaTriThang += sl.GiaTri.Value;
                                            tsltn.GiaTriNam   += sl.GiaTri.Value;
                                        }
                                        else
                                        {
                                            tslng.GiaTri -= sl.GiaTri;
                                            tslt.GiaTri  -= sl.GiaTri;
                                            tsln.GiaTri  -= sl.GiaTri;

                                            tsltn.GiaTriThang -= sl.GiaTri.Value;
                                            tsltn.GiaTriNam   -= sl.GiaTri.Value;
                                        }

                                        // insert or update ngay
                                        if (checkInsertDay)
                                        {
                                            var rs_checkInsertDay = TongSanLuong_NgayDAO.Insert(tslng);
                                            if (rs_checkInsertDay != "success")
                                            {
                                                ShowNotificationMessage(50, "Error", rs_checkInsertDay, ToolTipIcon.Error);
                                                reader.Close();
                                                return;
                                            }
                                        }
                                        else
                                        {
                                            var rs_checkUpdateDay = TongSanLuong_NgayDAO.Update(tslng);
                                            if (rs_checkUpdateDay != "success")
                                            {
                                                ShowNotificationMessage(50, "Error", rs_checkUpdateDay, ToolTipIcon.Error);
                                                reader.Close();
                                                return;
                                            }
                                        }
                                        // insert or update thang
                                        if (checkInsertMonth)
                                        {
                                            var rs_checkInsertMon = TongSanLuong_ThangDAO.Insert(tslt);
                                            if (rs_checkInsertMon != "success")
                                            {
                                                ShowNotificationMessage(50, "Error", rs_checkInsertMon, ToolTipIcon.Error);
                                                reader.Close();
                                                return;
                                            }
                                        }
                                        else
                                        {
                                            var rs_checkInsertMon = TongSanLuong_ThangDAO.Update(tslt);
                                            if (rs_checkInsertMon != "success")
                                            {
                                                ShowNotificationMessage(50, "Error", rs_checkInsertMon, ToolTipIcon.Error);
                                                reader.Close();
                                                return;
                                            }
                                        }
                                        // insert or update nam
                                        if (checkInsertYear)
                                        {
                                            var rs_checkInsertYear = TongSanLuong_NamDAO.Insert(tsln);
                                            if (rs_checkInsertYear != "success")
                                            {
                                                ShowNotificationMessage(50, "Error", rs_checkInsertYear, ToolTipIcon.Error);
                                                reader.Close();
                                                return;
                                            }
                                        }
                                        else
                                        {
                                            var rs_checkInsertYear = TongSanLuong_NamDAO.Update(tsln);
                                            if (rs_checkInsertYear != "success")
                                            {
                                                ShowNotificationMessage(50, "Error", rs_checkInsertYear, ToolTipIcon.Error);
                                                reader.Close();
                                                return;
                                            }
                                        }
                                        // insert or update thang-nam
                                        if (checkInsertMonthYear)
                                        {
                                            var rs_checkInsertYear = TongSanLuong_ThangNamDAO.Insert(tsltn);
                                            if (rs_checkInsertYear != "success")
                                            {
                                                ShowNotificationMessage(50, "Error", rs_checkInsertYear, ToolTipIcon.Error);
                                                reader.Close();
                                                return;
                                            }
                                        }
                                        else
                                        {
                                            var rs_checkInsertYear = TongSanLuong_ThangNamDAO.Update(tsltn);
                                            if (rs_checkInsertYear != "success")
                                            {
                                                ShowNotificationMessage(50, "Error", rs_checkInsertYear, ToolTipIcon.Error);
                                                reader.Close();
                                                return;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        count++;
                    }
                    ShowNotificationMessage(50, "Success", "Reading file 'Sản Lượng' 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 OnCreatedSanLuong(object source, FileSystemEventArgs e)
        {
            Common.MoveFile(e, conf);
            for (int v = 0; v < 100000; v++)
            {
                try
                {
                    DbContextService db = new DbContextService();
                    reader = new StreamReader(e.FullPath);
                    string fileName = e.Name;
                    // get DiemDoID
                    int get_DiemDoID = DiemDoDAO.GetDiemDoID(int.Parse(fileName.Split('.')[0].Substring(5)));
                    if (get_DiemDoID == 0)
                    {
                        //ShowNotificationMessage(50, "Error", "Điểm đo không tồn tại !!!", ToolTipIcon.Error);
                        reader.Close();
                        return;
                    }
                    string day   = fileName.Substring(0, 2);
                    string month = fileName.Substring(2, 2);

                    int    this_year = DateTime.Now.Year;
                    string year      = fileName.Substring(4, 1);
                    if (year == (this_year % 10).ToString())
                    {
                        year = this_year.ToString();
                    }
                    else
                    {
                        var temp = this_year - 1;
                        year = ((temp - temp % 10) + int.Parse(year)).ToString();
                    }
                    DateTime time = DateTime.Parse(month + "/" + day + "/" + year);
                    // read file
                    string line;
                    int    count = 1;
                    while ((line = reader.ReadLine()) != null)
                    {
                        if (count == 1 || count == 2 || count == 8 || count == 9)
                        {
                            string[] word       = line.Split(',');
                            int      get_KenhID = KenhDAO.GetKenhID(word[1]);
                            if (get_KenhID == 0)
                            {
                                //ShowNotificationMessage(50, "Error", "Kênh không tồn tại !!!", ToolTipIcon.Error);
                                reader.Close();
                                return;
                            }
                            //vong lap chu ky
                            for (int i = 2; i < word.Length; i++)
                            {
                                SanLuong sl = new SanLuong
                                {
                                    Ngay     = time,
                                    DiemDoID = get_DiemDoID,
                                    KenhID   = get_KenhID
                                };
                                sl.ChuKy  = short.Parse((i - 1).ToString());
                                sl.GiaTri = Convert.ToDouble(word[i]) * 1000; // from kWh to Wh
                                if (!SanLuongDAO.checkExistSL(sl))
                                {
                                    var rs = SanLuongDAO.InsertSanLuong(sl);
                                    if (rs != "success")
                                    {
                                        //ShowNotificationMessage(50, "Error", rs, ToolTipIcon.Error);
                                        reader.Close();
                                        return;
                                    }
                                }

                                //tinh tong san luong ngay
                                var calDay = TongSanLuong_NgayDAO.Calculator(sl.ChuKy, sl.Ngay);
                                if (calDay == "success")
                                {
                                    //ShowNotificationMessage(50, "Success", "Cập nhật TongSanLuong_Ngay thành công !!", ToolTipIcon.Info);
                                }
                            }
                        }

                        count++;
                    }
                    // tinh tong san luong thang
                    var calMonth = TongSanLuong_ThangDAO.Calculator(time);
                    if (calMonth == "success")
                    {
                        //ShowNotificationMessage(50, "Success", "Cập nhật TongSanLuong_Thang thành công !!", ToolTipIcon.Info);
                        var calYear = TongSanLuong_NamDAO.Calculator(time);
                        if (calYear == "success")
                        {
                            //ShowNotificationMessage(50, "Success", "Cập nhật TongSanLuong_Nam thành công !!", ToolTipIcon.Info);
                        }
                    }
                    //ShowNotificationMessage(50, "Success", "Reading file 'Sản Lượng' finished!!!!", ToolTipIcon.Info);
                    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
                    {
                    }
                }
            }
        }