예제 #1
0
        /// <summary>
        /// 将图片流输出为文件
        /// </summary>
        /// <param name="tablename"></param>
        public static string ExportSoilPicture(string type, string datetime, string cropcode, string nurient)
        {
            byte[]        imagebytes;
            string        datetimeforamt = datetime.Substring(0, datetime.LastIndexOf(" ")).Replace('/', '-');
            string        cropName       = DataBaseOperate.get_CropCHName(cropcode);
            string        nutrientName   = DataBaseOperate.get_NutrientCHName(nurient);
            string        pathname       = Application.StartupPath + @"\Image\" + type + "_" + datetimeforamt + "_" + cropName + "_" + nutrientName + ".jpg";
            string        strSql         = "select PIC_MAP from MONITOR_PICTURE where INDICATOR_NAME='" + type + "' and MONITORTIME='" + datetime + "' and CROP_CODE='" + cropcode + "' and NUTRIENT_CODE='" + nurient + "'";
            SqlConnection con            = DataBaseOperate.getSqlCon();
            SqlCommand    cmd            = new SqlCommand(strSql, con);
            SqlDataReader reader         = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            string        value_path     = "";

            while (reader.Read())
            {
                //获取图片数据
                imagebytes = (byte[])reader["PIC_MAP"];
                //将内存流格式化为位图
                if (imagebytes.Length > 0)
                {
                    MemoryStream stream = new MemoryStream(imagebytes);

                    if (File.Exists(pathname))
                    {
                        File.Delete(pathname);
                    }
                    Image image = Image.FromStream(stream);
                    image.Save(pathname);
                    stream.Close();
                    image.Dispose();

                    value_path = pathname;
                }
                else
                {
                    value_path = "";
                }
            }
            con.Close();
            return(value_path);
        }
예제 #2
0
 /// <summary>
 /// 转换表中的值
 /// </summary>
 /// <param name="dt"></param>
 /// <returns></returns>
 public static DataTable Convert_TableValue(DataTable dt)
 {
     for (int i = 0; i < dt.Rows.Count; i++)
     {
         if (dt.Columns.Count == 4)                 //根据输出列数判断是否是Soil
         {
             if (dt.Columns[0].ColumnName == "作业站") //根据列名判断作物范围
             {
                 dt.Rows[i][0] = DataBaseOperate.getVillName(dt.Rows[i][0].ToString());
             }
             else if (dt.Columns[0].ColumnName == "作业区")
             {
                 dt.Rows[i][0] = DataBaseOperate.getTownName(dt.Rows[i][0].ToString());
             }
             dt.Rows[i][1] = ((DateTime)dt.Rows[i][1]).ToShortDateString();
             dt.Rows[i][2] = DataBaseOperate.get_CropCHName(dt.Rows[i][2].ToString());
             dt.Rows[i][3] = Math.Round((double)dt.Rows[i][3], 3);
         }
         else //soil
         {
             if (dt.Columns[0].ColumnName == "作业站")
             {
                 dt.Rows[i][0] = DataBaseOperate.getVillName(dt.Rows[i][0].ToString());
             }
             else if (dt.Columns[0].ColumnName == "作业区")
             {
                 dt.Rows[i][0] = DataBaseOperate.getTownName(dt.Rows[i][0].ToString());
             }
             dt.Rows[i][1] = ((DateTime)dt.Rows[i][1]).ToShortDateString();
             dt.Rows[i][2] = DataBaseOperate.get_CropCHName(dt.Rows[i][2].ToString());
             dt.Rows[i][3] = DataBaseOperate.get_NutrientCHName(dt.Rows[i][3].ToString());
             dt.Rows[i][4] = Math.Round((double)dt.Rows[i][4], 4);
         }
     }
     return(dt);
 }