Пример #1
0
        private dbObject getDbObject()
        {
            dbObject dbRow = new dbObject();


            using (SqlConnection conn = new SqlConnection(DBConnector.ConnectionString))
            {
                conn.Open();

                string sql = @"SELECT * FROM Product join Price on Price.Id = Product.Id where Product.Id = @id";

                using (SqlCommand comm = new SqlCommand(sql, conn))
                {
                    comm.Parameters.AddWithValue("@id", this.Id);

                    var reader = comm.ExecuteReader();

                    int ordId   = reader.GetOrdinal("id");
                    int ordName = reader.GetOrdinal("name");
                    int ordEan  = reader.GetOrdinal("ean");
                    int ordNet  = reader.GetOrdinal("Net");
                    int ordTax  = reader.GetOrdinal("Tax");
                    while (reader.Read())
                    {
                        dbRow.Id   = reader.GetInt32(ordId);
                        dbRow.Name = reader.GetString(ordName);
                        dbRow.EAN  = reader.GetDecimal(ordEan);
                        dbRow.Tax  = reader.GetDecimal(ordNet);
                        dbRow.Net  = reader.GetInt32(ordTax);
                    }

                    return(dbRow);
                }
            }
        }
Пример #2
0
        /// <summary>Обновить связанные свойства</summary>
        private void updateDeferredProperties()
        {
            dbObject lastObject = null;

            foreach (DataAboutDeferredProperty propertyData in deferredProperty)
            {
                if (lastObject == null ||
                    lastObject.GetType() != propertyData.AccessoryType ||
                    lastObject.Id != propertyData.Id)
                {
                    lastObject = (dbObject)Activator.CreateInstance(propertyData.AccessoryType);
                    lastObject.Read(propertyData.Id);
                }

                if (lastObject.Id != 0)
                {
                    object idValue = BarcodeWorker.GetIdByRef(
                        propertyData.PropertyType,
                        propertyData.Value.ToString());
                    long id = Convert.ToInt64(idValue);

                    if (!id.Equals(0L))
                    {
                        lastObject.SetValue(propertyData.PropertyName, idValue);
                        lastObject.Sync();
                    }
                }
            }
        }
Пример #3
0
        private void fillControls()
        {
            dbObject obj = this.getDbObject();

            txtName.Text = obj.Name;
            txtEan.Text  = obj.EAN.ToString();
            txtNet.Text  = obj.Net.ToString();
            txtTax.Text  = obj.Tax.ToString();
        }
Пример #4
0
        /// <summary>�������� ���������(���. �� ��������� ���������, ������� ���������� = 1) ������������� �� ��������</summary>
        /// <param name="type">��� ������� ����������������</param>
        /// <param name="listOfDetail">������� ��������� � ��������� �����������</param>
        /// <param name="accessory">������ ����������������</param>
        /// <returns>������ ...</returns>
        public static List<LabelForConstructor> GetDetailVisualPresenter(Type type, out Dictionary<string, KeyValuePair<Type, object>> listOfDetail, dbObject accessory)
        {
            listOfDetail = new Dictionary<string, KeyValuePair<Type, object>>();
            List<LabelForConstructor> list = new List<LabelForConstructor>();

            PropertyInfo[] fields = type.GetProperties();

            foreach (PropertyInfo field in fields)
                {
                Attribute[] attributes = Attribute.GetCustomAttributes(field);

                foreach (Attribute a in attributes)
                    {
                    dbFieldAtt attribute = a as dbFieldAtt;

                    if (attribute != null)
                        {
                        if (attribute.NeedDetailInfo)
                            {
                            object value = field.GetValue(accessory, null);
                            listOfDetail.Add(attribute.Description,
                                             new KeyValuePair<Type, object>(attribute.dbObjectType, value));
                            }
                        else if (attribute.ShowInEditForm)
                            {
                            object value = field.GetValue(accessory, null);

                            if (attribute.dbObjectType == null)
                                {
                                if (field.PropertyType == typeof(DateTime))
                                    {
                                    DateTime dateTimeValue = (DateTime)value;
                                    value = dateTimeValue == SqlDateTime.MinValue.Value
                                                ? string.Empty
                                                : string.Format("{0:dd.MM.yyyy}", dateTimeValue);
                                    }
                                else if (field.PropertyType.IsEnum)
                                    {
                                    value = EnumWorker.GetDescription(field.PropertyType, Convert.ToInt32(value));
                                    }
                                else if (field.PropertyType == typeof(bool))
                                    {
                                    value = (bool)value ? "+" : "-";
                                    }
                                else if (value.Equals(0) || value.Equals(0L) || value.Equals(0D))
                                    {
                                    value = string.Empty;
                                    }
                                }
                            else
                                {
                                dbObject detailObject = (dbObject)Activator.CreateInstance(attribute.dbObjectType);
                                detailObject = (dbObject)detailObject.Read(attribute.dbObjectType, value, IDENTIFIER_NAME);
                                Dictionary<string, KeyValuePair<Type, object>> subListOfDetail;
                                List<LabelForConstructor> subList = GetSingleVisualPresenter(
                                    attribute.dbObjectType, out subListOfDetail, detailObject, true);
                                list.AddRange(subList);
                                value = ReadDescription(attribute.dbObjectType, value);
                                }

                            string data = String.Format("{0}: {1}", attribute.Description, value);

                            list.Add(new LabelForConstructor(field.Name, true, data, ControlsStyle.LabelSmall, false));
                            break;
                            }
                        }
                    }
                }

            if (type == typeof(Lamps) || type == typeof(ElectronicUnits))
                {
                listOfDetail.Add("������", new KeyValuePair<Type, object>(typeof(Cases), accessory.GetPropery("Case")));
                }

            return list;
        }
