Exemple #1
0
        private void btnIssueSave_Click(object sender, EventArgs e)
        {
            // do the validation here
            if (issueLocationValidation.Validate())
            {
                Institution recUnit = new Institution();

                if (ID != -1) //This is not new.
                {
                    recUnit.LoadByPrimaryKey(receivingUnitId);
                    recUnit.IsUsedAtFacility = chkIsInstitutionUsedAtFacility.Checked;
                }
                else
                {
                    recUnit.AddNew();
                    recUnit.IsDraft           = true; //If it is locally added, we mark it as draft until confirmed centrally.
                    recUnit.Active            = true;
                    recUnit.IsUsedAtFacility  = true;
                    recUnit.IsLocalSite       = true;
                    recUnit.OperationalStatus = true;
                    recUnit.Rowguid           = Guid.NewGuid();
                    recUnit.NUrowguid         = Guid.NewGuid();
                    recUnit.ModifiedBy        = CurrentContext.LoggedInUser.ID.ToString();
                    recUnit.ModifiedDate      = DateTimeHelper.ServerDateTime;
                    recUnit.SN = 1; //Saving default value here.  The actual value to come from the directory services.
                }

                recUnit.Name        = txtReceivingUnit.Text;
                recUnit.Phone       = txtPhone.Text;
                recUnit.Description = txtDescription.Text;
                recUnit.Route       = Convert.ToInt32(lkRoute.EditValue);
                recUnit.Ownership   = Convert.ToInt32(lkOwnership.EditValue);
                recUnit.RUType      = Convert.ToInt32(lkRUType.EditValue);

                if (lkWoreda.EditValue != null)
                {
                    recUnit.Woreda = int.Parse(lkWoreda.EditValue.ToString());
                }
                if (lkZone.EditValue != null)
                {
                    recUnit.Zone = int.Parse(lkZone.EditValue.ToString());
                }

                if (BLL.OwnershipType.IsPrivate(recUnit.Ownership))
                {
                    if (string.IsNullOrEmpty(txtLicenseNo.Text))
                    {
                        XtraMessageBox.Show("Please fill in the license number!", "Missing Information", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    recUnit.LicenseNo          = txtLicenseNo.Text;
                    recUnit.VATNo              = txtVATNo.Text;
                    recUnit.TinNo              = txtTinNo.Text;
                    recUnit.DateOfRegistration = dtRegistration.Value;
                }
                if (ID == -1)
                {
                    if (XtraMessageBox.Show(string.Format("Are you sure you want to add a new Receiving Unit", recUnit.Name.ToString()), "Confirmation", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                    {
                        recUnit.Save();
                        this.Close();
                    }
                }
                else if (XtraMessageBox.Show(string.Format("Are you sure you want to save change to {0}", recUnit.Name.ToString()), "Confirmation", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                {
                    recUnit.Save();
                    this.Close();
                }
            }
        }