Kategori: Devexpress

Devexpress Grid Örneği

<dx:ASPxGridView ID="gvCardStationOperator" ClientInstanceName="gvCardStationOperator"
	runat="server" Width="100%" KeyFieldName="RuleID" OnDataBinding="gvCardStationOperator_DataBinding"
	AutoGenerateColumns="false" EnableTheming="false" ClientVisible="false" OnHtmlEditFormCreated="gvCardStationOperator_HtmlEditFormCreated"
	OnRowDeleting="gvCardStationOperator_RowDeleting" OnRowInserting="gvCardStationOperator_RowInserting"
	OnRowUpdating="gvCardStationOperator_RowUpdating">
	<Columns>
		<dx:GridViewDataColumn FieldName="LocationID" Visible="false" />
		<dx:GridViewDataColumn FieldName="StationID" Visible="false" />
		<dx:GridViewDataColumn FieldName="intValue1" Visible="false" />
		<dx:GridViewDataColumn FieldName="intValue2" Visible="false" />
		<dx:GridViewDataColumn FieldName="LocationName" Width="100px" Caption="Lokasyon"
			GroupIndex="0" />
		<dx:GridViewDataColumn FieldName="StationName" Width="100px" Caption="İstasyon İsmi" />
		<dx:GridViewDataColumn FieldName="NameSurname" Width="250px" Caption="Yetkili Kişi" />
		<dx:GridViewCommandColumn ButtonType="Image" Width="30px" Caption="Sil">
			<DeleteButton Text="Sil" Visible="True">
				<Image Url="~/images/ButtonImages/delete.png" Width="20px">
				</Image>
			</DeleteButton>
		</dx:GridViewCommandColumn>
	</Columns>
	<Templates>
		<TitlePanel>
			<table width="100%">
				<tr>
					<td align="left">
						Kart Bakiyesi Düşecek Personeller
					</td>
					<td align="right">
						<dx:ASPxButton runat="server" ID="btnNewPrice" ClientInstanceName="btnNewPrice" EnableTheming="False"
							EnableDefaultAppearance="False" AutoPostBack="False" ToolTip="Yeni Bölge Ekle"
							Style="cursor: pointer;" UseSubmitBehavior="false">
							<Image Width="22px" Height="22px" Url="~/images/ButtonImages/add.png" />
							<ClientSideEvents Click="function(s, e) {
											gvCardStationOperator.AddNewRow();
											}" />
						</dx:ASPxButton>
					</td>
				</tr>
			</table>
		</TitlePanel>
		<EditForm>
			<table style="width: 350px; padding: 15px">
				<tr>
					<td style="width: 120px;">
						<dx:ASPxLabel ID="lblLocation" runat="server" Text="Lokasyon" Width="100px" />
					</td>
					<td style="width: 220px;">
						<dx:ASPxComboBox ID="cbLocation" ClientInstanceName="cbLocation" runat="server" ValueType="System.Int32"
							EnableTheming="false">
							<ClientSideEvents SelectedIndexChanged="ChangedLocation" />
							<ValidationSettings RequiredField-IsRequired="true" RequiredField-ErrorText="Bu alan boş bırakılamaz!"
								ValidationGroup="ValidationAction" ErrorDisplayMode="ImageWithTooltip" />
						</dx:ASPxComboBox>
					</td>
				</tr>
				<tr>
					<td>
						<dx:ASPxLabel ID="ASPxLabel1" runat="server" Text="İstasyon" Width="100px" />
					</td>
					<td>
						<dx:ASPxComboBox ID="cbStation" ClientInstanceName="cbStation" runat="server" ValueType="System.Int32"
							EnableTheming="false" OnCallback="cbStation_Callback">
							<ValidationSettings RequiredField-IsRequired="true" RequiredField-ErrorText="Bu alan boş bırakılamaz!"
								ValidationGroup="ValidationAction" ErrorDisplayMode="ImageWithTooltip" />
						</dx:ASPxComboBox>
					</td>
				</tr>
				<tr>
					<td>
						<dx:ASPxLabel ID="ASPxLabel2" runat="server" Text="Kullanıcı" Width="100px" />
					</td>
					<td>
						<dx:ASPxComboBox ID="CbUserName" runat="server" ClientInstanceName="CbUserName" FilterMinLength="3"
							IncrementalFilteringMode="Contains" ValueType="System.Int32" ValueField="UserID"
							EnableCallbackMode="true" TextFormatString="{1}" CallbackPageSize="10" OnItemsRequestedByFilterCondition="CbUserName_OnItemsRequestedByFilterCondition_SQL"
							OnItemRequestedByValue="CbUserName_OnItemRequestedByValue_SQL" Width="300px"
							DropDownStyle="DropDown">
							<Columns>
								<dx:ListBoxColumn FieldName="UserID" Caption="ID" Width="0px" />
								<dx:ListBoxColumn FieldName="NameSurname" Caption="İsmi" />
								<dx:ListBoxColumn FieldName="Department" Caption="Departmanı" />
								<dx:ListBoxColumn FieldName="Title" Caption="Ünvanı" />
							</Columns>
							<ValidationSettings RequiredField-IsRequired="true" RequiredField-ErrorText="Bu alan boş bırakılamaz!"
								ValidationGroup="ValidationAction" ErrorDisplayMode="ImageWithTooltip" />
						</dx:ASPxComboBox>
					</td>
				</tr>
			</table>
			<center><table style="padding: 15px">
				<tr>
					<td>
						<dx:ASPxButton runat="server" ID="btnCloseOperator" ClientInstanceName="btnCloseOperator"
							AutoPostBack="false" Width="75px" Text="İptal">
							<ClientSideEvents Click="function(e,s){
										 gvCardStationOperator.CancelEdit();
							}" />
						</dx:ASPxButton>
					</td>
					<td>
						<dx:ASPxButton runat="server" ID="btnSaveOperator" ClientInstanceName="btnSaveOperator"
							AutoPostBack="false" Width="75px">
							<ClientSideEvents Click="function(e,s){
									if(ASPxClientEdit.ValidateGroup('ValidationAction'))
									{ 
										gvCardStationOperator.UpdateEdit();
									}
							}" />
						</dx:ASPxButton>
					</td>
				</tr>
			</table></center>
		</EditForm>
	</Templates>
	<Styles>
		<AlternatingRow Enabled="true" BackColor="WhiteSmoke">
		</AlternatingRow>
	</Styles>
	<Settings ShowFooter="True" />
	<SettingsPager PageSize="20" />
	<SettingsLoadingPanel Mode="Disabled" />
	<Settings ShowTitlePanel="True" ShowGroupPanel="True" />
	<SettingsBehavior ConfirmDelete="true" />
	<SettingsEditing Mode="PopupEditForm" EditFormColumnCount="1" />
	<SettingsPopup>
		<EditForm HorizontalAlign="WindowCenter" VerticalAlign="WindowCenter" />
	</SettingsPopup>
	<SettingsText PopupEditFormCaption="Operatör Ekle / Düzenle" ConfirmDelete="Operatörü silmeyi onaylıyor musunuz?" />
	<ClientSideEvents RowDblClick="function(s,e){ 
						gvCardStationOperator.StartEditRow(e.visibleIndex);
						gvCardStationOperator.SelectRow(e.visibleIndex,true);}" BeginCallback="function(s, e) { LoadingPanel.Show(); }"
		EndCallback="function (s, e) { 
						LoadingPanel.Hide();  
						if(gvCardStationOperator.cpOpenPopUp)
						{
							pUpInfo.Show();
							lblMessage.SetText(gvCardStationOperator.cpMessage);
							gvCardStationOperator.cpOpenPopUp=false;
						}
			  }" />