Пример #5
0
        /// <summary>�������� ���������� ������������� ������ �� ��������(��� ��������� ���.)</summary>
        /// <param name="type">��� ������� ����������������</param>
        /// <param name="listOfDetail">������� ��������� � ��������� �����������</param>
        /// <param name="accessory">������ ����������������</param>
        /// <param name="isDetailMode">����� ���������� ������?</param>
        /// <returns>������ ...</returns>
        public static List<LabelForConstructor> GetSingleVisualPresenter(Type type, out Dictionary<string, KeyValuePair<Type, object>> listOfDetail, dbObject accessory, bool isDetailMode)
        {
            listOfDetail = new Dictionary<string, KeyValuePair<Type, object>>();
            List<LabelForConstructor> list = new List<LabelForConstructor>();

            PropertyInfo[] fields = type.GetProperties();

            foreach (PropertyInfo field in fields)
                {
                Attribute[] attributes = Attribute.GetCustomAttributes(field);

                foreach (Attribute a in attributes)
                    {
                    dbFieldAtt attribute = a as dbFieldAtt;

                    if (attribute != null)
                        {
                        if (attribute.NeedDetailInfo)
                            {
                            object value = field.GetValue(accessory, null);
                            listOfDetail.Add(attribute.Description,
                                             new KeyValuePair<Type, object>(attribute.dbObjectType, value));
                            }
                        else if ((isDetailMode && attribute.ShowInEditForm) ||
                            (!isDetailMode && !attribute.NotShowInForm))
                            {
                            object value = field.GetValue(accessory, null);

                            if (attribute.dbObjectType == null)
                                {
                                if (field.PropertyType == typeof(DateTime))
                                    {
                                    DateTime dateTimeValue = (DateTime)value;
                                    value = dateTimeValue == SqlDateTime.MinValue.Value
                                                ? string.Empty
                                                : String.Format("{0:dd.MM.yyyy}", dateTimeValue);
                                    }
                                else if (field.PropertyType.IsEnum)
                                    {
                                    value = EnumWorker.GetDescription(field.PropertyType, Convert.ToInt32(value));
                                    }
                                else if (field.PropertyType == typeof(bool))
                                    {
                                    value = (bool)value ? "+" : "-";
                                    }
                                else if (value.Equals(0) || value.Equals(0L) || value.Equals(0D))
                                    {
                                    value = string.Empty;
                                    }
                                }
                            else
                                {
                                value = ReadDescription(attribute.dbObjectType, value);
                                }

                            string data = String.Format("{0}: {1}", attribute.Description, value);

                            list.Add(new LabelForConstructor(data, ControlsStyle.LabelSmall, false));
                            break;
                            }
                        }
                    }
                }

            return list;
        }
