Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        private void ShowDetail()
        {
            SubdepoDto mm = null;

            if (Index != -1)
            {
                mm = Data[Index];
            }

            if (mm != null)
            {
                txtCode.Text      = mm.Code;
                txtOldCode.Text   = mm.OldCode;
                txtName.Text      = mm.Name;
                txtAddr1.Text     = mm.Address1;
                txtAddr2.Text     = mm.Address2;
                txtCity.Text      = mm.City;
                txtZipCode.Text   = mm.ZipCode;
                txtPhone1.Text    = mm.Phone1;
                txtFax1.Text      = mm.Fax1;
                txtLongitude.Text = mm.Longitude.ToString();
                txtLatitude.Text  = mm.Latitude.ToString();
                chkStatus.Checked = mm.Status == 1 ? true : false;

                btnFoto.Enabled = true;
            }
            Flag = Flag.IDLE;
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private bool MappingValue()
        {
            var rows = Processor.GetData(cmbSheet.SelectedValue.ToString()).AsEnumerable();

            Data = new List <SubdepoDto>();
            string errMsg = string.Empty;

            try
            {
                int        count = ExistSubdepoes.Count();
                SubdepoDto mm    = null;
                int        ii    = 0;
                foreach (var row in rows)
                {
                    mm = new SubdepoDto();
                    if (chkCode.Checked)
                    {
                        count++;
                        mm.Code = string.Format("{0:0000000}", count);
                    }
                    if (cmbOldCodeField.SelectedIndex != 0)
                    {
                        if (row.Field <object>(cmbOldCodeField.SelectedValue.ToString()) != null)
                        {
                            mm.OldCode = row.Field <object>(cmbOldCodeField.SelectedValue.ToString()).ToString();
                        }
                        else
                        {
                            mm.OldCode = string.Empty;
                        }
                    }
                    if (cmbNameField.SelectedIndex != 0)
                    {
                        if (row.Field <object>(cmbNameField.SelectedValue.ToString()) != null)
                        {
                            mm.Name = row.Field <object>(cmbNameField.SelectedValue.ToString()).ToString();
                        }
                        else
                        {
                            mm.Name = mm.Code;
                            errMsg += "Error Name Subdepo on line " + (ii + 1) + "\n";
                        }
                    }
                    if (cmbAdd1Field.SelectedIndex != 0)
                    {
                        if (row.Field <object>(cmbAdd1Field.SelectedValue.ToString()) != null)
                        {
                            mm.Address1 = row.Field <object>(cmbAdd1Field.SelectedValue.ToString()).ToString();
                        }
                        else
                        {
                            mm.Address1 = mm.Code;
                            errMsg     += "Error Address Subdepo on line " + (ii + 1) + "\n";
                        }
                    }
                    if (cmbAdd2Field.SelectedIndex != 0)
                    {
                        if (row.Field <object>(cmbAdd2Field.SelectedValue.ToString()) != null)
                        {
                            mm.Address2 = row.Field <object>(cmbAdd2Field.SelectedValue.ToString()).ToString();
                        }
                        else
                        {
                            mm.Address2 = string.Empty;
                        }
                    }
                    if (cmbCityField.SelectedIndex != 0)
                    {
                        if (row.Field <object>(cmbCityField.SelectedValue.ToString()) != null)
                        {
                            mm.City = row.Field <object>(cmbCityField.SelectedValue.ToString()).ToString();
                        }
                        else
                        {
                            mm.City = string.Empty;
                        }
                    }
                    if (cmbZipCodeField.SelectedIndex != 0)
                    {
                        if (row.Field <object>(cmbZipCodeField.SelectedValue.ToString()) != null)
                        {
                            mm.ZipCode = row.Field <object>(cmbZipCodeField.SelectedValue.ToString()).ToString();
                        }
                        else
                        {
                            mm.ZipCode = string.Empty;
                        }
                    }
                    if (cmbPhone1Field.SelectedIndex != 0)
                    {
                        if (row.Field <object>(cmbPhone1Field.SelectedValue.ToString()) != null)
                        {
                            mm.Phone1 = row.Field <object>(cmbPhone1Field.SelectedValue.ToString()).ToString();
                        }
                        else
                        {
                            mm.Phone1 = string.Empty;
                        }
                    }
                    if (cmbFax1Field.SelectedIndex != 0)
                    {
                        if (row.Field <object>(cmbFax1Field.SelectedValue.ToString()) != null)
                        {
                            mm.Fax1 = row.Field <object>(cmbFax1Field.SelectedValue.ToString()).ToString();
                        }
                        else
                        {
                            mm.Fax1 = string.Empty;
                        }
                    }

                    Data.Add(mm);
                    ii++;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(null,
                                ex.Message,
                                MasterModule.Name,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Stop);
                return(false);
            }

            if (!string.IsNullOrWhiteSpace(errMsg))
            {
                if (MessageBox.Show(null,
                                    errMsg,
                                    MasterModule.Name,
                                    MessageBoxButtons.AbortRetryIgnore,
                                    MessageBoxIcon.Warning) == DialogResult.Ignore)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        private bool Save()
        {
            bool       tResult = false;
            SubdepoDto mm      = null;

            try
            {
                if (Flag == Flag.DataDeleting)
                {
                    tResult = MasterModule.Handler.RepositoryV2.Delete <SubdepoDto>(Data[Index].Code).Equals("0") ? true : false;
                }
                else
                {
                    switch (Flag)
                    {
                    case Flag.DataCreating:
                        mm = new SubdepoDto()
                        {
                            OldCode  = txtOldCode.Text.Trim(),
                            Name     = txtName.Text.Trim(),
                            Address1 = txtAddr1.Text.Trim(),
                            Address2 = txtAddr2.Text.Trim(),
                            City     = txtCity.Text.Trim(),
                            ZipCode  = txtZipCode.Text.Trim(),
                            Phone1   = txtPhone1.Text.Trim(),
                            Fax1     = txtFax1.Text.Trim(),
                            Status   = chkStatus.Checked ? 1 : 0
                        };

                        if (string.IsNullOrWhiteSpace(txtCode.Text.Trim()))
                        {
                            mm.Code = string.Format("{0:000000}", Data.Count + 1);
                        }
                        else
                        {
                            mm.Code = txtCode.Text.Trim();
                        }

                        if (!string.IsNullOrWhiteSpace(txtGeoAddr1.Text.Trim()) &&
                            !string.IsNullOrWhiteSpace(txtGeoAddr2.Text.Trim()))
                        {
                            mm.GeoAddress = txtGeoAddr1.Text.Trim() + "#" + txtGeoAddr2.Text.Trim();
                        }
                        else if (!string.IsNullOrWhiteSpace(txtGeoAddr1.Text.Trim()))
                        {
                            mm.GeoAddress = txtGeoAddr1.Text.Trim();
                        }
                        else
                        {
                            mm.GeoAddress = txtGeoAddr2.Text.Trim();
                        }

                        if (!string.IsNullOrWhiteSpace(txtLongitude.Text.Trim()))
                        {
                            string lgt = txtLongitude.Text.Trim();
                            if (Regex.IsMatch(lgt, "^-?\\d*\\.?\\d*$"))
                            {
                                mm.Longitude = double.Parse(lgt);
                            }
                        }

                        if (!string.IsNullOrWhiteSpace(txtLatitude.Text.Trim()))
                        {
                            string lat = txtLatitude.Text.Trim();
                            if (Regex.IsMatch(lat, "^-?\\d*\\.?\\d*$"))
                            {
                                mm.Latitude = double.Parse(lat);
                            }
                        }

                        tResult = MasterModule.Handler.RepositoryV2.Insert <SubdepoDto>(mm).Equals("0") ? true : false;
                        break;

                    case Flag.DataUpdating:
                        mm = Tag as SubdepoDto;

                        mm.OldCode  = txtOldCode.Text.Trim();
                        mm.Name     = txtName.Text.Trim();
                        mm.Address1 = txtAddr1.Text.Trim();
                        mm.Address2 = txtAddr2.Text.Trim();
                        mm.City     = txtCity.Text.Trim();
                        mm.ZipCode  = txtZipCode.Text.Trim();
                        mm.Phone1   = txtPhone1.Text.Trim();
                        mm.Fax1     = txtFax1.Text.Trim();
                        mm.Status   = chkStatus.Checked ? 1 : 0;

                        if (!string.IsNullOrWhiteSpace(txtGeoAddr1.Text.Trim()) &&
                            !string.IsNullOrWhiteSpace(txtGeoAddr2.Text.Trim()))
                        {
                            mm.GeoAddress = txtGeoAddr1.Text.Trim() + "#" + txtGeoAddr2.Text.Trim();
                        }
                        else if (!string.IsNullOrWhiteSpace(txtGeoAddr1.Text.Trim()))
                        {
                            mm.GeoAddress = txtGeoAddr1.Text.Trim();
                        }
                        else
                        {
                            mm.GeoAddress = txtGeoAddr2.Text.Trim();
                        }

                        if (!string.IsNullOrWhiteSpace(txtLongitude.Text.Trim()))
                        {
                            string lgt = txtLongitude.Text.Trim();
                            if (Regex.IsMatch(lgt, "^-?\\d*\\.?\\d*$"))
                            {
                                mm.Longitude = double.Parse(lgt);
                            }
                        }

                        if (!string.IsNullOrWhiteSpace(txtLatitude.Text.Trim()))
                        {
                            string lat = txtLatitude.Text.Trim();
                            if (Regex.IsMatch(lat, "^-?\\d*\\.?\\d*$"))
                            {
                                mm.Latitude = double.Parse(lat);
                            }
                        }

                        mm.LastUpdated = DateTime.Now.ToString("yyyyMMddhhmmss");

                        tResult = MasterModule.Handler.RepositoryV2.Update <SubdepoDto>(mm).Equals("0") ? true : false;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                tResult = false;
                MessageBox.Show(null,
                                ex.Message,
                                MasterModule.Name,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Stop);
            }
            return(tResult);
        }