|
as you live in iran same as me, you can use some company web services to send sms via your web application.
if you buy a web service , they give you a uri of service, and you just need to add web reference to your reference folder, and in your code, you just need to make a new method of that, and pass some param to web service.
this my code:
var b = new ArrayOfString();
b.Add("با تشکر از شما جهت ایجاد اشتراک در سایت هلال. کد اشتراک :" + txtSubsCode.Text + "از این پس میتوانید جهت سفارش غذا با شماره:4242998 تماس حاصل نمایید.\n" +"لیست غدایی ما در بخش منوی سایت موجود میباشد");
var c = new ArrayOfString();
c.Add(submit.MobileNo);
var aaa = new sms.sendSmsWebServiceSoapClient();
aaa.sendSms("test", "password", "username", b, c, 1, "30008672");
|
|
|
|
|
Hi I am trying to build a Yahtzee game and am having trouble with the code for the hold dice button, thus to stop the dice from rolling again when button is clicked on.
Also am needing some help and code to make the dice only roll 3 times in a turn. Thanks
Code so far is as follows.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Media;
namespace yahtzeetrial
{
public partial class Form2 : Form
{
int m_nRoll = 0;
int numRolls = 0;
private Random RandomPick;
int[] DiceButtons = new int[] { 0, 0, 0, 0, 0 };
int[] DiceHold = new int[] { 0, 0, 0, 0, 0 };
int AllDice = 0;
public Form2()
{
InitializeComponent();
InitialiseDiceButtons();
}
SoundPlayer My_JukeBox = new SoundPlayer(@"C:\Users\Bronwyn\Documents\Yahtzee Game\yahtzeetrial\diceroll.wav");
public void InitialiseDiceButtons()
{
this.btn1.ImageList = imageList1;
this.btn1.ImageIndex = 0;
this.btn2.ImageList = imageList1;
this.btn2.ImageIndex = 0;
this.btn3.ImageList = imageList1;
this.btn3.ImageIndex = 0;
this.btn4.ImageList = imageList1;
this.btn4.ImageIndex = 0;
this.btn5.ImageList = imageList1;
this.btn5.ImageIndex = 0;
}
private void btnRoll_Click(object sender, EventArgs e)
{
My_JukeBox.Play();
InitialiseRandomRoll();
do
{
m_nRoll = 0;
Roll();
if ((m_nRoll >= 1) || (m_nRoll <= 6))
{
DiceButtons[AllDice] = m_nRoll;
AllDice++;
}
} while (AllDice < 5);
this.btn1.ImageIndex = DiceButtons[0];
this.btn2.ImageIndex = DiceButtons[1];
this.btn3.ImageIndex = DiceButtons[2];
this.btn4.ImageIndex = DiceButtons[3];
this.btn5.ImageIndex = DiceButtons[4];
AllDice = 0;
}
public void Roll()
{
m_nRoll = (int)(RandomPick.NextDouble() * 6) + 1;
}
public void InitialiseRandomRoll()
{
DateTime aTime = new DateTime(1000);
aTime = DateTime.Now;
int nSeed = (int)(aTime.Millisecond);
RandomPick = new Random(nSeed);
}
private void btnHold1_Click(object sender, EventArgs e)
{
if (DiceHold[0] == 0)
{
DiceHold[0] = 1;
this.btnHold1.ForeColor = Color.Red;
}
else
{
DiceHold[0] = 0;
this.btnHold1.ForeColor = Color.Black;
}
}
private void btnHold2_Click(object sender, EventArgs e)
{
if (DiceHold[1] == 0)
{
DiceHold[1] = 1;
this.btnHold2.ForeColor = Color.Red;
}
else
{
DiceHold[1] = 0;
this.btnHold2.ForeColor = Color.Black;
}
}
private void btnHold3_Click(object sender, EventArgs e)
{
if (DiceHold[2] == 0)
{
DiceHold[2] = 1;
this.btnHold3.ForeColor = Color.Red;
}
else
{
DiceHold[2] = 0;
this.btnHold3.ForeColor = Color.Black;
}
}
private void btnHold4_Click(object sender, EventArgs e)
{
if (DiceHold[3] == 0)
{
DiceHold[3] = 1;
this.btnHold4.ForeColor = Color.Red;
}
else
{
DiceHold[3] = 0;
this.btnHold4.ForeColor = Color.Black;
}
}
private void btnHold5_Click(object sender, EventArgs e)
{
if (DiceHold[4] == 0)
{
DiceHold[4] = 1;
this.btnHold5.ForeColor = Color.Red;
}
else
{
DiceHold[4] = 0;
this.btnHold5.ForeColor = Color.Black;
}
}
}
}
modified 1-Jun-12 22:22pm.
|
|
|
|
|
You can use this code for dice:
public void InitializeRandomRoll( int nSeed )
{
DateTime aTime = new DateTime(1000);
aTime = DateTime.Now;
nSeed += (int)(aTime.Millisecond);
RandomPick = new Random(nSeed);
}
We need to be able to hold a dice,so that it does not roll when the roll button is pressed.So,we add a variable to hold the state of the dice.and you can use this property.
private bool m_bHoldState = false;
public bool HoldState
{
get { return m_bHoldState; }
set { m_bHoldState = value; }
}
Now,we need to make sure that if the dice is held,it does not get rolled.
public void Roll()
{
if( !HoldState )
{
RollNumber = RandomPick.Next(1,7);
this.Invalidate();
}
}
At the end,the dice is drawn in black if the dice is not held,and in red if it is.
public void DrawDot( Graphics g, Point p )
{
SolidBrush myBrush;
if( HoldState )
{
myBrush = new SolidBrush( Color.Red );
}
else
{
myBrush = new SolidBrush( Color.Black );
}
g.FillEllipse( myBrush, p.X, p.Y, dotWidth, dotWidth );
myBrush.Dispose();
}
|
|
|
|
|
This coding looks like from the same source as I have already found on this site I was hoping that someone else may have something different to try out. Thanks.
|
|
|
|
|
I installed the EF CTP4 from here[^]
I am now trying to configure a mapping:
using System.Data.Entity.ModelConfiguration;
using Falcon.Entities.Entities;
namespace Falcon.DAL.Configuration
{
public class ClientConfiguration : EntityConfiguration<ClientEntity>
{
public ClientConfiguration()
{
Property(c => c.Id).IsIdentity();
Property(c => c.ClientName).HasMaxLength(50).IsRequired();
Property(c => c.IsActive);
Relationship(c => c.Company).IsRequired();
}
}
}
It can't find Relationship. All the code examples and the book I'm using have this. Anyone know what's wring here?
If it's not broken, fix it until it is
|
|
|
|
|
Hi Kevin,
I think you have to associate by providing the foreign key in the relationship.
Property(c => c.Company).IsRequired().WithMany()
.HasForeignKey(u => u.CompanyId);
|
|
|
|
|
I hope this is the correct place to post this. If not, please help me correct it.
Lately, I have been digging around in open source projects at SourceForge.net. I download the source for an interesting project, typically if it seems like something I may learn from. I may be working on a project in which I need to create a custom control and I would like a good code example that I can study. Once the source is downloaded and I extract it as needed, I load the solution in Visual Studio 2010.
Once I begin digging through some of the code my head begins to hurt. It hurts terribly. For one, I see little white space in many projects. And two, the thing that really gets me, is the fact that variables have completely meaningless names, usually just one or two letters. It looks like this (not real code; just an example):
Dictionary<string, int> d = new Dictionary<string, int>();
private void MyMethod(string p, int q)
{
bool b = p == "string1" ? true : false;
List<string> l = GetList(b);
foreach (string k in l)
{
if (!string.IsNullOrWhiteSpace(p) && q > 0)
d.Add(l, q);
}
}
Before I continue, what does the fact that p == "string1" have to do with anything? Also, what does GetList(bool) do and how does the value of 'b' affect the results?
The first thing I tend to notice is that there is no documentation (///<summary>) for the method. Adding those comments too methods and classes is typically the first thing I do when I am coding. Maybe it isn't a recommended practice but instead it is just my own "standard"/style? If so, that's fine. Should this be something everyone uses?
The comments are typically quite vague as well. Or comments are missing entirely, even in methods that contain a lot of code. And in MyMethod, how should you really know what "d" is when it is declared in another file/class? And why exactly does "q > 0" have to be met before adding the item? This isn't a perfect example but I'm not on the computer I use when browsing through these projects. Perhaps I am being overly conscious about coding practices, standards, whatever. But I find it very difficult to read the code at times.
Another thing that bugs me slightly, though I guess it's expected when anyone can contribute to the project, is the lack of a consistent coding style. That doesn't bug me near as much as the rest. It's just a thought that I figured I'd throw in here.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
My 2 cts:
1.
The worst style aspect is using single-letter identifiers, especially for the method itself and its parameters. Giving them meaningful names makes things a lot easier to understand. And they might show up in Intellisense or something similar, making the use of the method a lot easier.
2.
Yes, a method-level comment (a "contract") explaining what the method promises to do for you would be nice (unless #1 fixed all that already).
3.
About why "string1" and "q>0" are there I can't tell you anything, as I have no clue what the purpose of the whole thing is.
|
|
|
|
|
I don't know, but there's a lot of ugly code there.
0) Yes, the Dictionary should have a better name (and maybe it should have an access modifier).
1) ? true : false seems unnecessary.
2) if (!string.IsNullOrWhiteSpace(p) && q > 0) should probably wrap everything else.
3) I generally put XML documentation comments on code I publish, but I get lazy too.
4) I would prefer d [ l ] = q over d.Add(l, q)
5) You'll have to read GetList to see what it does
|
|
|
|
|
I agree. I'm just trying to find out why people think this is okay. Haha. I've seen practically identical examples on so many occasions and it just blows my mind. I mean, I do slip up once in a while, forgetting XML documentation, lazily naming a few variables, etc. But certainly if I were to contribute to an open source project I would want to use the best standards/practices that I was aware of. It's not like working in a team in the same room/office, where the other contributors could at least walk over to you and say "what the **** is this?" Haha.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
Matt U. wrote: . . . lazily naming a few variables, etc.
I really do try to use meaningful variable names. But sometimes I can't think of one that I haven't used elsewhere for a similar purpose...so I get frustrated and just use the first thing pops into my head.
So if you ever see a variable called BuffaloFart, do not attempt to divine a legitimate meaning. There may not be one.
|
|
|
|
|
GenJerDan wrote: So if you ever see a variable called BuffaloFart, do not attempt to divine a legitimate meaning. There may not be one.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
I don't recall any BuffaloFart variables in any of my code. However, I have been stuck as well and I have chosen something like "blah1", "blah2" and "blah3". They were all related in terms of how they were used. Haha.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
Matt U. wrote: Adding those comments too methods and classes is typically the first thing I do when I am coding +5
Me too. I always comment and organize my code. I don't enjoy spending hours trying to figure out what a developer (who's no longer at the copany) intended to do in a bunch of obtuse code and would hate to have a consumer of my code endure the same pain.
/ravi
|
|
|
|
|
Haha, yeah. I know what you mean. I am the only developer in my facility, a manufacturing environment. I'm not technically a developer (my job title, that is) but that is exactly what my job is. I write in-house applications. But even without others looking at my code, I get in the mindset like I do work on a team rather than solo. Just an extra precaution, I reckon.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
Matt U. wrote: Perhaps I am being overly conscious about coding practices, standards, whatever.
But I find it very difficult to read the code at times.
Unfortunately that is how the real world works.
I am hopeful that the example you posted is one of the worst rather than average.
All you can do is endeavor to make sure that no one ever asks (or thinks) the same thing about your code.
So make sure your code has comments, insure that if you are modifying existing code that it matches the existing style, give your variables better names and remove unused code.
Matt U. wrote: typically if it seems like something I may learn from.
Hopefully you have learned that it is likely that other people will look at your code, and will want/need to understand it and so you should write your code that reflects that understanging.
|
|
|
|
|
That makes sense. I definitely go into a project with the assumption that someone may eventually look at my code. And with the way things are going lately, that may be the case soon.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
Good afternoon to all.
Here's my problem:
I've created a WCF service and now I'm trying to install it with Installer project on target machine as administrator.
host = new ServiceHost(serviceType, serviceUri);
host.Open();
And here's exception:
HTTP could not register URL http:
When I start serviceCore as console application - it works fine.
What I'd tried:
- netsh;
- manifest with highestAvailable;
- turn off UAC;
ServiceInstaller is NetworkService, target machine OS is R2, domain user has adm rights.
|
|
|
|
|
Its easy
you can use this using directive
using System.ServiceModel
|
|
|
|
|
sina rahimzadeh wrote: you can use this using directive
That has absolutely nothing to do with it.
The OP doesn't have a compile problem.
|
|
|
|
|
He can sacrifice a chicken as well. It's as relevant as your answer.
|
|
|
|
|
even turkey can't help me -/
modified 1-Jun-12 10:18am.
|
|
|
|
|
|
as I've said, I'd already used "netsh"
I'd added localhost, ip, + with my domain user or Everyone. But it still doesn't work)
|
|
|
|
|
first remove that port and then reserve it again, or change your port, maybe its allready reserved by another service!
|
|
|
|