Пример #6
0
 /// <summary>�������� ���������� ������������� ������ �� ��������(��� ��������� ���.)</summary>
 /// <param name="type">��� ������� ����������������</param>
 /// <param name="listOfDetail">������� ��������� � ��������� �����������</param>
 /// <param name="accessory">������ ����������������</param>
 /// <returns>������ ...</returns>
 public static List<LabelForConstructor> GetSingleVisualPresenter(Type type, out Dictionary<string, KeyValuePair<Type, object>> listOfDetail, dbObject accessory)
 {
     return GetSingleVisualPresenter(type, out listOfDetail, accessory, false);
 }
Пример #7
0
        /// <summary>Переход</summary>
        /// <param name="sender">Выбранный тип следующего коплектующего</param>
        private void button_click(object sender)
        {
            Button button = ((Button)sender);
            Type   type   = button.Tag as Type;

            if (isMainDataEntered)
            {
                if (warrantlyDataIsValid())
                {
                    if (type != null)
                    {
                        MainProcess.ClearControls();
                        bool isNewObject = accessory.IsNew;

                        //Если выбранный тип совпадает с основным типом - "Сохранение перекрестных ссылок"
                        if (mainType == type && linkId != -1)
                        {
                            accessory.SetValue(mainType.Name.Substring(0, mainType.Name.Length - 1), linkId);
                            //Сохраняем для того что бы получить accessory.Id
                            accessory.Write();

                            dbObject mainObj = (Accessory)Activator.CreateInstance(mainType);
                            mainObj = (Accessory)mainObj.Read(mainType, linkId, dbObject.IDENTIFIER_NAME);
                            mainObj.SetValue(currentType.Name.Substring(0, currentType.Name.Length - 1), accessory.Id);
                            mainObj.Write();
                        }

                        //Запись
                        accessory.Write();

                        //Если документ новый - значит был процесс "Регистрация"
                        if (isNewObject)
                        {
                            //Внесение записи в "Перемещение"
                            Movement.RegisterLighter(accessory.BarCode, accessory.SyncRef,
                                                     OperationsWithLighters.Registration);
                        }

                        //Отображение
                        string propertyName   = type.Name.Substring(0, type.Name.Length - 1);
                        object newAccessory   = accessory.GetPropery(propertyName);
                        long   newAccessoryId = newAccessory == null ? 0 : Convert.ToInt64(newAccessory);

                        //Переход на связанное комплектующее
                        if ((newAccessoryId != 0 || (newAccessoryId == 0 && linkId != -1 && mainType == type)) &&
                            button.Text != okBtnText && button.Text != nextBtnText)
                        {
                            Accessory newObj = (Accessory)Activator.CreateInstance(type);
                            newObj.Read(type, newAccessoryId, dbObject.IDENTIFIER_NAME);
                            MainProcess.Process = new EditBuilder(MainProcess, mainType, mainTopic, type,
                                                                  button.Text, newObj, newObj.BarCode);
                            accessory = newObj;
                        }
                        //Переход на НОВЫЙ выбранный тип комплектующего
                        else
                        {
                            //Если выбранный тип совпадает с основным типом
                            if (mainType == type)
                            {
                                if (mainType == null || linkId == -1)
                                {
                                    accessory = (Accessory)accessory.Copy();
                                    accessory.ClearPosition();
                                    MainProcess.Process = new EditBuilder(MainProcess, mainType, mainType, mainTopic);
                                }

                                MainProcess.Process = new EditBuilder(MainProcess, mainType, mainType, mainTopic);
                            }
                            //Не совпадает - "Передача ИД комплектующего с которого переходим"
                            else
                            {
                                MainProcess.Process = new EditBuilder(MainProcess, type, mainType, button.Text,
                                                                      accessory.Id, type == typeof(ElectronicUnits));
                            }


                            //Если не было произведено копирование полей для следующего комплектующего, то очистить все поля
                            if (!accessory.IsNew)
                            {
                                accessory = null;
                            }
                        }
                    }
                }
            }
            else
            {
                showWriteErrorMessage();
            }
        }