Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var id = (comboBox1.Text + textBox2.Text + textBox3.Text).GetHashCode();


                var emp = new ContractorProperty
                {
                    ID                 = id,
                    ContractorName     = comboBox1.Text,
                    RepresendativeName = textBox2.Text,
                    PhoneNumber        = textBox3.Text
                };


                ////////////
                StartForm.EmpDb.ContractorProperties.Add(emp);
                StartForm.EmpDb.SaveChanges();

                /////
                var emp1 = StartForm.EmpDb.ContractorProperties.Select(conytractorname => conytractorname.ContractorName).ToList();
                var emp2 = StartForm.EmpDb.ContractorProperties.Select(ids => ids.ID).ToList();


                comboBox1.Items.Clear();
                coIDLi.Clear();

                foreach (var item in emp1)
                {
                    comboBox1.Items.Add(item);
                }

                coIDLi.AddRange(emp2);

                StartForm.showBalloon("!!!!توجه!!!!", "پیمانکار جدید اضافه شد");

                DialogResult dlgr;


                dlgr = MessageBox.Show("پیمانکار مورد نظر  با موفقیت ثبت شد\nآیا قصد ثبت جدید دارید؟", "پیام", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (dlgr == DialogResult.Cancel)
                {
                    this.Close();
                }

                else
                {
                    comboBox1.Text = null;
                    textBox2.Clear();
                    textBox3.Clear();
                    comboBox1.Focus();
                }
            }
            catch
            {
            }
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string _username = txtUser.Text;
            string _password = txtPass.Text.GetHashCode().ToString(CultureInfo.InvariantCulture);

            string _access = StartForm.EmpDb.users.Where(
                i => i.username.Equals(_username))
                             .Select(j => j.access)
                             .SingleOrDefault();

            string _DBusername = StartForm.EmpDb.users.Where(
                i => i.username.Equals(_username))
                                 .Select(j => j.username)
                                 .SingleOrDefault();
            string _DBpassword = StartForm.EmpDb.users.Where(
                i => i.password.Equals(_password))
                                 .Select(j => j.password)
                                 .SingleOrDefault();

            if ((_username == _DBusername) &&
                (_password == _DBpassword))
            {
                this.Hide();
                StartForm frm = new StartForm();
                StartForm.user = _username;
                frm.access     = _access;
                frm.Show();
            }
            else if (txtUser.Text == "" && txtPass.Text == "")
            {
                MessageBox.Show("لطفا نام کاربری و رمز عبور را وارد کنید", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (txtUser.Text == "" && txtPass.Text != "")
            {
                MessageBox.Show("لطفا نام کاربری را وارد کنید", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (txtUser.Text != "" && txtPass.Text == "")
            {
                MessageBox.Show("لطفا رمز عبور را وارد کنید", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                MessageBox.Show("نام کاربری و رمز عبور اشتباه وارد شده است", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 3
0
        private void buttoncreate_Click(object sender, EventArgs e)
        {
            try
            {
                companyName    = comboBox2.SelectedItem.ToString();
                companyResName =
                    StartForm.EmpDb.CompanyProperties.Where(i => i.CompanyName.Equals(companyName))
                    .Select(j => j.RepresendativeName).SingleOrDefault();
                companyNum =
                    StartForm.EmpDb.CompanyProperties.Where(i => i.CompanyName.Equals(companyName))
                    .Select(j => j.PhoneNumber).SingleOrDefault();

                contractorName    = comboBox3.SelectedItem.ToString();
                contractorResName =
                    StartForm.EmpDb.ContractorProperties.Where(i => i.ContractorName.Equals(contractorName))
                    .Select(j => j.RepresendativeName).SingleOrDefault();
                contractorNum =
                    StartForm.EmpDb.ContractorProperties.Where(i => i.ContractorName.Equals(contractorName))
                    .Select(j => j.PhoneNumber).SingleOrDefault();


                var id = (FirstNametxt.Text + LastNametxt.Text + BirthDatetxt.Text + BirthPlacetxt.Text).GetHashCode();

                var user = StartForm.user;

                const string photopath = @"photos\";
                newbmp2.Save(photopath + "photo(" + id + ").jpg", ImageFormat.Jpeg);

                var fs = new FileStream((photopath + "photo(" + id + ").jpg"), FileMode.Open, FileAccess.Read);
                var br = new BinaryReader(fs);
                imageperson = br.ReadBytes((int)fs.Length);

                /// create new employee to database

                var emp = new Employee
                {
                    ID                = id,
                    FirstName         = FirstNametxt.Text,
                    LastName          = LastNametxt.Text,
                    FatherName        = FatherNametxt.Text,
                    BirthDate         = DateTime.Parse(BirthDatetxt.Text),
                    BirthPlace        = BirthPlacetxt.Text,
                    NationalId        = NationalIdtxt.Text,
                    NationalCode      = NationalCodetxt.Text,
                    PassportId        = PassportIdtxt.Text,
                    Region            = Regiontxt.Text,
                    JobSituation      = JobSituationcmb.SelectedItem.ToString(),
                    LetterId          = LetterIdtxt.Text,
                    AnalArea          = AnalAreatxt.Text,
                    FirstArea         = FirstAreatxt.Text,
                    SecondArea        = SecondAreatxt.Text,
                    CreateDate        = DateTime.Parse(CreateDatetxt.Text),
                    ExpireDate        = DateTime.Parse(ExpireDatetxt.Text),
                    Image             = imageperson,
                    CompanyName       = companyName,
                    CompanyResName    = companyResName,
                    CompanyNum        = companyNum,
                    ContractorName    = contractorName,
                    ContractorResName = contractorResName,
                    ContarctorNum     = contractorNum,
                    Print             = 0,
                    @is               = 1,
                    user              = user
                };
                StartForm.EmpDb.Employees.Add(emp);
                StartForm.EmpDb.SaveChanges();
                ///////////////////////////////////////////////////////////////////
                StartForm.showBalloon("!!!!توجه!!!!", "کارمند جدید با موفقیت اضافه شد");
                /// qr
                var encoder  = new QRCodeEncoder();
                var qrImg    = encoder.Encode(id.ToString());
                var finalimg = (Image)(new Bitmap(qrImg, 65, 65));
                ////////////////////////////////////////////////////////////////////



                /// reset start form string bases
                companyName       = null;
                companyResName    = null;
                companyNum        = null;
                contractorName    = null;
                contractorResName = null;
                contractorNum     = null;
                ///////////////////////////////////////////////////////////////////////


                Bitmap bmpaa = new Bitmap(print.CardEmp(id), 546, 221);
                pictureBox1.Image = bmpaa;
                IdTotal           = id;


                button2.Enabled        = true;
                button3.Enabled        = true;
                buttoncreate.Enabled   = false;
                buttoncreate.BackColor = System.Drawing.Color.DarkSlateGray;
                button2.BackColor      = System.Drawing.Color.DeepSkyBlue;
                button3.BackColor      = System.Drawing.Color.DeepSkyBlue;
            }
            catch (Exception es)
            {
                MessageBox.Show("ایجاد نا موفق");
            }
        }