private static void RepreshOp(object prm)
        {
            RefreshOpMutex.WaitOne();
            try
            {
                LongStringClass msg = prm as LongStringClass;
                if (msg == null)
                {
                    return;
                }

                //List<ONLoperation> closedOp = new List<ONLoperation>();
                var closedOp = from o in staticDc.ONLoperations
                               where o.comp_id == msg.CompID &&
                               o.state == Constants.OP_STATE_SENT &&
                               o.ONLClimberCompLinks.Count(lnk => lnk.state != Constants.CLIMBER_CONFIRMED) == 0
                               select o;
                if (closedOp.Count() > 0)
                {
                    if (!String.IsNullOrEmpty(msg.Message))
                    {
                        try
                        {
                            var dbAdminList = (from ur in staticDc.ONLuserRoles
                                               where (ur.comp_id == msg.CompID && ur.role_id == Constants.ROLE_ADMIN) ||
                                               ur.role_id == Constants.ROLE_ADMIN_ROOT
                                               select ur.ONLuser.email).Distinct();
                            MailService ms = new MailService(staticDc, msg.CompID);
                            foreach (var s in dbAdminList)
                            {
                                try
                                {
                                    string sErr;
                                    ms.SendMail(s, "Получена заявка",
                                                msg.Message, System.Net.Mail.MailPriority.Normal, out sErr);
                                }
                                catch { }
                            }
                        }
                        catch { }
                    }
                    string inL = "";
                    Dictionary <string, ONLuser> uList = new Dictionary <string, ONLuser>();
                    foreach (var n in closedOp)
                    {
                        n.state = Constants.OP_STATE_CONFIRMED;
                        if (inL != "")
                        {
                            inL += ",";
                        }
                        inL += n.ToString();
                        if (!uList.ContainsKey(n.user_id))
                        {
                            uList.Add(n.user_id, n.ONLuser);
                        }
                    }
                    foreach (var v in uList)
                    {
                        v.Value.messageToSend = String.Empty;
                    }
                    staticDc.SaveChanges();
                }
            }
            catch { }
            finally { RefreshOpMutex.ReleaseMutex(); }
        }
        protected void gvApps_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                int rowN = Convert.ToInt32(e.CommandArgument);
                gvApps.SelectRow(rowN);

                long iid = Convert.ToInt64(gvApps.SelectedValue);

                string clmName            = gvApps.SelectedRow.Cells[2].Text;
                ClimbingConfirmations cfs = new ClimbingConfirmations();
                SqlCommand            cmd = new SqlCommand();
                cmd.Connection = cn;
                bool   reloadApps = false;
                string clmStr     = getClmString(iid);
                switch (e.CommandName)
                {
                case "ConfirmLine":
                    bool cDel, qfErr, cEdit;
                    reloadApps = true;
                    string message;
                    switch (cfs.ConfirmClimber(iid, out cDel, out cEdit, out qfErr, out message))
                    {
                    case InsertingResult.SUCCESS:
                        if (cDel)
                        {
                            LblErrorMessage.Text = "Участник " + clmName + " успешно удалён";
                            MessageString        = MessageString + "\r\n" + clmStr + "Удаление";
                        }
                        else
                        {
                            MessageString        = MessageString + "\r\n" + clmStr + (cEdit ? "Правка" : "Добавление");
                            LblErrorMessage.Text = "Участник " + clmName + " успешно " + (cEdit ? "изменён" : "внесён в базу данных");
                        }
                        break;

                    case InsertingResult.QUOTA_EXCEED:
                        LblErrorMessage.Text = "Участник " + clmName + " не был добавлен по причине превышения квоты";
                        break;

                    case InsertingResult.TO_QUEUE:
                        MessageString        = MessageString + "\r\n" + clmStr + "В очередь";
                        LblErrorMessage.Text = "Участник " + clmName + " был поставлен в очередь.";
                        break;

                    case InsertingResult.DUPLICATE:
                        reloadApps           = false;
                        LblErrorMessage.Text = "Такой участник уже есть в БД";
                        break;

                    default:
                        reloadApps           = false;
                        LblErrorMessage.Text = "Ошибка зявки учатника " + clmName;
                        break;
                    }
                    if (qfErr)
                    {
                        LblErrorMessage.Text += "; " + ClimbingConfirmations.RAZR_NOTE;
                    }
                    if (!String.IsNullOrEmpty(message))
                    {
                        LblErrorMessage.Text += "<br />" + message;
                    }
                    break;

                case "DeleteLine":
                    var toDel = dc.ONLClimberCompLinks.First(l => l.iid == iid);
                    List <ONLClimberCompLink> tUpd = new List <ONLClimberCompLink>();
                    foreach (var v in toDel.ONLClimberCompLink1)
                    {
                        tUpd.Add(v);
                    }
                    foreach (var v in tUpd)
                    {
                        v.replacementID = null;
                    }
                    dc.SaveChanges();
                    dc.ONLClimberCompLinks.DeleteObject(toDel);
                    dc.SaveChanges();
                    LblErrorMessage.Text = "Заявка на участника " + clmName + " отменена.";
                    reloadApps           = true;
                    break;

                case "EditLine":
                    SetToEdit(iid);
                    return;
                }
                if (reloadApps)
                {
                    LongStringClass lstr = new LongStringClass(compID, MessageString);
                    Thread          thr  = new Thread(RepreshOp);
                    thr.Start(lstr);
                }
                RefreshTable();
            }
            catch (Exception ex)
            {
                LblErrorMessage.Text = "Ошибка правки";
                if (User.IsInRole(Constants.ROLE_ADMIN, compID))
                {
                    LblErrorMessage.Text += ": " + ex.Message;
                }
            }
        }