protected void UpdateSelfPhone(object sender, GridViewUpdateEventArgs e) { var GridView1 = (GridView)EmployeeFormView.FindControl("GridView2"); var SpecificStaffPlaceId = (Guid)e.Keys[0]; string currentPhoneNumber = ((TextBox)GridView1.Rows[e.RowIndex] .FindControl("txtCompanyName1")).Text; string currentPhoneType = ((DropDownList)GridView1.Rows[e.RowIndex] .FindControl("PhoneTypeDropDownList5")).SelectedValue; string commandText = "update SpecificStaffPlace set PhoneTypeId='" + currentPhoneType + "',PhoneNumber='" + currentPhoneNumber + "' where Id='" + SpecificStaffPlaceId + "'"; SqlConnection connection = DBHelper.GetConnection(); var cmd = new SqlCommand(commandText, connection) { CommandType = CommandType.Text }; try { connection.Open(); cmd.ExecuteNonQuery(); } catch (Exception ex) { ShellLogger.WriteLog("DB.log", "Ошибка обновления стационарного номера", ex); } finally { connection.Close(); } }
protected void AddFavoritesClicked(object sender, ImageClickEventArgs e) { var currentUserGuid = new Guid(Session["CurrentUser"].ToString()); string commandArguents = ((ImageButton)sender).CommandArgument; string commandText = "RemoveFavorites"; var favoriteUserGuid = new Guid(commandArguents); SqlConnection connection = DBHelper.GetConnection(); var cmd = new SqlCommand(commandText, connection) { CommandType = CommandType.StoredProcedure }; cmd.Parameters.Add("@ParentUserGuid", SqlDbType.UniqueIdentifier); cmd.Parameters["@ParentUserGuid"].Value = currentUserGuid; cmd.Parameters.Add("@FavoriteUserGuid", SqlDbType.UniqueIdentifier); cmd.Parameters["@FavoriteUserGuid"].Value = favoriteUserGuid; try { connection.Open(); cmd.ExecuteNonQuery(); GridView1.DataBind(); } catch (Exception ex) { ShellLogger.WriteLog("DB.log", "Ошибка добаления сотрудника в избранное", ex); } finally { connection.Close(); } }
//protected void EmployeeFormView_ItemUpdated(object sender, FormViewUpdatedEventArgs e) //{ // TextBox streetTextBox = (TextBox) EmployeeFormView.FindControl("StreetTextBox"); // string currentStreet = streetTextBox.Text; // TextBox edificeTextBox = (TextBox) EmployeeFormView.FindControl("EdificeTextBox"); // string currentEdifice = edificeTextBox.Text; // DropDownList regionList = (DropDownList) EmployeeFormView.FindControl("RegionList"); // string currentRegion = regionList.SelectedValue; // UpdateEmployeeAddress(new Guid(currentRegion), currentStreet, currentEdifice); //} private void UpdateEmployeeAddress(Guid EmployeePlaceId, Guid region, string street, string edifice, string phone, Guid phoneType) { if (region == Guid.Empty) { string script = "<script type='text/javascript'>showError("; script += "'Ошибка выбора региона для сотрудника!'"; script += ");</script>"; ScriptManager.RegisterStartupScript(Page, GetType(), "tmp3", script, false); return; } const string commandText = "UpdateEmployeeAddress"; SqlConnection connection = DBHelper.GetConnection(); var cmd = new SqlCommand(commandText, connection) { CommandType = CommandType.StoredProcedure }; cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier); cmd.Parameters["@Guid"].Value = new Guid(Request.QueryString["ID"]); cmd.Parameters.Add("@EmployeePlaceId", SqlDbType.UniqueIdentifier); cmd.Parameters["@EmployeePlaceId"].Value = EmployeePlaceId; cmd.Parameters.Add("@Region", SqlDbType.UniqueIdentifier); cmd.Parameters["@Region"].Value = region; cmd.Parameters.Add("@Street", SqlDbType.NVarChar); cmd.Parameters["@Street"].Value = street; cmd.Parameters.Add("@Edifice", SqlDbType.NVarChar); cmd.Parameters["@Edifice"].Value = edifice; cmd.Parameters.Add("@Phone", SqlDbType.NVarChar); cmd.Parameters["@Phone"].Value = phone; cmd.Parameters.Add("@PhoneType", SqlDbType.UniqueIdentifier); cmd.Parameters["@PhoneType"].Value = phoneType; try { connection.Open(); cmd.ExecuteScalar(); } catch (Exception ex) { ShellLogger.WriteLog("DB.log", "Ошибка обновления адреса сотрудника", ex); } finally { connection.Close(); } }
private Dictionary <Guid, string> GetDivisionParents(Guid divisionGuid) { var departments = new Dictionary <Guid, string>(); const string commandText = "GetDivisionAllParents"; SqlConnection connection = DBHelper.GetConnection(); var cmd = new SqlCommand(commandText, connection) { CommandType = CommandType.StoredProcedure }; cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier); cmd.Parameters["@Guid"].Value = divisionGuid; SqlDataReader reader = null; try { connection.Open(); reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { Guid idItem = reader.GetGuid(0); string itemType = reader.GetString(1); departments.Add(idItem, itemType); } } } catch (Exception ex) { ShellLogger.WriteLog("DB.log", "Ошибка GetDivisionParentsв", ex); //Response.Write("<script>window.alert('Ошибка приложения');</script>"); } finally { if (reader != null && !reader.IsClosed) { reader.Close(); } connection.Close(); } return(departments); }
/// <summary> /// Получение списка DepartmentState /// </summary> /// <param name="parentNode"></param> /// <returns></returns> private Dictionary <Guid, string> GetDepartmentState(Guid parentNode) { var departments = new Dictionary <Guid, string>(); string commandText = parentNode == Guid.Empty ? "select Id,Department,ParentId from DepartmentState where ExpirationDate IS NULL AND ParentId is null" : "select Id,Department,ParentId from DepartmentState where ExpirationDate IS NULL AND ParentId ='" + parentNode + "'"; SqlConnection connection = DBHelper.GetConnection(); var cmd = new SqlCommand(commandText, connection); SqlDataReader reader = null; try { connection.Open(); reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { Guid idDepartment = reader.GetGuid(0); string department = reader.GetString(1); if (!departments.ContainsKey(idDepartment)) { departments.Add(idDepartment, department); } } } } catch (Exception ex) { ShellLogger.WriteLog("DB.log", "Ошибка GetDepartmentStateв", ex); //Response.Write("<script>window.alert('Ошибка приложения');</script>"); } finally { if (reader != null && !reader.IsClosed) { reader.Close(); } connection.Close(); } return(departments); }
/// <summary> /// Признак наличия у элемента потомков /// </summary> /// <param name="treeNodeType">Тип элемента дерева</param> /// <param name="parent">Идентификатор родительского элемента</param> /// <returns>true-у родителя есть потомки</returns> private bool IsHasChilds(DepartmentTreeNodeType treeNodeType, Guid parent) { string commandText = string.Empty; switch (treeNodeType) { case DepartmentTreeNodeType.DivisionState: commandText = "select count(Id) as ChildsCount from DivisionState where ParentId='" + parent + "'"; break; case DepartmentTreeNodeType.DepartmentState: commandText = "select count(Id) as ChildsCount from DepartmentState where ExpirationDate IS NULL AND ParentId='" + parent + "'"; break; } SqlConnection connection = DBHelper.GetConnection(); var cmd = new SqlCommand(commandText, connection); try { connection.Open(); string childCount = cmd.ExecuteScalar().ToString(); int nodeChildsCount; if (int.TryParse(childCount, out nodeChildsCount)) { if (nodeChildsCount > 0) { return(true); } } } catch (Exception ex) { ShellLogger.WriteLog("DB.log", "Ошибка проверки наличия дочерних элементов", ex); } finally { connection.Close(); } return(false); }
protected void AddFavoritesClicked(object sender, ImageClickEventArgs e) { var currentUserGuid = new Guid(Session["CurrentUser"].ToString()); string[] commandArguents = ((ImageButton)sender).CommandArgument.Split(';'); bool isFavorite = bool.Parse(commandArguents[1]); var favoriteUserGuid = new Guid(commandArguents[0]); SqlConnection connection = DBHelper.GetConnection(); string commandText = isFavorite ? "RemoveFavorites" : "AddFavorites"; var cmd = new SqlCommand(commandText, connection) { CommandType = CommandType.StoredProcedure }; cmd.Parameters.Add("@ParentUserGuid", SqlDbType.UniqueIdentifier); cmd.Parameters["@ParentUserGuid"].Value = currentUserGuid; cmd.Parameters.Add("@FavoriteUserGuid", SqlDbType.UniqueIdentifier); cmd.Parameters["@FavoriteUserGuid"].Value = favoriteUserGuid; try { connection.Open(); cmd.ExecuteNonQuery(); EmployeeFormView.DataBind(); //string popupScript = "<script language='javascript'>" +"showSuccessToast();" +"</script>"; //Page.ClientScript.RegisterStartupScript(typeof(Page), "popupScript", popupScript); } catch (Exception ex) { ShellLogger.WriteLog("DB.log", "Ошибка добаления сотрудника в избранное", ex); } finally { connection.Close(); } }
protected void DeleteSelfPhone(object sender, ImageClickEventArgs e) { var remove = (ImageButton)sender; string commandText = "delete from SpecificStaffPlace where Id='" + remove.CommandArgument + "'"; SqlConnection connection = DBHelper.GetConnection(); var cmd = new SqlCommand(commandText, connection) { CommandType = CommandType.Text }; try { connection.Open(); cmd.ExecuteNonQuery(); } catch (Exception ex) { ShellLogger.WriteLog("DB.log", "Ошибка удаления стационарного номера", ex); } finally { connection.Close(); } }