Exemple #1
0
        public ChartResult GetID(string labcode, double?chartmin, double?chartmax, double?normalmin, double?normalmax, double?value, string displayvalue, string summary)
        {
            try
            {
                using (InhCheckupDataContext cdc = new InhCheckupDataContext())
                {
                    var mlch = cdc.mst_lab_charts
                               .Where(x => x.mlch_lab_code == labcode &&
                                      x.mlch_min_value == chartmin &&
                                      x.mlch_max_value == chartmax &&
                                      x.mlch_min_normal == normalmin &&
                                      x.mlch_max_normal == normalmax &&
                                      x.mlch_summary == summary &&
                                      x.mlch_lab_value == value)
                               .FirstOrDefault();
                    if (mlch != null && mlch.mlch_active == true)
                    {
                        return(new ChartResult {
                            chartid = mlch.mlch_id, chartpath = mlch.mlch_file_path
                        });
                    }
                    else
                    {
                        DateTime dateNow = Class.globalCls.GetServerDateTime();
                        if (mlch == null)
                        {
                            mlch = new mst_lab_chart
                            {
                                mlch_lab_code    = labcode,
                                mlch_min_value   = chartmin,
                                mlch_max_value   = chartmax,
                                mlch_min_normal  = normalmin,
                                mlch_max_normal  = normalmax,
                                mlch_lab_value   = value,
                                mlch_summary     = summary,
                                mlch_create_date = dateNow
                            };
                            cdc.mst_lab_charts.InsertOnSubmit(mlch);
                        }
                        mlch.mlch_update_date = dateNow;

                        Image img;
                        if (chartmin == null || chartmax == null || normalmin == null || normalmax == null || value == null)
                        {
                            img = Properties.Resources.Error;
                            mlch.mlch_active = false;
                        }
                        else
                        {
                            var genrs = new LabClass.GenerateChartCls().Generate(chartmin, chartmax, normalmin, normalmax, value, displayvalue, summary);
                            mlch.mlch_active = genrs.active;
                            img = genrs.img;
                        }
                        string dirLab    = @"\" + (string.IsNullOrEmpty(labcode) ? "xxxx" : labcode);
                        string dirMinMax = @"\LR" + (chartmin == null ? "xxxx" : chartmin.ToString()) + "_" + (chartmax == null ? "xxxx" : chartmax.ToString());
                        string dirRange  = @"\NLR" + (normalmin == null ? "xxxx" : normalmin.ToString()) + "_" + (normalmax == null ? "xxxx" : normalmax.ToString());
                        string path      = Class.GetDBConfigCls.GetConfig("PathChartImage") + dirLab + dirMinMax + dirRange;
                        if (!System.IO.Directory.Exists(path))
                        {
                            System.IO.Directory.CreateDirectory(path);
                        }
                        string filename = @"\V" + (value == null ? "xxxx" : value.ToString()) + ".png";
                        img.Save(path + filename, System.Drawing.Imaging.ImageFormat.Png);
                        mlch.mlch_file_path = path + filename;
                    }
                    cdc.SubmitChanges();
                    return(new ChartResult {
                        chartid = mlch.mlch_id, chartpath = mlch.mlch_file_path
                    });
                }
            }
            catch (Exception ex)
            {
                Class.globalCls.MessageError("MstLabChartCls", "GetID(double? min, double? max, double? normal_min, double? normal_max, string value)", ex.Message);
                return(new ChartResult {
                    chartid = null, chartpath = null
                });
            }
        }
Exemple #2
0
 public int GetID(string mlch_lab_code, double?mlch_min_value, double?mlch_max_value, double?mlch_min_normal, double?mlch_max_normal, string normal_range, string mlch_lab_value, string ShowValue)
 {
     try
     {
         using (InhCheckupDataContext cdc = new InhCheckupDataContext())
         {
             bool     error      = false;
             DateTime dateNow    = globalCls.GetServerDateTime();
             double   min        = 0;
             double   max        = 0;
             double   min_normal = 0;
             double   max_normal = 0;
             double   value      = 0;
             try
             {
                 min        = (double)mlch_min_value;
                 max        = (double)mlch_max_value;
                 min_normal = (double)mlch_min_normal;
                 max_normal = (double)mlch_max_normal;
                 value      = Convert.ToDouble(mlch_lab_value);
             }
             catch
             {
                 error = true;
             }
             mst_lab_chart mlch = cdc.mst_lab_charts
                                  .Where(x => x.mlch_lab_code == mlch_lab_code &&
                                         x.mlch_min_value == min &&
                                         x.mlch_max_value == max &&
                                         x.mlch_min_normal == min_normal &&
                                         x.mlch_max_normal == max_normal &&
                                         x.mlch_lab_value == value)
                                  .FirstOrDefault();
             if (mlch == null || mlch.mlch_active == false)
             {
                 if (mlch == null)
                 {
                     mlch = new mst_lab_chart
                     {
                         mlch_lab_code    = mlch_lab_code,
                         mlch_summary     = value >= min_normal && value <= max_normal ? "N" : "A",
                         mlch_min_value   = min,
                         mlch_max_value   = max,
                         mlch_min_normal  = min_normal,
                         mlch_max_normal  = max_normal,
                         mlch_lab_value   = value,
                         mlch_active      = true,
                         mlch_create_date = dateNow
                     };
                     cdc.mst_lab_charts.InsertOnSubmit(mlch);
                 }
                 mlch.mlch_normal_range = normal_range.Trim();
                 mlch.mlch_summary      = value >= min_normal && value <= max_normal ? "N" : "A";
                 mlch.mlch_update_date  = dateNow;
                 Image img;
                 if (!error)
                 {
                     try
                     {
                         img = new GenerateChartCls().Generate(min, max, min_normal, max_normal, value, ShowValue);
                         mlch.mlch_active = true;
                     }
                     catch (Exception ex)
                     {
                         img = Properties.Resources.Error;
                         mlch.mlch_active = false;
                         globalCls.MessageError("MstLabChartCls", "GetID(double? min, double? max, double? normal_min, double? normal_max, string value)", ex.Message);
                     }
                 }
                 else
                 {
                     img = Properties.Resources.Error;
                     mlch.mlch_active = false;
                 }
                 string dirLab    = @"\" + mlch.mlch_lab_code;
                 string dirMinMax = @"\LR" + min.ToString() + "_" + max.ToString();
                 string dirRange  = @"\NLR" + min_normal.ToString() + "_" + max_normal.ToString();
                 string path      = GetDBConfigCls.GetConfig("PathChartImage") + dirLab + dirMinMax + dirRange;
                 if (!System.IO.Directory.Exists(path))
                 {
                     System.IO.Directory.CreateDirectory(path);
                 }
                 try
                 {
                     string filename = @"\V" + value.ToString() + ".png";
                     img.Save(path + filename, System.Drawing.Imaging.ImageFormat.Png);
                     mlch.mlch_file_path = path + filename;
                 }
                 catch (Exception ex)
                 {
                     mlch.mlch_file_path = "";
                     mlch.mlch_active    = false;
                     globalCls.MessageError("MstLabChartCls", "GetID(double? min, double? max, double? normal_min, double? normal_max, string value)", ex.Message);
                 }
                 cdc.SubmitChanges();
             }
             return(mlch.mlch_id);
         }
     }
     catch (Exception ex)
     {
         globalCls.MessageError("MstLabChartCls", "GetID(double? min, double? max, double? normal_min, double? normal_max, string value)", ex.Message);
         return(1);
     }
 }