Please check the code below :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using iTimeService.dsitimeTableAdapters;
using System.IO;
namespace iTimeService
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
public zkemkeeper.CZKEMClass axCZKEM1 = new zkemkeeper.CZKEMClass();
private bool bIsConnected = false;//the boolean value identifies whether the device is connected
private int iMachineNumber = 1;//the serial number of the device.After connecting the device ,this value will be changed.
TENTERTableAdapter tenteradapter = new TENTERTableAdapter();
T012_GATETableAdapter gateadapter = new T012_GATETableAdapter();
}
}
I am getting an error on the object creation of zkemkeeper.CZKEMClass where it says : interop type 'zkemkeeper.CZKEMClass' cannot be embedded. Use the application interface instead.
click on the reference you have, I think for that specific project that would be 'zkemkeeper'
then on its properties just set the 'Embed Interop Type' to 'False'
I hope this would help.
OK, Thanks!
private MayChamCongBLL _mayChamCongBLL = new MayChamCongBLL();
private MayChamCongDTO _mayChamCongDTO = new MayChamCongDTO();
// private System.Configuration.Configuration _ngonNgu = ConfigurationManager.OpenExeConfiguration("MitaAttendance.exe");
private int a;
private ArrayList arrMayChamCong = new ArrayList();
//public CZKEM axCZKEM1 = new CZKEM();
public zkemkeeper.CZKEMClass axCZKEM1 = new zkemkeeper.CZKEMClass();
private int b;
// private Bar bar1;
private bool bIsConnected = false;
private int c;
private string sMaMayChamCong;
private string sSuDungWeb;
private int iMachineNumber = 1;
private int iNgonNgu;
private CZKEMClass axCZKEM1 = new CZKEMClass();
private static bool _bIsConnected = false;
private static int _iMachineNumber = 1;
private static int _errorCode = 0;
public bool GetConnectState()
{
return _bIsConnected;
}
private void SetConnectState(bool state)
{
_bIsConnected = state;
}
private int GetMachineNumber()
{
return _iMachineNumber;
}
public int sta_ConnectTCP(string ip, string port, string commKey)
{
if (ip == "" || port == "" || commKey == "")
{
return -1;// ip or port is null
}
if (Convert.ToInt32(port) <= 0 || Convert.ToInt32(port) > 65535)
{
return -1;
}
if (Convert.ToInt32(commKey) < 0 || Convert.ToInt32(commKey) > 999999)
{
return -1;
}
int idwErrorCode = 0;
axCZKEM1.SetCommPassword(Convert.ToInt32(commKey));
if (_bIsConnected)
{
axCZKEM1.Disconnect();
SetConnectState(false);
return -2; //disconnect
}
if (axCZKEM1.Connect_Net(ip, Convert.ToInt32(port)))
{
SetConnectState(true);
return 1;
}
else
{
axCZKEM1.GetLastError(ref idwErrorCode);
return idwErrorCode;
}
}
public void sta_DisConnect()
{
if (GetConnectState())
{
axCZKEM1.Disconnect();
}
}
public int sta_ReadNewAttLog(DataTable dt_log)
{
if (GetConnectState() == false)
{
//Please connect first!";
return -1024;
}
int ret = 0;
axCZKEM1.EnableDevice(GetMachineNumber(), false);//disable the device
string sdwEnrollNumber = "";
int idwVerifyMode = 0;
int idwInOutMode = 0;
int idwYear = 0;
int idwMonth = 0;
int idwDay = 0;
int idwHour = 0;
int idwMinute = 0;
int idwSecond = 0;
int idwWorkcode = 0;
if (axCZKEM1.ReadNewGLogData(GetMachineNumber()))
{
while (axCZKEM1.SSR_GetGeneralLogData(GetMachineNumber(), out sdwEnrollNumber, out idwVerifyMode,
out idwInOutMode, out idwYear, out idwMonth, out idwDay, out idwHour, out idwMinute, out idwSecond, ref idwWorkcode))//get records from the memory
{
DataRow dr = dt_log.NewRow();
dr["User ID"] = sdwEnrollNumber;
dr["Verify Date"] = idwYear + "-" + idwMonth + "-" + idwDay + " " + idwHour + ":" + idwMinute + ":" + idwSecond;
dr["idwYear"] = idwYear;
dr["idwMonth"] = idwMonth;
dr["idwDay"] = idwDay;
dr["idwHour"] = idwHour;
dr["idwMinute"] = idwMinute;
dr["idwSecond"] = idwSecond;
dr["Verify Type"] = idwVerifyMode;
dr["Verify State"] = idwInOutMode;
dr["WorkCode"] = idwWorkcode;
dt_log.Rows.Add(dr);
}
ret = 1;
}
else
{
axCZKEM1.GetLastError(ref _errorCode);
ret = _errorCode;
if (_errorCode != 0)
{
//"*Read attlog by period failed,ErrorCode: " + idwErrorCode.ToString();
}
else
{
//"No data from terminal returns!";
}
}
//lblOutputInfo.Items.Add("[func ReadNewGLogData]Temporarily unsupported");
axCZKEM1.EnableDevice(GetMachineNumber(), true);//enable the device
return ret;
}
Related
Given two strings s and t, determine length of shortest string z such that z is a subsequence of s and not a subsequence of t.
example :
s :babab,
t :babba
sol :
3 (aab)
not looking for copy pastable code, please if anybody can help with intution for solving this.
thanks a lot !
Here you go. I created on IEnumarable method which gives back all possible combinations. This is compared with t. I optimized the solution to loop only once over the not match String t.
using System;
using System.Collections.Generic;
namespace GuessTheNumber
{
public class Element:IComparable<Element>
{
public string Seq { get; set; }
public int Id { get; set; }
public int CompareTo(Element other)
{
return this.Seq.CompareTo(other.Seq);
}
}
class Program
{
static void Main(string[] args)
{
string s = "babab";
string t = "babba";
string z = ShortestUncommonSuqsequence(s, t);
}
static public string ShortestUncommonSuqsequence(string SubSequenceOf, string NotSubSequenceOf)
{
var uniqueSeq = new SortedList<Element, int>();
uniqueSeq.Add(new Element() { Seq = "", Id = -1 }, -1);
foreach (Element oneSequence in GetNextUniqueSequences(uniqueSeq, SubSequenceOf))
{
int index = oneSequence.Id + 1;
while (index < NotSubSequenceOf.Length)
{
char NotChar = NotSubSequenceOf[index];
if (oneSequence.Seq[oneSequence.Seq.Length - 1] == NotChar) break;
index++;
}
if (index == NotSubSequenceOf.Length)
{
return oneSequence.Seq;
}
else
{
oneSequence.Id = index;
}
}
return null;
}
static public IEnumerable<Element> GetNextUniqueSequences(SortedList<Element, int> UniqueSeq, string Input)
{
SortedList<Element, int> results = new SortedList<Element, int>();
foreach (var prevResult in UniqueSeq)
{
for (int i = 0; i < Input.Length; i++)
{
if (prevResult.Value < prevResult.Key.Seq.Length + i)
{
string nextStr = prevResult.Key.Seq + Input[i].ToString();
Element newElem = new Element() { Seq = nextStr, Id = prevResult.Key.Id };
if (!results.Keys.Contains(newElem))
{
results.Add(newElem, prevResult.Key.Seq.Length + i);
yield return newElem;
}
}
}
}
if (Input.Length > 1)
{
foreach (Element res in GetNextUniqueSequences(results, Input.Substring(1)))
{
yield return res;
}
}
}
}
}
I want to sort an ArrayList of High scores. The list contains objects, which each contain String name, String category and int score. I want to sort the ArrayList into descending order by score:
This is what I have at the moment, however it crashes the program when the procedure runs:
**INITIALIZING ARRAY AND VARIABLES:**
private static ArrayList<HighScore> highScores = new ArrayList<HighScore>();
private static int Last;
private static int First = 0;
private static int PivotValue;
private static int LeftPointer;
private static int RightPointer;
private static int Pivot;
**READING IN VALUES INTO ARRAYLIST**
String File = "src/project/res/highscores.txt";
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(File));
while ((line = br.readLine()) != null) {
HighScore h = new HighScore(line);
highScores.add(h);
}
} catch (Exception e) {
System.out.println("Problem reading in high scores!");
}
**CALLING THE PROCEDURE**
quickSort(highScores,First,Last);
private static void quickSort(ArrayList<HighScore> highScores2, int first, int last){
if(first < last)
{
PivotValue = highScores2.get(first).getScore();
LeftPointer = first + 1;
RightPointer = last;
while((LeftPointer <= RightPointer))
{
while((LeftPointer <= RightPointer)&&(highScores2.get(LeftPointer).getScore() < PivotValue))
{
LeftPointer++;
}
while((highScores2.get(RightPointer).getScore() > PivotValue)&&(LeftPointer <= RightPointer))
{
RightPointer--;
}
if(LeftPointer < RightPointer)
{
HighScore temp = highScores2.get(LeftPointer);
highScores2.set(RightPointer, highScores2.get(LeftPointer));
temp.equals(highScores2.get(RightPointer));
}
}
Pivot = RightPointer;
HighScore temp = highScores2.get(first);
highScores2.set(Pivot,highScores2.get(first));
temp.equals(highScores2.get(Pivot));
quickSort(highScores2, first, Pivot-1);
quickSort(highScores2, Pivot + 1, last);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
public enum Suit
{
Club,
Diamond,
Heart,
Spade
}
public static int i = 0;
public class Card
{
private Suit suit;
private int rank;
private string pictureUrl;
public Suit Suit
{
get { return suit;}
set { suit = value; }
}
public int Rank
{
get { return rank; }
set { rank = value; }
}
public string PictureUrl
{
get { return pictureUrl; }
set { pictureUrl = value; }
}
public Card(Suit suit, int rank, string pictureUrl)
{
this.suit = suit;
this.rank = rank;
this.pictureUrl = pictureUrl;
}
}
protected void InitDeck(List<Card> deck)
{
for (int suit = 0; suit < 4; suit++)
for (int rank = 0; rank < 13; rank++)
{
string strPath = "Images\\" + (suit * 13 + rank).ToString() + ".png";
deck.Add(new Card((Suit)suit, rank + 2, strPath));
}
}
protected void InitGameBoard(Card[,] gameBoard, List<Card> deck)
{
Random rnd = new Random();
int rndPosition;
for(int i = 0; i < 5; i++)
for (int j = 0; j < 5; j++)
{
if (i == 4 && j == 4)
{
gameBoard[i, j] = new Card(0, 100, "Images\\b1fv.png");
}
else
{
rndPosition = rnd.Next(0, deck.Count);
gameBoard[i, j] = deck[rndPosition];
deck.RemoveAt(rndPosition);
}
}
}
protected void DrawTable(Card[,] gameBoard)
{
Table gameTable = new Table();
gameTable.GridLines = GridLines.Both;
gameTable.BorderWidth = 4;
gameTable.ID = "gameTable";
ImageButton imgBtn = null;
for (int i = 0; i < 5; i++)
{
TableRow tblRow = new TableRow();
for (int j = 0; j < 5; j++)
{
TableCell tblCell = new TableCell();
tblCell.HorizontalAlign = HorizontalAlign.Center;
imgBtn = new ImageButton();
imgBtn.ID = i.ToString() + j.ToString();
imgBtn.Width = 80;
imgBtn.Height = 105;
imgBtn.ImageUrl = gameBoard[i, j].PictureUrl;
imgBtn.Click += new ImageClickEventHandler(Checking);
tblCell.Controls.Add(imgBtn);
tblRow.Cells.Add(tblCell);
}
gameTable.Rows.Add(tblRow);
}
Panel1.Controls.Add(gameTable);
}
protected void Checking(System.Object sender, System.EventArgs e)
{
ImageButton imgBtn = (ImageButton)sender;
int imgBtnIdNo = int.Parse(imgBtn.ID);
Label1.Text = i.ToString();
}
protected void Page_Load(object sender, EventArgs e)
{
List<Card> deck = new List<Card>();
Card[,] gameBoard = new Card[5, 5];
InitDeck(deck);
InitGameBoard(gameBoard, deck);
DrawTable(gameBoard);
}
}
This a win-form game i'm bulding, where a random 5 X 5 table is generated filled with cards except a blank cell, you need to press image button around a blanked cell, to switch their places and bulding Rows of poker made hands, but evrey time im pressing an image button the table keep generating.
By default, a button press sends the event to the server (and the page gets re-loaded). To handle it in the client, you need to use the OnClientClick property (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.onclientclick.aspx)
Do you know some way to programmaticaly show different typing indicators on the screen?
I know I can simply draw bitmap but I'd like to do it universally for any RIM OS version.
Also, there is a setMode(int) function in 4.2.1 but in 4.3 it's already deprecated...
Any suggestions will be helpful, thanks!
since there is no alternatives, I made a sample with provided images:
alt text http://img42.imageshack.us/img42/6692/typeindicator.jpg
alt text http://img3.imageshack.us/img3/5259/inputind.jpg
custom Title Field class code:
class TITitleField extends Field implements DrawStyle {
static final boolean mIsDimTheme = Integer.parseInt(DeviceInfo
.getDeviceName().substring(0, 4)) < 8900;
static final Bitmap ALT = Bitmap.getBitmapResource(mIsDimTheme ?
"typ_ind_alt_mode_Gen_Zen_328560_11.jpg" :
"typ_ind_alt_mode_Precsn_Zen_392908_11.jpg");
static final Bitmap MULTITAP = Bitmap.getBitmapResource(mIsDimTheme ?
"typ_ind_mltap_mode_Gen_Zen_328975_11.jpg" :
"typ_ind_mutlitap_mode_Precsn_Zen_452907_11.jpg");
static final Bitmap NUMLOCK = Bitmap
.getBitmapResource(mIsDimTheme ?
"typ_ind_num_lock_Gen_Zen_328568_11.jpg" :
"typ_ind_num_lock_Precsn_Zen_392925_11.jpg");
static final Bitmap SHIFT = Bitmap.getBitmapResource(mIsDimTheme ?
"typ_ind_shift_mode_Gen_Zen_328574_11.jpg" :
"typ_ind_shift_mode_Precsn_Zen_392931_11.jpg");
public static final int MODE_NONE = 0;
public static final int MODE_ALT = 1;
public static final int MODE_MULTITAP = 2;
public static final int MODE_NUMLOCK = 3;
public static final int MODE_SHIFT = 4;
public void setTypingIndicatorMode(int mode) {
mMode = mode;
updateLayout();
}
public int getTypingIndicatorMode()
{
return mMode;
}
int mWidth = 0;
int mMode = 0;
String mTitle = "";
XYRect mIndicatorDestRect = new XYRect();
public TITitleField() {
this("");
}
public TITitleField(String title) {
mTitle = title;
}
protected void paint(Graphics graphics) {
graphics.drawText(mTitle, 0, 0, LEFT | ELLIPSIS, mWidth);
if (0 != mMode) {
graphics.drawBitmap(mIndicatorDestRect,getIndicator(mMode),0,0);
}
}
private static Bitmap getIndicator(int mode) {
Bitmap result = null;
switch (mode) {
case MODE_ALT:
result = ALT;
break;
case MODE_MULTITAP:
result = MULTITAP;
break;
case MODE_NUMLOCK:
result = NUMLOCK;
break;
case MODE_SHIFT:
result = SHIFT;
break;
case MODE_NONE:
break;
default:
break;
}
return result;
}
protected void layout(int width, int height) {
mWidth = width;
if (0 != mMode) {
Bitmap indicator = getIndicator(mMode);
mIndicatorDestRect.width = indicator.getWidth();
mIndicatorDestRect.height = indicator.getHeight();
mIndicatorDestRect.y = 0;
mIndicatorDestRect.x = mWidth - mIndicatorDestRect.width;
}
setExtent(width, getPreferredHeight());
}
public int getPreferredHeight() {
int height = getFont().getHeight() + 4;
if (0 != mMode) {
int indicatorHeight = getIndicator(mMode).getHeight();
height = Math.max(height, indicatorHeight);
}
return height;
}
}
Sample of use code:
class Scr extends MainScreen {
static final TITitleField mTitle = new TITitleField("Start");
public Scr() {
this.setTitle(mTitle);
}
protected void makeMenu(Menu menu, int instance) {
super.makeMenu(menu, instance);
int typingIndicatorMode = mTitle.getTypingIndicatorMode();
if(typingIndicatorMode != mTitle.MODE_NONE)
menu.add(new MenuItem("None Mode", 0, 0) {
public void run() {
mTitle.setTypingIndicatorMode(mTitle.MODE_NONE);
}
});
if(typingIndicatorMode != mTitle.MODE_ALT)
menu.add(new MenuItem("Alt Mode", 0, 0) {
public void run() {
mTitle.setTypingIndicatorMode(mTitle.MODE_ALT);
}
});
if(typingIndicatorMode != mTitle.MODE_MULTITAP)
menu.add(new MenuItem("Multitap Mode", 0, 0) {
public void run() {
mTitle.setTypingIndicatorMode(mTitle.MODE_MULTITAP);
}
});
if(typingIndicatorMode != mTitle.MODE_NUMLOCK)
menu.add(new MenuItem("NumLock Mode", 0, 0) {
public void run() {
mTitle.setTypingIndicatorMode(mTitle.MODE_NUMLOCK);
}
});
if(typingIndicatorMode != mTitle.MODE_SHIFT)
menu.add(new MenuItem("Shift Mode", 0, 0) {
public void run() {
mTitle.setTypingIndicatorMode(mTitle.MODE_SHIFT);
}
});
}
}
i want to create sub menu for a BB application
when i click on menu item it shows
Option 1
Option 2
Option 3
When i click on option 3 it should display
1
2
3
as sub menu items..
using j2me + eclipse
Always wanted to do this )
alt text http://img380.imageshack.us/img380/3874/menugy.jpg
class Scr extends MainScreen {
SubMenu menu = new SubMenu();
public Scr() {
for (int i = 0; i < 3; i++) {
SubMenu sMenu = new SubMenu();
menu.add(new SubMenuItem(i + " item", sMenu));
for (int k = 0; k < 3; k++) {
SubMenu sSMenu = new SubMenu();
sMenu.add(new SubMenuItem(i + "-" + k + " item", sSMenu));
for (int l = 0; l < 3; l++) {
sSMenu
.add(new SubMenuItem(i + "-" + k + "-" + l
+ " item"));
}
}
}
add(new LabelField("testing menu", FOCUSABLE) {
protected void makeContextMenu(ContextMenu contextMenu) {
menu.mRectangle.x = this.getContentRect().X2();
menu.mRectangle.y = this.getContentRect().Y2();
Ui.getUiEngine().pushScreen(menu);
EventInjector.invokeEvent(new KeyEvent(KeyEvent.KEY_DOWN,
Characters.ESCAPE, 0));
}
});
}
}
class SubMenu extends PopupScreen implements ListFieldCallback {
private static final int MAX_WIDTH = Font.getDefault().getAdvance(
"max menu item text");
XYRect mRectangle = new XYRect();
Vector mSubMenuItems = new Vector();
ListField mListField;
public SubMenu() {
super(new SubMenuItemManager(), DEFAULT_CLOSE);
int rowHeight = getFont().getHeight() + 2;
mListField = new ListField() {
protected boolean navigationClick(int status, int time) {
runMenuItem(getSelectedIndex());
return super.navigationClick(status, time);
}
};
mListField.setRowHeight(rowHeight);
add(mListField);
mListField.setCallback(this);
updateMenuItems();
}
public void add(SubMenuItem subMenuItem) {
mSubMenuItems.addElement(subMenuItem);
subMenuItem.mMenu = this;
updateMenuItems();
}
private void updateMenuItems() {
int rowCounts = mSubMenuItems.size();
mRectangle.width = getMaxObjectToStringWidth(mSubMenuItems);
mRectangle.height = mListField.getRowHeight() * rowCounts;
mListField.setSize(rowCounts);
}
private void runMenuItem(int index) {
SubMenuItem item = (SubMenuItem) get(mListField, index);
if (null != item.mSubMenu) {
item.mSubMenu.setSubMenuPosition(getSubMenuRect(index));
Ui.getUiEngine().pushScreen(item.mSubMenu);
} else {
item.run();
}
}
private XYRect getSubMenuRect(int index) {
SubMenuItem item = (SubMenuItem) get(mListField, index);
XYRect result = item.mSubMenu.mRectangle;
result.x = mRectangle.x + mRectangle.width;
result.y = mRectangle.y + mListField.getRowHeight() * index;
int testWidth = Display.getWidth() - (mRectangle.width + mRectangle.x);
if (testWidth < result.width) {
result.width = testWidth;
}
int testHeight = Display.getHeight()
- (mRectangle.height + mRectangle.y);
if (testHeight < result.height)
result.height = testHeight;
return result;
}
public void setSubMenuPosition(XYRect rect) {
mRectangle = rect;
}
protected void sublayout(int width, int height) {
super.sublayout(mRectangle.width, mRectangle.height);
setPosition(mRectangle.x, mRectangle.y);
setExtent(mRectangle.width, mRectangle.height);
}
private int getMaxObjectToStringWidth(Vector objects) {
int result = 0;
for (int i = 0; i < objects.size(); i++) {
int width = getFont().getAdvance(objects.elementAt(i).toString());
if (width > result) {
if (width > MAX_WIDTH) {
result = MAX_WIDTH;
break;
} else {
result = width;
}
}
}
return result;
}
public void drawListRow(ListField field, Graphics g, int i, int y, int w) {
// Draw the text.
String text = get(field, i).toString();
g.setColor(Color.WHITE);
g.drawText(text, 0, y, DrawStyle.ELLIPSIS, w);
}
public Object get(ListField listField, int index) {
return mSubMenuItems.elementAt(index);
}
public int getPreferredWidth(ListField listField) {
return mRectangle.width;
}
public int indexOfList(ListField listField, String prefix, int start) {
return 0;
}
}
class SubMenuItemManager extends VerticalFieldManager {
public SubMenuItemManager() {
super(USE_ALL_HEIGHT | USE_ALL_WIDTH);
}
public int getPreferredWidth() {
return ((SubMenu) getScreen()).mRectangle.width;
}
public int getPreferredHeight() {
return ((SubMenu) getScreen()).mRectangle.height;
}
protected void sublayout(int maxWidth, int maxHeight) {
maxWidth = getPreferredWidth();
maxHeight = getPreferredHeight();
super.sublayout(maxWidth, maxHeight);
setExtent(maxWidth, maxHeight);
}
}
class SubMenuItem implements Runnable {
String mName;
SubMenu mMenu;
SubMenu mSubMenu;
public SubMenuItem(String name) {
this(name, null);
}
public SubMenuItem(String name, SubMenu subMenu) {
mName = name;
mSubMenu = subMenu;
}
public String toString() {
return mName;
}
public void run() {
}
}
Submenus are not part of the standard BlackBerry API. If you want to do this, you'll have to make your own custom menu+submenu control.