Beispiel #1
0
        private void ProcessDataChitiet(ref DataTable m_dtReport)
        {
            try
            {
                var lstAdded  = new List <DataRow>();
                int startDate = Utility.Int32Dbnull(Utility.GetYYYYMMDD(dtFromDate.Value), 0);
                int EndDate   = Utility.Int32Dbnull(Utility.GetYYYYMMDD(dtToDate.Value), 0);

                int iFound = 0;
                int idx    = 0;
                foreach (DataRow dr in m_dtReport.Rows)
                {
                    DateTime _ngaybiendong = Convert.ToDateTime(dr[TBiendongThuoc.Columns.NgayBiendong]);
                    long     _myId         = Utility.Int64Dbnull(dr[TBiendongThuoc.Columns.IdBiendong], 0);
                    iFound++;
                    if (iFound == 1) //Tính tồn cuối dòng đầu tiên tìm thấy
                    {
                        dr["Toncuoi"] = Utility.Int32Dbnull(dr["Tondau"], 0) + Utility.Int32Dbnull(dr["SoLuongNhap"], 0)
                                        - Utility.Int32Dbnull(dr["SoLuongXuat"], 0);
                    }
                    else
                    {
                        OrderedEnumerableRowCollection <DataRow> q = from p in m_dtReport.AsEnumerable()
                                                                     where
                                                                     Convert.ToDateTime(
                            p[TBiendongThuoc.Columns.NgayBiendong]) <=
                                                                     _ngaybiendong
                                                                     &&
                                                                     Utility.Int64Dbnull(
                            p[TBiendongThuoc.Columns.IdBiendong], 0) !=
                                                                     _myId &&
                                                                     Utility.Int32Dbnull(p["processed"], 0) > 0
                                                                     orderby
                                                                     Utility.Int32Dbnull(p["processed"], 0)
                                                                     descending
                                                                     //Convert.ToDateTime(p[TBiendongThuoc.Columns.NgayBiendong]) descending
                                                                     select p;

                        if (q.Count() > 0)
                        {
                            DataRow drPrevious = q.FirstOrDefault();
                            dr["Tondau"]  = Utility.Int32Dbnull(drPrevious["Toncuoi"], 0);
                            dr["Toncuoi"] = Utility.Int32Dbnull(dr["Tondau"], 0) +
                                            Utility.Int32Dbnull(dr["SoLuongNhap"], 0)
                                            - Utility.Int32Dbnull(dr["SoLuongXuat"], 0);
                        }
                    }
                    idx++;
                    dr["processed"] = idx;
                    m_dtReport.AcceptChanges();
                }
            }
            catch
            {
            }
        }
Beispiel #2
0
        private void ProcessDataThethuoc(ref DataTable m_dtReport)
        {
            DataTable dtTemp = m_dtReport.Clone();

            try
            {
                var lstAdded  = new List <DataRow>();
                int startDate = Utility.Int32Dbnull(Utility.GetYYYYMMDD(dtFromDate.Value), 0);
                int EndDate   = Utility.Int32Dbnull(Utility.GetYYYYMMDD(dtToDate.Value), 0);
                if (m_dtReport.Rows.Count == 1 && Utility.sDbnull(m_dtReport.Rows[0]["YYYYMMDD"], "") == "")
                {
                    m_dtReport.Rows[0]["YYYYMMDD"] = startDate.ToString();
                    m_dtReport.Rows[0][TBiendongThuoc.Columns.NgayBiendong] = dtFromDate.Value.Date.ToString("dd/MM/yyyy");
                }
                int      iFound        = 0;
                DataRow  rowdata       = m_dtReport.Rows[0];
                DateTime _dtmStartDate = dtFromDate.Value.Date;// Utility.FromYYYYMMDD2Datetime(startDate.ToString());

                if (THU_VIEN_CHUNG.Laygiatrithamsohethong("THUOC_THETHUOC_TUDONGTHEMDULIEU_TUONGLAI", "0", false) == "1")
                {
                    while (_dtmStartDate <= dtToDate.Value.Date)
                    {
                        DataRow[] arrDr = m_dtReport.Select("YYYYMMDD=" + Utility.GetYYYYMMDD(_dtmStartDate));
                        if (arrDr.Length > 0)
                        {
                            dtTemp.ImportRow(arrDr[0]);
                        }
                        else
                        {
                            DataRow newDr = dtTemp.NewRow();
                            Utility.CopyData(rowdata, ref newDr);
                            newDr["YYYYMMDD"] = Utility.GetYYYYMMDD(_dtmStartDate);
                            newDr[TBiendongThuoc.Columns.NgayBiendong] =
                                _dtmStartDate.ToString("dd/MM/yyyy");

                            newDr["Xuat"]    = 0;
                            newDr["Tondau"]  = 0;
                            newDr["Toncuoi"] = 0;
                            newDr["Nhap"]    = 0;
                            dtTemp.Rows.Add(newDr);
                        }
                        _dtmStartDate = _dtmStartDate.AddDays(1);
                    }
                }
                else
                {
                    dtTemp = m_dtReport.Copy();
                }
                _dtmStartDate = dtFromDate.Value.Date;
                while (_dtmStartDate <= dtToDate.Value.Date)
                {
                    DataRow[] arrDr = dtTemp.Select("YYYYMMDD=" + Utility.GetYYYYMMDD(_dtmStartDate));
                    if (arrDr.Length > 0)
                    {
                        iFound++;
                        if (iFound == 1) //Tính tồn cuối dòng đầu tiên tìm thấy
                        {
                            arrDr[0]["Toncuoi"] = Utility.Int32Dbnull(arrDr[0]["Tondau"], 0) +
                                                  Utility.Int32Dbnull(arrDr[0]["Nhap"], 0)
                                                  - Utility.Int32Dbnull(arrDr[0]["Xuat"], 0);
                        }
                        else
                        {
                            OrderedEnumerableRowCollection <DataRow> q = from p in dtTemp.AsEnumerable()
                                                                         where Utility.Int32Dbnull(p["YYYYMMDD"], 0) < Utility.Int32Dbnull(Utility.GetYYYYMMDD(_dtmStartDate))
                                                                         orderby p["YYYYMMDD"] descending
                                                                         select p;
                            if (q.Count() > 0)
                            {
                                DataRow drPrevious = q.FirstOrDefault();
                                arrDr[0]["Tondau"]  = Utility.Int32Dbnull(drPrevious["Toncuoi"], 0);
                                arrDr[0]["Toncuoi"] = Utility.Int32Dbnull(arrDr[0]["Tondau"], 0) +
                                                      Utility.Int32Dbnull(arrDr[0]["Nhap"], 0)
                                                      - Utility.Int32Dbnull(arrDr[0]["Xuat"], 0);
                            }
                        }
                        dtTemp.AcceptChanges();
                    }
                    else
                    {
                    }
                    _dtmStartDate = _dtmStartDate.AddDays(1);
                }
            }
            catch (Exception ex)
            {
                //Utility.CatchException(ex);
            }
            finally{
                m_dtReport = dtTemp.Copy();
            }
        }