public override void TinhGiatri() { string sql; //Lấy Tổng giá trị cần phân bổ object[] os = DbData.GetValueByStore("sopsKetChuyen", new string[] { "@tk", "@ngayct", "@ngayct1", "@dk", "@psno" }, new object[] { tk, _Tungay, _Denngay, null, null }, new SqlDbType[] { SqlDbType.NVarChar, SqlDbType.DateTime, SqlDbType.DateTime, SqlDbType.NVarChar, SqlDbType.Float }, new ParameterDirection[] { ParameterDirection.Input, ParameterDirection.Input, ParameterDirection.Input, ParameterDirection.Input, ParameterDirection.Output }); if (os == null || os.Length == 0) { return; } Tongtien = Double.Parse(os[0].ToString()); //Lấy hệ số phân bổ sql = "select " + dryt["TruongSP"].ToString() + " as Masp," + dryt["Heso"].ToString() + " as Heso from " + dryt["BangDM"].ToString(); //sql += " where ngayct between cast('" + _Tungay.ToShortDateString() + "'as datetime) and cast('" + _Denngay.ToShortDateString() + "'as datetime) "; sql += " where " + dryt["TruongSP"].ToString() + " in (select mavt from dmvt where nhomgt ='" + this.Manhom + "') and Thang = " + _Tungay.Month.ToString() + " and Nam = " + _Tungay.Year.ToString(); DataTable tbHeso = DbData.GetDataTable(sql); tbHeso.PrimaryKey = new DataColumn[] { tbHeso.Columns["MaSP"] }; //Lấy tổng hệ số phân bổ double TongHeso = 0; DataColumn col = new DataColumn("Heso", typeof(double)); col.DefaultValue = 0; dtkq.Columns.Add(col); foreach (DataRow dr in dtkq.Rows) { string Masp = dr["MaSP"].ToString(); DataRow drHeso; if (!tbHeso.Rows.Contains(Masp)) { continue; } drHeso = tbHeso.Rows.Find(Masp); //double heso=double.Parse(dr["soluong"].ToString()) * double.Parse(drHeso["Heso"].ToString()); double heso = double.Parse(drHeso["Heso"].ToString()); dr["Heso"] = heso; TongHeso += heso; } //Phân bổ if (TongHeso == 0) { return; } foreach (DataRow dr in dtkq.Rows) { dr[Name] = double.Parse(dr["Heso"].ToString()) * Tongtien / TongHeso; } dtkq.Columns.Remove("Heso"); dtkq.Columns.Remove("Soluong"); }
public override void TinhGiatri() { if (YTPt.Count == 0) { return; } //dtkq.PrimaryKey = new DataColumn[] { dtkq.Columns["MaSP"] }; object[] os = DbData.GetValueByStore("sopsKetChuyen", new string[] { "@tk", "@ngayct", "@ngayct1", "@dk", "@psno" }, new object[] { tk, _Tungay, _Denngay, null, null }, new SqlDbType[] { SqlDbType.NVarChar, SqlDbType.DateTime, SqlDbType.DateTime, SqlDbType.NVarChar, SqlDbType.Float }, new ParameterDirection[] { ParameterDirection.Input, ParameterDirection.Input, ParameterDirection.Input, ParameterDirection.Input, ParameterDirection.Output }); if (os == null || os.Length == 0) { return; } Tongtien = Double.Parse(os[0].ToString()); double TongHeso = 0; string BangDM = ""; string TruongSP; string TruongHSDC = ""; DataTable TbHSDC = null; string sql = ""; DataColumn col = new DataColumn("HESO"); col.DataType = typeof(double); col.DefaultValue = 0.0; col.Caption = "HESO"; this.dtkq.Columns.Add(col); DataColumn col1 = new DataColumn("HSDC"); col1.DataType = typeof(double); col1.DefaultValue = 0.0; col1.Caption = "HSDC"; this.dtkq.Columns.Add(col1); if (dryt["BangDM"] != null && dryt["BangDM"].ToString().Trim() != "") { BangDM = dryt["BangDM"].ToString(); TruongSP = dryt["TruongSP"].ToString(); TruongHSDC = dryt["Heso"].ToString(); sql = "select * from " + BangDM + " where ngayct between '" + _Tungay.ToShortDateString() + "' and '" + _Denngay.ToShortDateString() + "'"; TbHSDC = DbData.GetDataTable(sql); if (TbHSDC == null) { return; } TbHSDC.PrimaryKey = new DataColumn[] { TbHSDC.Columns[TruongSP] }; foreach (DataRow dr in dtkq.Rows) { Hashtable h = new Hashtable(); foreach (Ytgt YT1 in YTPt) { DataRow tmp = YT1.Kq.Rows.Find(dr["masp"].ToString()); if (tmp != null) { h.Add(YT1.Name.ToUpper(), double.Parse(tmp[YT1.Name].ToString())); } else { h.Add(YT1.Name.ToUpper(), 0); } } dr["HESO"] = bt.Evaluate(h); DataRow drtmp; drtmp = TbHSDC.Rows.Find(dr[TruongSP].ToString()); if (drtmp != null) { dr["HSDC"] = double.Parse(drtmp[TruongHSDC].ToString()); } else { dr["HSDC"] = 0; } TongHeso += double.Parse(dr["HESO"].ToString()) * double.Parse(dr["HSDC"].ToString()); } } else { foreach (DataRow dr in dtkq.Rows) { Hashtable h = new Hashtable(); foreach (Ytgt YT1 in YTPt) { DataRow tmp = YT1.Kq.Rows.Find(dr["masp"].ToString()); if (tmp != null) { h.Add(YT1.Name.ToUpper(), double.Parse(tmp[YT1.Name].ToString())); } else { h.Add(YT1.Name.ToUpper(), 0); } } dr["HESO"] = bt.Evaluate(h); dr["HSDC"] = 1; TongHeso += double.Parse(dr["HESO"].ToString()); } } foreach (DataRow dr in dtkq.Rows) { double heso = double.Parse(dr["HESO"].ToString()); double HSDC = double.Parse(dr["HSDC"].ToString()); dr[Name] = Tongtien * heso * HSDC / (TongHeso); } dtkq.Columns.Remove("Soluong"); this.dtkq.Columns.Remove("HESO"); this.dtkq.Columns.Remove("HSDC"); }