示例#1
0
        private void DraftRegister_Load(object sender, EventArgs e)
        {
            UsersCrud  usersCrud  = new UsersCrud();
            UniqueCrud uniqueCrud = new UniqueCrud();

            uniqueModel = uniqueCrud.GetLastUnique();
            var users = usersCrud.findUsers();

            txtUserID.DisplayMember = "Name";
            txtUserID.ValueMember   = "ID";

            txtDate.Text = CommonUtils.ConvertMiladiToPersianDate(DateTime.Now.ToShortDateString());
            foreach (var item in users)
            {
                var model = new ItemModel();
                model.Name = item.name + " " + item.family;
                model.ID   = item.ID;
                txtUserID.Items.Add(model);
            }

            txtTruck.DisplayMember = "Name";
            txtTruck.ValueMember   = "ID";
            foreach (var item in CommonUtils.getTrucksType())
            {
                txtTruck.Items.Add(item);
            }

            if (isForUpdate == true)
            {
                btnUpdate.Enabled   = true;
                btnRegister.Enabled = false;
                DraftCrud draftCrud = new DraftCrud();
                var       draft     = draftCrud.findDraftByID(DraftID);
                setElementsValue(draft);
            }



            if (isForUpdate == false)
            {
                fillForRegisterLoad();
            }
        }
示例#2
0
        private void btnRegister_Click(object sender, EventArgs e)
        {
            if (txtCarTag.Text == "" || txtCertificateDriver.Text == "" || txtDate.Text == "" || txtDestination.Text == "" || txtDriver.Text == "" ||
                txtManagement.Text == "" || txtNumber.Text == "" || txtOrigin.Text == "" || txtSerial.Text == "" || txtTruck.Text == "" || txtType.Text == "" ||
                txtUserID.SelectedItem == null || txtValue.Text == "")
            {
                MessageBox.Show("اطلاعات را به صورت کامل وارد نمایید.", "خطا در ورود اطلاعات", MessageBoxButtons.OK);
                return;
            }


            if (ChekDateIsValid() == false)
            {
                return;
            }
            if (CheckIsCarTagValid() == false)
            {
                return;
            }

            var paramValues = bindFields();

            if (MessageBox.Show("آیا اطلاعات ذخیره گردد. ", "ثبت اطلاعات", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                DbContext context = new DbContext();
                context.InsertData(DatabaseConstantData.DraftTable, paramValues);
                MessageBox.Show("اطلاعات با موفقیت ثبت گردید", "ثبت اطلاعات", MessageBoxButtons.OK);
                DraftCrud draftCrud = new DraftCrud();
                var       draft     = draftCrud.findDraftByNumber(txtNumber.Text);
                var       stiReport = CommonUtils.ShowReport(draft.ID);
                stiReport.Show();
                List <TextBox> textBoxes = new List <TextBox>();
                textBoxes.Add(txtCarTag);
                textBoxes.Add(txtCertificateDriver);
                textBoxes.Add(txtDate);
                textBoxes.Add(txtDestination);
                textBoxes.Add(txtDriver);
                textBoxes.Add(txtManagement);
                textBoxes.Add(txtNumber);
                textBoxes.Add(txtOrigin);
                textBoxes.Add(txtSerial);
                textBoxes.Add(txtValue);
                setNullToTextBox(textBoxes);

                if (DateTime.Now.ToShortDateString() != CommonUtils.ConvertPersianToMiladiDate(uniqueModel.Date).ToShortDateString())
                {
                    uniqueModel.UniquID = 1;
                }

                else
                {
                    uniqueModel.UniquID++;
                }
                var paramsGenerate = bindFieldsGenerate(uniqueModel.UniquID);
                context.UpdateGenerate(DatabaseConstantData.GenerateTable, uniqueModel.ID, paramsGenerate);
                UniqueCrud uniqueCrud = new UniqueCrud();
                uniqueModel = uniqueCrud.GetLastUnique();
                fillForRegisterLoad();
            }
            else
            {
                return;
            }
        }