</dx:ASPxGridView>

 

protected void gvCardStationOperator_DataBinding(object sender, EventArgs e)
{
	if (Page.IsCallback || gvCardStationOperator.IsCallback)
	{
		if (Session["uc_CardRules"] != null)
			gvCardStationOperator.DataSource = Session["uc_CardRules"] as List<CardRule>;
		else
		{
			List<CardRule> _CardRule = new List<CardRule>();
			List<Filter> _FilterList = new List<Filter>();
			Filter _Filter = new Filter();
			_Filter.FieldName = "CardApp";
			_Filter.CriteriaMode = EnumsFilterCriteriaMode.Equal;
			_Filter.CriteriaOperator = EnumsFilterCriteriaOperator.And;
			_Filter.FilterIntValue = _CardApp;
			_FilterList.Add(_Filter);
			_Filter = new Filter();
			_Filter.FieldName = "Rule";
			_Filter.CriteriaMode = EnumsFilterCriteriaMode.Equal;
			_Filter.CriteriaOperator = EnumsFilterCriteriaOperator.And;
			_Filter.FilterIntValue = Convert.ToInt32(EnumsCardRule.CardStationOperator);
			_FilterList.Add(_Filter);
			var tmp = ucProxy.ObjectManager.GetCardRules(_FilterList.ToArray());
			if (tmp != null)
				_CardRule = tmp.ToList();

			Session["uc_CardRules"] = _CardRule;
			gvCardStationOperator.DataSource = _CardRule;
		}
	}
}
protected void gvCardStationOperator_HtmlEditFormCreated(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewEditFormEventArgs e)
{
	ASPxButton btnSave = (ASPxButton)gvCardStationOperator.FindEditFormTemplateControl("btnSaveOperator");
	ASPxComboBox cbLocation = (ASPxComboBox)gvCardStationOperator.FindEditFormTemplateControl("cbLocation");
	ASPxComboBox cbStation = (ASPxComboBox)gvCardStationOperator.FindEditFormTemplateControl("cbStation");
	ASPxComboBox cbUserName = (ASPxComboBox)gvCardStationOperator.FindEditFormTemplateControl("CbUserName");

	List<CardLocationObject> CardLocations = new List<CardLocationObject>();
	if (Session["uc_CardLocation"] == null)
	{
		List<Filter> _FilterList = new List<Filter>();
		Filter _Filter = new Filter();
		_Filter.FieldName = "CardApp";
		_Filter.CriteriaMode = EnumsFilterCriteriaMode.Equal;
		_Filter.CriteriaOperator = EnumsFilterCriteriaOperator.And;
		_Filter.FilterIntValue = _CardApp;
		_FilterList.Add(_Filter);
		_Filter = new Filter();
		_Filter.FieldName = "State";
		_Filter.CriteriaMode = EnumsFilterCriteriaMode.Equal;
		_Filter.CriteriaOperator = EnumsFilterCriteriaOperator.And;
		_Filter.FilterIntValue = Convert.ToInt32(EnumsCardState.Active);
		_FilterList.Add(_Filter);
		_Filter = new Filter();
		_Filter.FieldName = "ReduceBalance";
		_Filter.CriteriaMode = EnumsFilterCriteriaMode.Equal;
		_Filter.CriteriaOperator = EnumsFilterCriteriaOperator.And;
		_Filter.FilterIntValue = 0;
		_FilterList.Add(_Filter);

		var tmp = ucProxy.ObjectManager.GetCardLocations(_FilterList.ToArray());
		if (tmp != null)
			Session["uc_CardLocation"] = tmp.ToList();
		else
			Session["uc_CardLocation"] = new List<CardLocationObject>();
	}

	CardLocations = (List<CardLocationObject>)Session["uc_CardLocation"];
	foreach (CardLocationObject item in CardLocations)
	{
		cbLocation.Items.Add(item.LocationName, item.LocationID);
	}

	if (gvCardStationOperator.EditingRowVisibleIndex >= 0)
	{
		btnSave.Text = "Güncelle";
		CardRule _CardRule = (CardRule)gvCardStationOperator.GetRow(gvCardStationOperator.EditingRowVisibleIndex);
		FillStation(cbStation, _CardRule.LocationID);
		cbLocation.Items.FindByValue(_CardRule.LocationID).Selected = true;
		cbStation.Items.FindByValue(_CardRule.StationID).Selected = true;
		cbUserName.Items.Add(_CardRule.NameSurname, _CardRule.intValue2);
		cbUserName.SelectedIndex = 0;
	}
	else
		btnSave.Text = "Kaydet";
}
protected void gvCardStationOperator_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
{
	e.Cancel = true;
	DeleteOfflineAction(Convert.ToInt32(e.Keys[0]));
	gvCardStationOperator.CancelEdit();
}
protected void gvCardStationOperator_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
{
	ASPxGridView gridView = (ASPxGridView)sender;
	e.Cancel = true;
	SaveUpdateCardStationOperator(gridView);
	gridView.CancelEdit();
}
protected void gvCardStationOperator_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
{
	ASPxGridView gridView = (ASPxGridView)sender;
	e.Cancel = true;
	SaveUpdateCardStationOperator(gridView);
	gridView.CancelEdit();
}
protected void cbStation_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
{
	if (e.Parameter != null)
	{
		ASPxComboBox Combobox = (ASPxComboBox)sender;
		FillStation(Combobox, Convert.ToInt32(e.Parameter));
	}
}
protected void CbUserName_OnItemRequestedByValue_SQL(object source, ListEditItemRequestedByValueEventArgs e)
{
	//Olması gerek
}
protected void CbUserName_OnItemsRequestedByFilterCondition_SQL(object source, ListEditItemsRequestedByFilterConditionEventArgs e)
{
	if (e.Filter.Length >= 3)
	{
		ASPxComboBox cbUserName = (ASPxComboBox)source;
		UserService.User[] UserList = ucProxy.UserManager.GetUserListByName(e.Filter);
		cbUserName.DataSource = UserList;
		cbUserName.DataBind();
	}
}
private void SaveUpdateCardStationOperator(ASPxGridView gridView)
{
	try
	{
		ASPxComboBox cbStation = (ASPxComboBox)gvCardStationOperator.FindEditFormTemplateControl("cbStation");
		ASPxComboBox cbUserName = (ASPxComboBox)gvCardStationOperator.FindEditFormTemplateControl("CbUserName");

		int OperatorID = 0, StationID = 0;
		int.TryParse(cbUserName.Value.ToString(), out OperatorID);
		int.TryParse(cbStation.Value.ToString(), out StationID);

		if (OperatorID > 0 && StationID > 0)
		{
			int SaveID = 0;
			if (gvCardStationOperator.EditingRowVisibleIndex >= 0)
			{//Update
				CardRule _CardRuleRow = (CardRule)gvCardStationOperator.GetRow(gvCardStationOperator.EditingRowVisibleIndex);

				CardRule _CardRule = new CardRule();
				_CardRule.RuleID = _CardRuleRow.RuleID;
				_CardRule.ModifiedUserID = Convert.ToInt32(Session["UserId"].ToString());
				_CardRule.CardApp = _CardRuleRow.CardApp;
				_CardRule.Rule = EnumsCardRule.CardStationOperator;
				_CardRule.intValue1 = StationID;
				_CardRule.intValue2 = OperatorID;
				_CardRule.stringValue = string.Empty;

				SaveID = ucProxy.ObjectManager.SaveCardRule(_CardRule);
			}
			else
			{//Insert
				CardRule _CardRule = new CardRule();
				_CardRule.RuleID = 0;
				_CardRule.ModifiedUserID = Convert.ToInt32(Session["UserId"].ToString());
				_CardRule.CardApp = (EnumsCardApp)_CardApp;
				_CardRule.Rule = EnumsCardRule.CardStationOperator;
				_CardRule.intValue1 = StationID;
				_CardRule.intValue2 = OperatorID;
				_CardRule.stringValue = string.Empty;

				SaveID = ucProxy.ObjectManager.SaveCardRule(_CardRule);
			}

			if (SaveID > 0)
			{
				gvCardStationOperator.JSProperties["cpOpenPopUp"] = true;
				gvCardStationOperator.JSProperties["cpMessage"] = "Kayıt İşleminiz Başarıyla Gerçekleştirildi";
			}
			else
			{
				gvCardStationOperator.JSProperties["cpOpenPopUp"] = true;
				gvCardStationOperator.JSProperties["cpMessage"] = "Kayıt işleminiz gerçekleşemedi. Lütfen Sistem Yöneticinizle Görüşünüz";
			}
		}
		else
		{
			gvCardStationOperator.JSProperties["cpOpenPopUp"] = true;
			gvCardStationOperator.JSProperties["cpMessage"] = "Lütfen Tüm Alanları Eksiksiz Doldurunuz";
		}
		Session["uc_CardRules"] = null;
	}
	catch (Exception ex)
	{
		Session["uc_CardRules"] = null;
		gvCardStationOperator.JSProperties["cpOpenPopUp"] = true;
		gvCardStationOperator.JSProperties["cpMessage"] = "Beklenilmeyen Hata!\n\n" + ex.Message;
	}
}
private void DeleteOfflineAction(int RuleID)
{
	try
	{
		List<Filter> _FilterList = new List<Filter>();
		Filter _Filter = new Filter();
		_Filter.FieldName = "RuleID";
		_Filter.CriteriaMode = EnumsFilterCriteriaMode.Equal;
		_Filter.CriteriaOperator = EnumsFilterCriteriaOperator.And;
		_Filter.FilterIntValue = RuleID;
		_FilterList.Add(_Filter);

		var tmp = ucProxy.ObjectManager.GetCardRules(_FilterList.ToArray());
		if (tmp != null && tmp.Count() == 1)
		{
			CardRule _CardRule = tmp.FirstOrDefault();
			ucProxy.ObjectManager.DeleteCardRule(_CardRule.RuleID);
			gvCardStationOperator.JSProperties["cpMessage"] = "Silme İşleminiz Gerçekleşmiştir";

			Session["uc_CardRules"] = null;
			gvCardStationOperator.JSProperties["cpOpenPopUp"] = true;
		}
	}
	catch (Exception ex)
	{
		Session["uc_CardRules"] = null;
		gvCardStationOperator.JSProperties["cpOpenPopUp"] = true;
		gvCardStationOperator.JSProperties["cpMessage"] = "Beklenilmeyen Hata!\n\n" + ex.Message;
	}
}
private void FillStation(ASPxComboBox Combobox, int LocationID)
{
	List<Filter> _FilterList = new List<Filter>();
	Filter _Filter = new Filter();
	_Filter.FieldName = "LocationID";
	_Filter.CriteriaMode = EnumsFilterCriteriaMode.Equal;
	_Filter.CriteriaOperator = EnumsFilterCriteriaOperator.And;
	_Filter.FilterIntValue = LocationID;
	_FilterList.Add(_Filter);
	_Filter = new Filter();
	_Filter.FieldName = "State";
	_Filter.CriteriaMode = EnumsFilterCriteriaMode.Equal;
	_Filter.CriteriaOperator = EnumsFilterCriteriaOperator.And;
	_Filter.FilterIntValue = Convert.ToInt32(EnumsCardState.Active);
	_FilterList.Add(_Filter);
	var tmp = ucProxy.ObjectManager.GetCardStations(_FilterList.ToArray());
	if (tmp != null)
	{
		foreach (CardStationObject item in tmp)
		{
			Combobox.Items.Add(item.Description, item.StationID);
		}
	}
}