In my document which contains a lot of pages i need to Find specific name of text Frame, and if script will find it copy found pages into another document
var textFrame = app.activeDocument.textFrames.everyItem().getElements();
function doesLayerExist(layers, name) {
for (i=0; i<layers.length; i++) {
if (layers[i].name==name) return true;
}
return false;
}
if (doesLayerExist(app.activeDocument.layers, "SCRIPT")) {
alert("Warstwa Skrypt Istnieje");
if (textFrame[0].contents == "Test")
{
alert("Works!");
}
if (textFrame[0].contents == "Test2")
{
alert("Works!");
}
#......More if statements
}
Related
Here I have the SearchBar method, which, at the moment, searching keywords from my TITLE element of the Post Class. But I want to search by TITLE and LOCATION, which is the second element in my Post Class. How to add the LOCATION element from my Post class to the searchBar method?
private void searchBarmainPage_TextChanged(object sender, TextChangedEventArgs e)
{
try
{
using (SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation))
{
var keyword = e.NewTextValue;
conn.CreateTable<PostClass>();
var posts = conn.Table<PostClass>().ToList();
if(keyword.Length >= 1)
{
var results = posts.Where(x => x.Title.ToLower().Contains(keyword.ToLower()));
listViewMainPage.ItemsSource = results;
listViewMainPage.IsVisible = true;
}
else
{
listViewMainPage.IsVisible = false;
}
}
} catch (NullReferenceException r)
{
}catch (Exception m)
{
}
}
You can use the || operator to check if the keyword is contained inside the Title or inside the Location.
If you want the keyword to be in both places at the same type, you should use &&
using (SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation))
{
var keyword = e.NewTextValue;
conn.CreateTable<PostClass>();
var posts = conn.Table<PostClass>().ToList();
if(keyword.Length >= 1)
{
var results = posts.Where(x => x.Title.ToLower().Contains(keyword.ToLower()) || x.Location.ToLower().Contains(keyword.ToLower()) );
listViewMainPage.ItemsSource = results;
listViewMainPage.IsVisible = true;
}
else
{
listViewMainPage.IsVisible = false;
}
}
I have the below requirement.
I need to perform the sum of each field across multiple records of the same entity However while performing the sum, I also need to check the type and cast them accrodingly. For eg, For whole number cast to Int, For Decimal cast to decimal. Also some of the values are aliased value too. I am looking for a generic function which I can call for both alias fields and direct fields and it will return me the value based on the type
Background on the code written below -
Attribute List is the list of all attributes that belong to the
entity.
Format in which the field values are stored in AttributeList-
AttributeList = { "price ", "quantity", "contact.revenue", "opportunity.sales"}
price, quantity - fields of main entity on which we are querying
contact.revenue, opportunity.sales - fields of the aliased entities,
entity name is appended to understand which entity's field it is
Below is the code which i have tried so far -
I only have decimal and whole number fields in my attributeList.
private void calculate(List<string> attributeList,List<Entity> mainEntityList,Guid targetId,Guid oppId,Guid contactId)
{
var mainentity = new mainEntity();
mainentity.Id = targetId;
var opportunity = new Opportunity();
opportunity.Id = oppId;
var contact = new Contact();
contact.Id = contactId;
foreach (var attribute in attributeList)
{
var fieldSum = new decimal(0);
int intFieldSum = 0;
bool attributeFound = false;
foreach (var entity in mainEntityList)
{
if (entity.Contains(attribute))
{
var type = entity[attribute].GetType().Name;
attributeFound = true;
switch (type)
{
case "AliasedValue":
var aliasedFieldValue = entity.GetAttributeValue<AliasedValue>(attribute);
if (aliasedFieldValue.Value.GetType().Name == "Decimal")
{
decimalFieldSum += (decimal)aliasedFieldValue.Value;
}
else
{
intFieldSum += (int)aliasedFieldValue.Value;
}
break;
case "Decimal":
decimalFieldSum += entity.GetAttributeValue<decimal>(attribute);
break;
case "Int32":
intFieldSum += entity.GetAttributeValue<int>(attribute);
break;
default:
break;
}
}
}
if (attributeFound)
{
if (attribute.Contains("opportunity"))
{
opportunity[attribute] = decimalFieldSum != 0 ? decimalFieldSum : intFieldSum;
}
else if (attribute.Contains("contact"))
{
contact[attribute] = decimalFieldSum != 0 ? decimalFieldSum : intFieldSum;
}
else
{
mainentity[attribute] = decimalFieldSum != 0 ? decimalFieldSum : intFieldSum;
}
}
}
service.update(opportunity);
service.update(contact);
service.update(mainentity);
}
Any help would be appreciated.
Just a little bit edited your code.
...
var fieldSum = new decimal(0);
foreach (var entity in mainEntityList)
{
fieldSum += GetAttrValue(entity, attribute);
}
...
You can use this function to calculate fieldSum variable which is of decimal type.
private decimal GetAttrValue(Entity entity, string attribute)
{
var attrValue = new decimal(0);
if (!entity.Contains(attribute) || entity.Attributes[attribute] == null)
{
return attrValue;
}
var type = entity.Attributes[attribute].GetType().Name;
switch (type)
{
case "AliasedValue":
var aliasedFieldValue = entity.GetAttributeValue<AliasedValue>(attribute);
attrValue = type == "Decimal" ? (decimal)aliasedFieldValue.Value : (int)aliasedFieldValue.Value;
break;
case "Decimal":
attrValue = entity.GetAttributeValue<decimal>(attribute);
break;
case "Int32":
attrValue = entity.GetAttributeValue<int>(attribute);
break;
default:
break;
}
return attrValue;
}
On the other hand if you just need a generic function which will return decimal or int value for an attribute you can use this
private T GetAttrValue<T>(Entity entity, string attribute)
{
if (!entity.Contains(attribute) || entity.Attributes[attribute] == null)
{
return default(T);
}
T result;
var type = entity.Attributes[attribute].GetType().Name;
if (type == "AliasedValue")
{
var aliasedFieldValue = entity.GetAttributeValue<AliasedValue>(attribute);
result = (T)aliasedFieldValue.Value;
}
else
{
result = entity.GetAttributeValue<T>(attribute);
}
return result;
}
--Update--
So, here is the whole code if I understand you requirements right.
First of all add this class.
public class AttributeInfo
{
public string Name { get; set; }
public Type Type { get; set; }
public decimal DecimalSum { get; set; } = new decimal(0);
public int IntSum { get; set; } = 0;
}
And add this function
private void SetValue(Entity entity, AttributeInfo attributeInfo)
{
if (entity.Contains(attributeInfo.Name))
{
switch (attributeInfo.Type.Name)
{
case "Decimal":
entity[attributeInfo.Name] = attributeInfo.DecimalSum;
break;
case "Int32":
entity[attributeInfo.Name] = attributeInfo.IntSum;
break;
default:
break;
}
}
}
Then this is you Calculate function
private void Calculate(List<string> attributeList, List<Entity> mainEntityList, Guid targetId, Guid oppId, Guid contactId)
{
var mainentity = new mainEntity();
mainentity.Id = targetId;
var opportunity = new Opportunity();
opportunity.Id = oppId;
var contact = new Contact();
contact.Id = contactId;
var attributesInfo = new List<AttributeInfo>();
foreach (var attribute in attributeList)
{
var attributeInfo = new AttributeInfo
{
Name = attribute
};
foreach (var entity in mainEntityList)
{
if (entity.Contains(attribute))
{
attributeInfo.Type = entity[attribute].GetType();
switch (attributeInfo.Type.Name)
{
case "AliasedValue":
var aliasedFieldValue = entity.GetAttributeValue<AliasedValue>(attribute);
if (aliasedFieldValue.Value.GetType().Name == "Decimal")
{
attributeInfo.DecimalSum += (decimal)aliasedFieldValue.Value;
}
else
{
attributeInfo.IntSum += (int)aliasedFieldValue.Value;
}
break;
case "Decimal":
attributeInfo.DecimalSum += entity.GetAttributeValue<decimal>(attribute);
break;
case "Int32":
attributeInfo.IntSum += entity.GetAttributeValue<int>(attribute);
break;
default:
break;
}
}
}
attributesInfo.Add(attributeInfo);
}
foreach (var attributeInfo in attributesInfo)
{
if (attributeInfo.Type != null)
{
SetValue(mainentity, attributeInfo);
SetValue(opportunity, attributeInfo);
SetValue(contact, attributeInfo);
}
}
service.update(mainentity);
service.update(opportunity);
service.update(contact);
}
I should say that the structure of the calculate function still seems weird for me. However, here I tried to keep the main structure.
Having DataGrind In Windows application Enable search option like Microsoft Excel search entire sheet (DataGrid).
foreach (DataGridViewRow row in DisplayGridView.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
if (cell.Value == searchValue)
{
cell.Selected = true;
break;
}
}
}
I have tried above method but not getting result. I have impliment this code
foreach (DataGridViewRow row in DisplayGridView.Rows)
{
for (int i = 0; i < DisplayGridView.Columns.Count; i++)
{
if (row.Cells[i].Value.ToString().Equals(searchValue))
{
row.Cells[i].Selected = true;
break;
}
}
}
Still, the result is null can anyone suggest the code.
I am assuming you are not checking for null values. Adding these null value checks appears to work as you describe. Adding the ToString() method to the line : cell.Value == searchValue after Value makes the comparison successful. Also the breaks are not needed.
DisplayGridView.ClearSelection();
foreach (DataGridViewRow row in DisplayGridView.Rows) {
foreach (DataGridViewCell cell in row.Cells) {
if (cell.Value != null) {
if (cell.Value.ToString() == searchValue) {
cell.Selected = true;
}
}
}
}
Next method
DisplayGridView.ClearSelection();
foreach (DataGridViewRow row in DisplayGridView.Rows) {
for (int i = 0; i < DisplayGridView.Columns.Count; i++) {
if (row.Cells[i].Value != null) {
if (row.Cells[i].Value.ToString().Equals(searchValue)) {
row.Cells[i].Selected = true;
}
}
}
}
If you want to highlight the cell if the search string is contained in the cells string, then you only need to change the equals method to contains.
DisplayGridView.ClearSelection();
foreach (DataGridViewRow row in DisplayGridView.Rows) {
foreach (DataGridViewCell cell in row.Cells) {
if (cell.Value != null) {
if (cell.Value.ToString().Contains(searchValue)) {
cell.Selected = true;
}
}
}
}
Hope this helps.
I have a RadPageview in Strip Mode and I want my program to had support a right-to-left language. When I changing the Right-to-Left Property to true it works fine. but when I run my program and use Arrow Keys (Left or Right) it doesn't work correctly. Left key goes to Right and Right key goes to Left. How can I fix it?
Telerik answered my question:
http://www.telerik.com/forums/right-to-left-arrow-keys-problem
the possible solution that I can suggest is to create a custom RadPageViewStripElement and override its IsNextKey and IsPreviousKey methods on a way to reverse the previous/next navigation as follows:
public class CustomPageView : RadPageView
{
public override string ThemeClassName
{
get
{
return typeof(RadPageView).FullName;
}
}
protected override RadPageViewElement CreateUI()
{
switch (this.ViewMode)
{
case PageViewMode.Strip:
return new CustomRadPageViewStripElement();
default:
return base.CreateUI();
}
}
}
public class CustomRadPageViewStripElement : RadPageViewStripElement
{
public CustomRadPageViewStripElement()
{
}
protected override Type ThemeEffectiveType
{
get
{
return typeof(RadPageViewStripElement);
}
}
protected override bool IsNextKey(Keys key)
{
if (this.RightToLeft)
{
if (key == Keys.Left)
{
return true;
}
else
{
return false;
}
}
return base.IsNextKey(key);
}
protected override bool IsPreviousKey(Keys key)
{
if (this.RightToLeft)
{
if (key == Keys.Right)
{
return true;
}
else
{
return false;
}
}
return base.IsPreviousKey(key);
}
}
I fix it programmatically by using ProcessCmdKey of form.
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.Right))
{
int x = radPageView1.Pages.IndexOf(this.radPageView1.SelectedPage) - 1;
if (x < 0)
x = radPageView1.Pages.Count() - 1;
else if (x >= radPageView1.Pages.Count())
x = 0;
radPageView1.SelectedPage = radPageView1.Pages[x];
return true;
}
else if(keyData == Keys.Left)
{
int x = radPageView1.Pages.IndexOf(this.radPageView1.SelectedPage) + 1;
if (x <= 0)
x = radPageView1.Pages.Count() - 1;
else if (x >= radPageView1.Pages.Count())
x = 0;
radPageView1.SelectedPage = radPageView1.Pages[x];
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
How to know if a *.lnk file link to something or not. How can I achieve that in C#?
Get the Link Target Getting specific file attributes
Check the file from Link Target Path if exist using the File.Exists
class Program
{
[STAThread]
static void Main()
{
List<string> arrHeaders = new List<string>();
Shell32.Shell shell = new Shell32.Shell();
Shell32.Folder objFolder;
objFolder = shell.NameSpace(#"D:\shortcuts");
for (int i = 0; i < short.MaxValue; i++)
{
string header = objFolder.GetDetailsOf(null, i);
if (String.IsNullOrEmpty(header))
break;
arrHeaders.Add(header);
}
foreach (Shell32.FolderItem2 item in objFolder.Items())
{
for (int i = 0; i < arrHeaders.Count; i++)
{
//Console.WriteLine("{0}\t{1}: {2}", i, arrHeaders[i], objFolder.GetDetailsOf(item, i));
if (arrHeaders[i] == "Link target")
{
var getPath = objFolder.GetDetailsOf(item, i);
Console.WriteLine("{0}", getPath);
if (File.Exists(getPath))
{
Console.WriteLine("The file exists.");
}
else
{
Console.WriteLine("File not exist");
//Do stuff to delete
}
}
}
}
Console.ReadLine();
}
}