Exemplo n.º 1
0
 public virtual DsOnl.ONLclimbersDataTable GetDataByIid(int iid)
 {
     this.Adapter.SelectCommand = this.CommandCollection[0];
     this.Adapter.SelectCommand.Parameters[0].Value = ((int)(iid));
     DsOnl.ONLclimbersDataTable dataTable = new DsOnl.ONLclimbersDataTable();
     this.Adapter.Fill(dataTable);
     return(dataTable);
 }
Exemplo n.º 2
0
        public virtual int FillByIid(DsOnl.ONLclimbersDataTable dataTable, int iid)
        {
            this.Adapter.SelectCommand = this.CommandCollection[0];
            this.Adapter.SelectCommand.Parameters[0].Value = ((int)(iid));
            if ((this.ClearBeforeFill == true))
            {
                dataTable.Clear();
            }
            int returnValue = this.Adapter.Fill(dataTable);

            return(returnValue);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Сохраняет хранящуюся в БД фото участника/судьи на сервер и возвращает относительный путь к этой фотке
        /// Если фотка уже есть на сервере, то возвращает пустую строку
        /// </summary>
        /// <param name="cn">Используемое соединение</param>
        /// <param name="iid">iid участника/судьи</param>
        /// <param name="judges">true, если нухна фотка судьи</param>
        /// <returns></returns>
        public static string GetOnlineImg(SqlConnection cn, int iid, bool judges)
        {
            try
            {
                if (cn.State != ConnectionState.Open)
                {
                    cn.Open();
                }
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = cn;
                string table;
                if (judges)
                {
                    table = "ONLjudges";
                }
                else
                {
                    table = "ONLclimbers";
                }
                cmd.CommandText = "SELECT phLoaded FROM " + table + "(NOLOCK) WHERE iid=" + iid.ToString();
                object obj = cmd.ExecuteScalar();
                if (obj == null || obj == DBNull.Value)
                {
                    return("");
                }
                bool   bRes = Convert.ToBoolean(obj);
                string dir  = System.Threading.Thread.GetDomain().BaseDirectory;

                if (dir.Length > 0 && dir[dir.Length - 1] != '\\')
                {
                    dir += "\\";
                }

                if (!Directory.Exists(dir + IMG_PATH))
                {
                    Directory.CreateDirectory(dir + IMG_PATH);
                }
                string prfix;
                if (judges)
                {
                    prfix = JUDGE_PREFIX;
                }
                else
                {
                    prfix = "";
                }
                if (bRes && File.Exists(dir + IMG_PATH + "\\" + prfix + iid.ToString() + ".jpg"))
                {
                    return(IMG_PATH + "\\" + prfix + iid.ToString() + ".jpg");
                }
                if (File.Exists(dir + IMG_PATH + "\\" + prfix + iid.ToString() + ".jpg"))
                {
                    try { File.Delete(dir + IMG_PATH + "\\" + prfix + iid.ToString() + ".jpg"); }
                    catch { }
                }
                ONLclimbersTableAdapter ota = new ONLclimbersTableAdapter();
                ota.Connection = cn;
                DsOnl.ONLclimbersDataTable dt = ota.GetDataByIid(iid);
                bool imageLoaded = false;
                try
                {
                    foreach (DsOnl.ONLclimbersRow row in dt.Rows)
                    {
                        if (row.IsphotoNull())
                        {
                            imageLoaded = true;
                            return("");
                        }
                        else
                        {
                            Image  img = GetFromBytes(row.photo);
                            Bitmap bmp = new Bitmap(img);
                            bmp.Save(dir + IMG_PATH + "\\" + prfix + iid.ToString() + ".jpg", ImageFormat.Jpeg);
                            imageLoaded = true;
                            return(IMG_PATH + "\\" + prfix + iid.ToString() + ".jpg");
                        }
                    }
                }
                finally
                {
                    if (imageLoaded)
                    {
                        cmd.CommandText = "UPDATE " + table + " SET phLoaded = 1 WHERE iid=" + iid.ToString();
                        cmd.ExecuteNonQuery();
                    }
                }
                return("");
            }

            catch { return(""); }
        }